diff --git a/src/dftracer/writer/chrome_writer.cpp b/src/dftracer/writer/chrome_writer.cpp index 653e14e..e3a31d1 100644 --- a/src/dftracer/writer/chrome_writer.cpp +++ b/src/dftracer/writer/chrome_writer.cpp @@ -78,8 +78,6 @@ 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+", @@ -87,8 +85,7 @@ void dftracer::ChromeWriter::finalize(bool has_entry) { } 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", ""); diff --git a/src/dftracer/writer/chrome_writer.h b/src/dftracer/writer/chrome_writer.h index b98868f..a085106 100644 --- a/src/dftracer/writer/chrome_writer.h +++ b/src/dftracer/writer/chrome_writer.h @@ -55,19 +55,16 @@ class ChromeWriter { bool is_first_write; inline size_t write_buffer_op(bool force = false) { + std::unique_lock 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 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 "