Skip to content

Commit

Permalink
checks for consistent buffer writing.
Browse files Browse the repository at this point in the history
  • Loading branch information
hariharan-devarajan committed Sep 30, 2024
1 parent a9cf909 commit 8a3d57f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
5 changes: 1 addition & 4 deletions src/dftracer/writer/chrome_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,14 @@ void dftracer::ChromeWriter::finalize(bool has_entry) {
DFTRACER_LOG_INFO("Profiler finalizing writer %s", filename.c_str());
write_buffer_op(true);
fflush(fh);
int last_off = ftell(fh);
(void)last_off;
int status = fclose(fh);
if (status != 0) {
DFTRACER_LOG_ERROR("unable to close log file %s for a+",
filename.c_str()); // GCOVR_EXCL_LINE
}
if (!has_entry) {
DFTRACER_LOG_INFO(
"No trace data written as offset is %d. Deleting file %s", last_off,
filename.c_str());
"No trace data written deleting file %s", filename.c_str());
df_unlink(filename.c_str());
} else {
DFTRACER_LOG_INFO("Profiler writing the final symbol", "");
Expand Down
13 changes: 5 additions & 8 deletions src/dftracer/writer/chrome_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,16 @@ class ChromeWriter {

bool is_first_write;
inline size_t write_buffer_op(bool force = false) {
std::unique_lock<std::shared_mutex> lock(mtx);
if (current_index == 0 || (!force && current_index < write_buffer_size))
return 0;
DFTRACER_LOG_DEBUG("ChromeWriter.write_buffer_op %s",
this->filename.c_str());
size_t written_elements = 0;
{
std::unique_lock<std::shared_mutex> lock(mtx);
flockfile(fh);
written_elements = fwrite(buffer.data(), current_index, sizeof(char), fh);
current_index = 0;
funlockfile(fh);
}

flockfile(fh);
written_elements = fwrite(buffer.data(), current_index, sizeof(char), fh);
current_index = 0;
funlockfile(fh);
if (written_elements != 1) { // GCOVR_EXCL_START
DFTRACER_LOG_ERROR(
"unable to log write only %ld of %d trying to write %d with error code "
Expand Down

0 comments on commit 8a3d57f

Please sign in to comment.