From 6a6696c4083e28d3d48363f3166c9d95e0524b81 Mon Sep 17 00:00:00 2001 From: Brett Dutro Date: Tue, 30 Apr 2024 13:10:59 -0500 Subject: [PATCH] Fix reporting bug where ContextCounters have their per-context counts printed twice --- sparta/sparta/report/Report.hpp | 4 ++-- sparta/src/Report.cpp | 14 +++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/sparta/sparta/report/Report.hpp b/sparta/sparta/report/Report.hpp index 3149a0b106..130d917572 100644 --- a/sparta/sparta/report/Report.hpp +++ b/sparta/sparta/report/Report.hpp @@ -401,7 +401,7 @@ namespace sparta * by another item immediately in this report (not the name of a * subreport or item in a subreport) */ - StatAdder add(const StatisticInstance& si, const std::string& name=""); + StatAdder add(const StatisticInstance& si, const std::string& name="", const bool recurse=true); /*! * \brief Moves an existing statistic instance into this Report @@ -414,7 +414,7 @@ namespace sparta * by another item immediately in this report (not the name of a * subreport or item in a subreport) */ - StatAdder add(StatisticInstance&& si, const std::string& name=""); + StatAdder add(StatisticInstance&& si, const std::string& name="", const bool recurse=true); /*! * \brief Add a StatisticDef to the report diff --git a/sparta/src/Report.cpp b/sparta/src/Report.cpp index fd7571e758..a06a9c307b 100644 --- a/sparta/src/Report.cpp +++ b/sparta/src/Report.cpp @@ -1150,7 +1150,7 @@ class ReportFileParserYAML std::string filename_; //!< For recalling errors }; // class ReportFileParserYAML -Report::StatAdder Report::add(const StatisticInstance& si, const std::string& name) { +Report::StatAdder Report::add(const StatisticInstance& si, const std::string& name, const bool recurse) { if(name != "" && stat_names_.find(name) != stat_names_.end()){ throw SpartaException("There is already a statistic instance in this Report (") << getName() << ") named \"" << name << "\" pointing to " @@ -1164,12 +1164,14 @@ Report::StatAdder Report::add(const StatisticInstance& si, const std::string& na if(name != ""){ stat_names_.insert(name); } - addSubStatistics_(&si); + if(recurse) { + addSubStatistics_(&si); + } return Report::StatAdder(*this); } -Report::StatAdder Report::add(StatisticInstance&& si, const std::string& name) { +Report::StatAdder Report::add(StatisticInstance&& si, const std::string& name, const bool recurse) { if(name != "" && stat_names_.find(name) != stat_names_.end()){ throw SpartaException("There is already a statistic instance in this Report (") << getName() << ") named \"" << name << "\" pointing to " @@ -1183,7 +1185,9 @@ Report::StatAdder Report::add(StatisticInstance&& si, const std::string& name) { if(name != ""){ stat_names_.insert(name); } - addSubStatistics_(&si); + if(recurse) { + addSubStatistics_(&si); + } return Report::StatAdder(*this); } @@ -1416,7 +1420,7 @@ void Report::recursAddSubtree_(const TreeNode* n, //for(auto& s : stats_){ // std::cerr << " Stat " << s.second->stringize() << " " << s.second->getLocation() << std::endl; //} - add(n, child_stat_prefix + n->getName()); + add(n, child_stat_prefix + n->getName(), false); } }