Squashed commit of the following:
commit
f5cbcb1e165ad8c3ba18f921c0dd5dc2a656e9d7
Author: Satyajit Padalkar <spadalkar@gmail.com>
Date: Wed Mar 3 16:52:35 2021 -0500
perf_monitor: Fix finalizing JSON output files for trackers
{
fwrite("[", 1, 1, fh);
first_write = true;
+ initialized = true;
}
void JSONFormatter::write(FILE* fh, time_t cur_time)
}
void JSONFormatter::finalize_output(FILE* fh)
-{ fwrite("]\n", 2, 1, fh); }
+{
+ if ( initialized )
+ {
+ fwrite("]\n", 2, 1, fh);
+ initialized = false;
+ }
+}
#ifdef CATCH_TEST_BUILD
private:
bool first_write = true;
+ bool initialized = false;
};
#endif
PerfTracker::~PerfTracker()
{
- formatter->finalize_output(fh);
- delete formatter;
+ close();
- if (fh && fh != stdout)
- fclose(fh);
+ delete formatter;
}
void PerfTracker::close()
{
- if (fh && fh != stdout)
+ if (fh)
{
- fclose(fh);
- fh = nullptr;
+ formatter->finalize_output(fh);
+ if (fh != stdout)
+ {
+ fclose(fh);
+ fh = nullptr;
+ }
}
}