Bobby Bruce has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/54943 )

Change subject: python: Fix `get_simstat` func for non-Root SimObject case
......................................................................

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 <bbr...@ucdavis.edu>
Maintainer: Bobby Bruce <bbr...@ucdavis.edu>
Tested-by: kokoro <noreply+kok...@google.com>
---
M src/python/m5/stats/gem5stats.py
1 file changed, 47 insertions(+), 11 deletions(-)

Approvals:
  Bobby Bruce: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass




diff --git a/src/python/m5/stats/gem5stats.py b/src/python/m5/stats/gem5stats.py
index 9a2259a..3b4bc7e 100644
--- a/src/python/m5/stats/gem5stats.py
+++ b/src/python/m5/stats/gem5stats.py
@@ -234,17 +234,21 @@
         _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 @@

     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 @@
         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.")




--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/54943
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: I33538120015280bb6260ccf8eba6b75ff43d280e
Gerrit-Change-Number: 54943
Gerrit-PatchSet: 3
Gerrit-Owner: Bobby Bruce <bbr...@ucdavis.edu>
Gerrit-Reviewer: Andreas Sandberg <andreas.sandb...@arm.com>
Gerrit-Reviewer: Bobby Bruce <bbr...@ucdavis.edu>
Gerrit-Reviewer: Jason Lowe-Power <ja...@lowepower.com>
Gerrit-Reviewer: Jason Lowe-Power <power...@gmail.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-CC: Gabe Black <gabe.bl...@gmail.com>
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

Reply via email to