base, python, sim: Add support for resoving a stat using its name
authorNikos Nikoleris <nikos.nikoleris@arm.com>
Tue, 7 Apr 2020 15:04:41 +0000 (16:04 +0100)
committerNikos Nikoleris <nikos.nikoleris@arm.com>
Wed, 29 Apr 2020 21:02:32 +0000 (21:02 +0000)
This CL adds resolve, a function in the Stats namespace that allows
access to a stat as specified by its name.

Change-Id: I4fa8bed394b4cb35d9c6cf5d8db062b8d6bb9ca5
Signed-off-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/27891
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/base/statistics.cc
src/base/statistics.hh

index 036029b4a96057784e942124465a0f163dfb19d5..e4315baf9f8ba58d55cd4e29d22aa39e288a0009 100644 (file)
@@ -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
@@ -54,6 +54,7 @@
 #include "base/str.hh"
 #include "base/time.hh"
 #include "base/trace.hh"
+#include "sim/root.hh"
 
 using namespace std;
 
@@ -573,6 +574,17 @@ reset()
         fatal("No registered Stats::reset handler");
 }
 
+const Info *
+resolve(const std::string &name)
+{
+    const auto &it = nameMap().find(name);
+    if (it != nameMap().cend()) {
+        return it->second;
+    } else {
+        return Root::root()->resolveStat(name);
+    }
+}
+
 void
 registerDumpCallback(Callback *cb)
 {
index 24a0d06de00a3f1a3bb1a9179b2f6f1b3e207ece..8f665fe0e8e0de42d4c9c4e552c5f40b0af8a3ae 100644 (file)
@@ -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
@@ -3349,6 +3349,7 @@ void dump();
 void reset();
 void enable();
 bool enabled();
+const Info* resolve(const std::string &name);
 
 /**
  * Register reset and dump handlers.  These are the functions which