base: Add support for resolving stats within groups by name
This change adds a member function to the Group class that returns a
stat given its name. The function will go through all stats in the
group and its subgroups and will return the stat that matches the
name. For example, if g is the Group system.bigCluster.cpus then a
call to
p = g.resolveStat("ipc")
will return a pointer to the stat system.bigCluster.cpus.ipc.
Change-Id: I5af8401b38b41aee611728f6d1a595f99d22d9de
Signed-off-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/27890
Reviewed-by: Bobby R. Bruce <bbruce@ucdavis.edu>
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2019 Arm Limited
|
||||
* Copyright (c) 2019, 2020 Arm Limited
|
||||
* All rights reserved
|
||||
*
|
||||
* The license below extends only to copyright in the software and shall
|
||||
@@ -117,6 +117,38 @@ Group::addStatGroup(const char *name, Group *block)
|
||||
statGroups[name] = block;
|
||||
}
|
||||
|
||||
const Info *
|
||||
Group::resolveStat(std::string name) const
|
||||
{
|
||||
auto pos = name.find(".");
|
||||
if (pos == std::string::npos) {
|
||||
// look for the stat in this group
|
||||
for (auto &info : stats) {
|
||||
if (info->name == name) {
|
||||
return info;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// look for the stat in subgroups
|
||||
const std::string gname = name.substr(0, pos);
|
||||
for (auto &g : statGroups) {
|
||||
if (g.first == gname) {
|
||||
return g.second->resolveStat(name.substr(pos + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// finally look for the stat in groups that have been merged
|
||||
for (auto &g : mergedStatGroups) {
|
||||
auto info = g->resolveStat(name);
|
||||
if (info) {
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
Group::mergeStatGroup(Group *block)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2019 Arm Limited
|
||||
* Copyright (c) 2019, 2020 Arm Limited
|
||||
* All rights reserved
|
||||
*
|
||||
* The license below extends only to copyright in the software and shall
|
||||
@@ -157,6 +157,22 @@ class Group
|
||||
*/
|
||||
void addStatGroup(const char *name, Group *block);
|
||||
|
||||
/**
|
||||
* Resolve a stat by its name within this group.
|
||||
*
|
||||
* This method goes through the stats in this group and sub-groups
|
||||
* and returns a pointer to the the stat that matches the provided
|
||||
* name. The input name has to be relative to the name of this
|
||||
* group. For example, if this group is the SimObject
|
||||
* system.bigCluster.cpus and we want the stat
|
||||
* system.bigCluster.cpus.ipc, the input param should be the
|
||||
* string "ipc".
|
||||
*
|
||||
* @param name Name of the desired stat
|
||||
* @return Pointer to the stat with the provided name
|
||||
*/
|
||||
const Info * resolveStat(std::string name) const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Merge the contents (stats & children) of a block to this block.
|
||||
|
||||
@@ -128,5 +128,6 @@ pybind_init_stats(py::module &m_native)
|
||||
.def("getStats", &Stats::Group::getStats)
|
||||
.def("getStatGroups", &Stats::Group::getStatGroups)
|
||||
.def("addStatGroup", &Stats::Group::addStatGroup)
|
||||
.def("resolveStat", &Stats::Group::resolveStat)
|
||||
;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user