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 8a2de14
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 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, "r+");
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 @@ -41,15 +41,7 @@ dlio_profiler::ChromeWriter::log(std::string &event_name, std::string &category,

void dlio_profiler::ChromeWriter::finalize() {
if (fp != nullptr) {
int status = fclose(fp);
if (status != 0) {
ERROR(status != 0, "unable to close log file %d for a+", filename.c_str());
}
fp = fopen(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);
int status = fseek(fp, 0, SEEK_SET);
if (status != 0) {
ERROR(status != 0, "unable to seek to start log file %d", filename.c_str());
}
Expand Down

0 comments on commit 8a2de14

Please sign in to comment.