Skip to content

Commit

Permalink
#1881: open lb statistics json file on first use
Browse files Browse the repository at this point in the history
  • Loading branch information
nlslatt committed Jul 28, 2022
1 parent de1593b commit 2b7ca89
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
24 changes: 15 additions & 9 deletions src/vt/vrt/collection/balance/lb_invoke/lb_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -450,12 +450,6 @@ void LBManager::destroyLB() {
}
}

void LBManager::initialize() {
#if vt_check_enabled(lblite)
createStatisticsFile();
#endif
}

void LBManager::finalize() {
closeStatisticsFile();
}
Expand Down Expand Up @@ -548,13 +542,17 @@ void LBManager::statsHandler(StatsMsgType* msg) {

void LBManager::stagePreLBStatistics(const StatisticMapType &statistics) {
// Statistics output when LB is enabled and appropriate flag is enabled
if (!theConfig()->vt_lb_statistics) {
if (theContext()->getNode() != 0 or !theConfig()->vt_lb_statistics) {
return;
}

nlohmann::json j;
j["pre-LB"] = lb::jsonifyPhaseStatistics(statistics);

if (!statistics_writer_) {
createStatisticsFile();
}

using JSONAppender = util::json::Appender<std::ofstream>;
auto writer = static_cast<JSONAppender*>(statistics_writer_.get());
writer->stageObject(j);
Expand All @@ -564,22 +562,26 @@ void LBManager::stagePostLBStatistics(
const StatisticMapType &statistics, int32_t migration_count
) {
// Statistics output when LB is enabled and appropriate flag is enabled
if (!theConfig()->vt_lb_statistics) {
if (theContext()->getNode() != 0 or !theConfig()->vt_lb_statistics) {
return;
}

nlohmann::json j;
j["post-LB"] = lb::jsonifyPhaseStatistics(statistics);
j["migration count"] = migration_count;

if (!statistics_writer_) {
createStatisticsFile();
}

using JSONAppender = util::json::Appender<std::ofstream>;
auto writer = static_cast<JSONAppender*>(statistics_writer_.get());
writer->stageObject(j);
}

void LBManager::commitPhaseStatistics(PhaseType phase) {
// Statistics output when LB is enabled and appropriate flag is enabled
if (!theConfig()->vt_lb_statistics) {
if (theContext()->getNode() != 0 or !theConfig()->vt_lb_statistics) {
return;
}

Expand All @@ -591,6 +593,10 @@ void LBManager::commitPhaseStatistics(PhaseType phase) {
nlohmann::json j;
j["id"] = phase;

if (!statistics_writer_) {
createStatisticsFile();
}

using JSONAppender = util::json::Appender<std::ofstream>;
auto writer = static_cast<JSONAppender*>(statistics_writer_.get());
writer->stageObject(j);
Expand Down
1 change: 0 additions & 1 deletion src/vt/vrt/collection/balance/lb_invoke/lb_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ struct LBManager : runtime::component::Component<LBManager> {
std::string name() override { return "LBManager"; }

void startup() override;
void initialize() override;
void finalize() override;
void fatalError() override;

Expand Down

0 comments on commit 2b7ca89

Please sign in to comment.