[gem5-dev] Change in gem5/gem5[develop]: base: Add support for resolving stats within groups by name

2020-04-29 Thread Nikos Nikoleris (Gerrit) via gem5-dev
Nikos Nikoleris has submitted this change. (  
https://gem5-review.googlesource.com/c/public/gem5/+/27890 )


Change subject: base: Add support for resolving stats within groups by name
..

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 
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/27890
Reviewed-by: Bobby R. Bruce 
Reviewed-by: Andreas Sandberg 
Maintainer: Andreas Sandberg 
Tested-by: kokoro 
---
M src/base/stats/group.cc
M src/base/stats/group.hh
M src/python/pybind11/stats.cc
3 files changed, 51 insertions(+), 2 deletions(-)

Approvals:
  Andreas Sandberg: Looks good to me, approved; Looks good to me, approved
  Bobby R. Bruce: Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/base/stats/group.cc b/src/base/stats/group.cc
index d054b7a..06eaa46 100644
--- a/src/base/stats/group.cc
+++ b/src/base/stats/group.cc
@@ -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 @@
 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  : stats) {
+if (info->name == name) {
+return info;
+}
+}
+} else {
+// look for the stat in subgroups
+const std::string gname = name.substr(0, pos);
+for (auto  : 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  : mergedStatGroups) {
+auto info = g->resolveStat(name);
+if (info) {
+return info;
+}
+}
+
+return nullptr;
+}
+
 void
 Group::mergeStatGroup(Group *block)
 {
diff --git a/src/base/stats/group.hh b/src/base/stats/group.hh
index f54df5c..4fd9e79 100644
--- a/src/base/stats/group.hh
+++ b/src/base/stats/group.hh
@@ -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 @@
  */
 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.
diff --git a/src/python/pybind11/stats.cc b/src/python/pybind11/stats.cc
index 32c3b8b..1149eba 100644
--- a/src/python/pybind11/stats.cc
+++ b/src/python/pybind11/stats.cc
@@ -128,5 +128,6 @@
 .def("getStats", ::Group::getStats)
 .def("getStatGroups", ::Group::getStatGroups)
 .def("addStatGroup", ::Group::addStatGroup)
+.def("resolveStat", ::Group::resolveStat)
 ;
 }

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/27890
To unsubscribe, or for help writing mail filters, visit  
https://gem5-review.googlesource.com/settings


Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I5af8401b38b41aee611728f6d1a595f99d22d9de
Gerrit-Change-Number: 27890
Gerrit-PatchSet: 2
Gerrit-Owner: Nikos Nikoleris 
Gerrit-Reviewer: Andreas Sandberg 
Gerrit-Reviewer: Bobby R. Bruce 
Gerrit-Reviewer: Giacomo Travaglini 
Gerrit-Reviewer: Jason Lowe-Power 
Gerrit-Reviewer: Nikos Nikoleris 
Gerrit-Reviewer: kokoro 
Gerrit-MessageType: merged
___
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s


[gem5-dev] Change in gem5/gem5[develop]: base: Add support for resolving stats within groups by name

2020-04-20 Thread Nikos Nikoleris (Gerrit)
Nikos Nikoleris has uploaded this change for review. (  
https://gem5-review.googlesource.com/c/public/gem5/+/27890 )



Change subject: base: Add support for resolving stats within groups by name
..

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 
---
M src/base/stats/group.cc
M src/base/stats/group.hh
M src/python/pybind11/stats.cc
3 files changed, 51 insertions(+), 2 deletions(-)



diff --git a/src/base/stats/group.cc b/src/base/stats/group.cc
index d054b7a..06eaa46 100644
--- a/src/base/stats/group.cc
+++ b/src/base/stats/group.cc
@@ -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 @@
 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  : stats) {
+if (info->name == name) {
+return info;
+}
+}
+} else {
+// look for the stat in subgroups
+const std::string gname = name.substr(0, pos);
+for (auto  : 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  : mergedStatGroups) {
+auto info = g->resolveStat(name);
+if (info) {
+return info;
+}
+}
+
+return nullptr;
+}
+
 void
 Group::mergeStatGroup(Group *block)
 {
diff --git a/src/base/stats/group.hh b/src/base/stats/group.hh
index f54df5c..4fd9e79 100644
--- a/src/base/stats/group.hh
+++ b/src/base/stats/group.hh
@@ -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 @@
  */
 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.
diff --git a/src/python/pybind11/stats.cc b/src/python/pybind11/stats.cc
index 32c3b8b..1149eba 100644
--- a/src/python/pybind11/stats.cc
+++ b/src/python/pybind11/stats.cc
@@ -128,5 +128,6 @@
 .def("getStats", ::Group::getStats)
 .def("getStatGroups", ::Group::getStatGroups)
 .def("addStatGroup", ::Group::addStatGroup)
+.def("resolveStat", ::Group::resolveStat)
 ;
 }

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/27890
To unsubscribe, or for help writing mail filters, visit  
https://gem5-review.googlesource.com/settings


Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I5af8401b38b41aee611728f6d1a595f99d22d9de
Gerrit-Change-Number: 27890
Gerrit-PatchSet: 1
Gerrit-Owner: Nikos Nikoleris 
Gerrit-MessageType: newchange
___
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev