Nikos Nikoleris has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/27891 )
Change subject: base, python, sim: Add support for resoving a stat using
its name
..
base, python, sim: Add support for resoving a stat using its name
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
---
M src/base/statistics.cc
M src/base/statistics.hh
M src/python/m5/stats/__init__.py
M src/python/pybind11/stats.cc
M src/sim/stat_register.cc
5 files changed, 47 insertions(+), 10 deletions(-)
diff --git a/src/base/statistics.cc b/src/base/statistics.cc
index 036029b..21641d7 100644
--- a/src/base/statistics.cc
+++ b/src/base/statistics.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
@@ -507,14 +507,17 @@
return root ? root->str() : "";
}
-Handler resetHandler = NULL;
-Handler dumpHandler = NULL;
+Handler resetHandler = nullptr;
+Handler dumpHandler = nullptr;
+ResolveHandler resolveHandler = nullptr;
void
-registerHandlers(Handler reset_handler, Handler dump_handler)
+registerHandlers(Handler reset_handler, Handler dump_handler,
+ ResolveHandler resolve_handler)
{
resetHandler = reset_handler;
dumpHandler = dump_handler;
+resolveHandler = resolve_handler;
}
CallbackQueue dumpQueue;
@@ -573,6 +576,15 @@
fatal("No registered Stats::reset handler");
}
+Info *
+resolve(const std::string )
+{
+if (resolveHandler)
+return resolveHandler(name);
+else
+fatal("No registered Stats::resolve handler");
+}
+
void
registerDumpCallback(Callback *cb)
{
diff --git a/src/base/statistics.hh b/src/base/statistics.hh
index 24a0d06..639df38 100644
--- a/src/base/statistics.hh
+++ b/src/base/statistics.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
@@ -3349,6 +3349,7 @@
void reset();
void enable();
bool enabled();
+Info* resolve(const std::string );
/**
* Register reset and dump handlers. These are the functions which
@@ -3356,8 +3357,10 @@
* including processing the reset/dump callbacks
*/
typedef void (*Handler)();
+typedef Info* (*ResolveHandler)(const std::string &);
-void registerHandlers(Handler reset_handler, Handler dump_handler);
+void registerHandlers(Handler reset_handler, Handler dump_handler,
+ ResolveHandler resolve_handler);
/**
* Register a callback that should be called whenever statistics are
diff --git a/src/python/m5/stats/__init__.py
b/src/python/m5/stats/__init__.py
index 7b810c6..9e1c20b 100644
--- a/src/python/m5/stats/__init__.py
+++ b/src/python/m5/stats/__init__.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2017-2019 ARM Limited
+# Copyright (c) 2017-2020 ARM Limited
# All rights reserved.
#
# The license below extends only to copyright in the software and shall
@@ -394,6 +394,19 @@
_m5.stats.processResetQueue()
+def resolve(name):
+'''Look up and return the stat with the given name'''
+
+# First search the global dict for the stats
+if name in stats_dict:
+return stats_dict[name]
+else:
+# Otherwise the stat might be in a StatGroup
+root = Root.getInstance()
+if root:
+stat = root.resolveStat(name)
+return stat
+
flags = attrdict({
'none': 0x,
'init': 0x0001,
diff --git a/src/python/pybind11/stats.cc b/src/python/pybind11/stats.cc
index 1149eba..72d0435 100644
--- a/src/python/pybind11/stats.cc
+++ b/src/python/pybind11/stats.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 ARM Limited
+ * Copyright (c) 2017-2020 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
@@ -70,6 +70,14 @@
m.attr("reset")();
}
+Info*
+pythonResolve(const std::string )
+{
+py::module m = py::module::import("m5.stats");
+py::object result_py = m.attr("resolve")(name);
+return result_py.cast();
+}
+
}
void
diff --git a/src/sim/stat_register.cc b/src/sim/stat_register.cc
index d7242a6..a924fe8 100644
--- a/src/sim/stat_register.cc
+++ b/src/sim/stat_register.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014 ARM Limited
+ * Copyright (c) 2014, 2020 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
@@ -44,10 +44,11 @@
extern void pythonDump();
extern void pythonReset();
+extern Info* pythonResolve(const std::string );
void registerPythonStatsHandlers()
{
-registerHandlers(pythonReset, pythonDump);
+