stats: Add a preDumpStats() callback to Stats::Group

Some objects need to know that we are about to dump stats to perform
prepare statistics. This is currently done by registering a callback
with the stat system. Expose this callback as a virtual method
in Stats::Group to make this pattern more convenient.

Change-Id: I5aa475b7d04c288e45f5f413ab7a1907b971dae5
Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/21139
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br>
This commit is contained in:
Andreas Sandberg
2019-09-24 10:41:17 +01:00
parent 4f52287500
commit 7e52bf014a
4 changed files with 22 additions and 0 deletions

View File

@@ -93,6 +93,16 @@ Group::resetStats()
g.second->resetStats();
}
void
Group::preDumpStats()
{
for (auto &g : mergedStatGroups)
g->preDumpStats();
for (auto &g : statGroups)
g.second->preDumpStats();
}
void
Group::addStat(Stats::Info *info)
{

View File

@@ -127,6 +127,13 @@ class Group
*/
virtual void resetStats();
/**
* Callback before stats are dumped. This can be overridden by
* objects that need to perform calculations in addition to the
* capabiltiies implemented in the stat framework.
*/
virtual void preDumpStats();
/**
* Register a stat with this group. This method is normally called
* automatically when a stat is instantiated.

View File

@@ -371,6 +371,10 @@ def dump(root=None):
# Only prepare stats the first time we dump them in the same tick.
if new_dump:
_m5.stats.processDumpQueue()
# Notify new-style stats group that we are about to dump stats.
sim_root = Root.getInstance()
if sim_root:
sim_root.preDumpStats();
prepare()
for output in outputList:

View File

@@ -127,6 +127,7 @@ pybind_init_stats(py::module &m_native)
m, "Group")
.def("regStats", &Stats::Group::regStats)
.def("resetStats", &Stats::Group::resetStats)
.def("preDumpStats", &Stats::Group::preDumpStats)
.def("getStats", &Stats::Group::getStats)
.def("getStatGroups", &Stats::Group::getStatGroups)
.def("addStatGroup", &Stats::Group::addStatGroup)