From ee5b65955e06369a202ff2d4afb783415ad68344 Mon Sep 17 00:00:00 2001 From: "Bobby R. Bruce" Date: Tue, 28 Dec 2021 16:29:47 -0800 Subject: [PATCH] python: Fix `get_simstat` func for non-Root SimObject case The `get_simstat` function in `src/python/m5/stats/gem5stats.py` was returning an error when a non-Root Simobject was passed: ``` AttributeError: object 'PyTrafficGen' has no attribute 'name' At: build/NULL_MESI_Two_Level/python/m5/SimObject.py(1430): __getattr__ build/NULL_MESI_Two_Level/python/m5/stats/gem5stats.py(279): get_simstat ``` The issue was an assumption that SimObjects have a field `name`. They do not. To get a SimObject's name the `get_name()` function must be used. This patch fixes this issue. In addition to this fix, the documentation in this function has been improved to state more clearly what can be passed and what shall be returned. Previously it was somewhat unclear. Change-Id: I33538120015280bb6260ccf8eba6b75ff43d280e Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/54943 Reviewed-by: Bobby Bruce Maintainer: Bobby Bruce Tested-by: kokoro --- src/python/m5/stats/gem5stats.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/python/m5/stats/gem5stats.py b/src/python/m5/stats/gem5stats.py index 9a2259aab5..3b4bc7eb6c 100644 --- a/src/python/m5/stats/gem5stats.py +++ b/src/python/m5/stats/gem5stats.py @@ -234,17 +234,21 @@ def _prepare_stats(group: _m5.stats.Group): _prepare_stats(child) -def get_simstat(root: Union[Root, List[SimObject]], +def get_simstat(root: Union[SimObject, List[SimObject]], prepare_stats: bool = True) -> SimStat: """ - This function will return the SimStat object for a simulation. From the - SimStat object all stats within the current gem5 simulation are present. + This function will return the SimStat object for a simulation given a + SimObject (typically a Root SimObject), or list of SimObjects. The returned + SimStat object will contain all the stats for all the SimObjects contained + within the "root", inclusive of the "root" SimObject/SimObjects. Parameters ---------- - root: Union[Root, List[Root]] - The root, or a list of Simobjects, of the simulation for translation to - a SimStat object. + root: Union[SimObject, List[SimObject]] + A SimObject, or list of SimObjects, of the simulation for translation + into a SimStat object. Typically this is the simulation's Root + SimObject as this will obtain the entirety of a run's statistics in a + single SimStat object. prepare_stats: bool Dictates whether the stats are to be prepared prior to creating the @@ -269,6 +273,8 @@ def get_simstat(root: Union[Root, List[SimObject]], for r in root: if isinstance(r, Root): + # The Root is a special case, we jump directly into adding its + # constituent Groups. if prepare_stats: _prepare_stats(r) for key in r.getStatGroups(): @@ -276,12 +282,11 @@ def get_simstat(root: Union[Root, List[SimObject]], elif isinstance(r, SimObject): if prepare_stats: _prepare_stats(r) - stats_map[r.name] = get_stats_group(r) + stats_map[r.get_name()] = get_stats_group(r) else: - raise TypeError("Object (" + str(r) + ") passed is neither Root " - "nor SimObject. " + __name__ + " only processes " - "Roots, SimObjects, or a list of Roots and/or " - "SimObjects.") + raise TypeError("Object (" + str(r) + ") passed is not a " + "SimObject. " + __name__ + " only processes " + "SimObjects, or a list of SimObjects.")