Skip to content

Commit

Permalink
bug fix for multi thread appends
Browse files Browse the repository at this point in the history
  • Loading branch information
hariharan-devarajan committed Aug 10, 2023
1 parent fb7fb65 commit 25f0891
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/dlio_profiler/writer/chrome_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
void dlio_profiler::ChromeWriter::initialize(char *filename, bool throw_error) {
this->throw_error = throw_error;
this->filename = filename;
if (this->fp == nullptr) {
fp = fopen(filename, "a+");
if (fp == nullptr) {
ERROR(fp == nullptr,"unable to create log file %s", filename);
}
}
}

void
dlio_profiler::ChromeWriter::log(std::string &event_name, std::string &category, TimeResolution &start_time, TimeResolution &duration,
std::unordered_map<std::string, std::any> &metadata, int process_id) {
if (this->fp == nullptr) {
fp = fopen(filename.c_str(), "a+");
if (fp == nullptr) {
ERROR(fp == nullptr,"unable to create log file %s", filename.c_str());
}
}
if (fp != nullptr) {
std::string json = convert_json(event_name, category, start_time, duration, metadata, process_id);
auto written_elements = fwrite(json.c_str(), json.size(), sizeof(char), fp);
Expand All @@ -45,13 +45,9 @@ void dlio_profiler::ChromeWriter::finalize() {
if (status != 0) {
ERROR(status != 0, "unable to close log file %d for a+", filename.c_str());
}
fp = fopen(filename.c_str(), "r+");
fp = fopen(this->filename.c_str(), "r");
if (fp == nullptr) {
ERROR(fp == nullptr,"unable to create log file %s for r+", filename.c_str());
}
status = fseek(fp, 0, SEEK_SET);
if (status != 0) {
ERROR(status != 0, "unable to seek to start log file %d", filename.c_str());
ERROR(fp == nullptr,"unable to create log file %s", this->filename.c_str());
}
std::string data = "[\n";
auto written_elements = fwrite(data.c_str(), data.size(), sizeof(char), fp);
Expand Down

0 comments on commit 25f0891

Please sign in to comment.