From 3e3152fe0b69b9279729d1de878da2a84ba41826 Mon Sep 17 00:00:00 2001 From: Andreas Sandberg Date: Mon, 5 Oct 2020 15:13:06 +0100 Subject: [PATCH] stats: Make Stats::Group::mergeStatGroup public The stat system currently assumes that the decision to merge groups is done at construction time. This makes it hard to implement global statistics that live in a single global group. This change adds some error checking to mergeStatGroup and marks it as a public method. Change-Id: I6a42f48545c5ccfcd0672bae66a5bc86bb042f13 Signed-off-by: Andreas Sandberg Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/35615 Reviewed-by: Jason Lowe-Power Maintainer: Jason Lowe-Power Tested-by: kokoro --- src/base/stats/group.cc | 17 ++++++++++++++++- src/base/stats/group.hh | 3 +-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/base/stats/group.cc b/src/base/stats/group.cc index a76ad4f31..f1eda1d6d 100644 --- a/src/base/stats/group.cc +++ b/src/base/stats/group.cc @@ -47,7 +47,7 @@ namespace Stats { Group::Group(Group *parent, const char *name) - : mergedParent(name ? nullptr : parent) + : mergedParent(nullptr) { if (parent && name) { parent->addStatGroup(name, this); @@ -152,7 +152,22 @@ Group::resolveStat(std::string name) const void Group::mergeStatGroup(Group *block) { + panic_if(!block, "No stat block provided"); + panic_if(block->mergedParent, + "Stat group already merged into another group"); + panic_if(block == this, "Stat group can't merge with itself"); + + // Track the new stat group mergedStatGroups.push_back(block); + + // We might not have seen stats that were associated with the + // child group before it was merged, so add them here. + for (auto &s : block->stats) + addStat(s); + + // Setup the parent pointer so the child know that it needs to + // register new stats with the parent. + block->mergedParent = this; } const std::map & diff --git a/src/base/stats/group.hh b/src/base/stats/group.hh index 985bf61f6..ef223bce6 100644 --- a/src/base/stats/group.hh +++ b/src/base/stats/group.hh @@ -194,7 +194,6 @@ class Group */ const Info * resolveStat(std::string name) const; - private: /** * Merge the contents (stats & children) of a block to this block. * @@ -205,7 +204,7 @@ class Group private: /** Parent pointer if merged into parent */ - Group *const mergedParent; + Group *mergedParent; std::map statGroups; std::vector mergedStatGroups; -- 2.30.2