stats: Ignore non-Group objects in stat hierarchy

Some objects, such as SystemC modules, are not a subclass of
Stat::Group. Calling the addStatGroup function on them causes errors.
This changes ignores those objects that are not Stat::Group in the stat

Signed-off-by: Chun-Chen TK Hsu <>
Change-Id: I9b62419417b7af7331461fbfaf15e45a4ee2b35f
Reviewed-by: Jason Lowe-Power <>
Reviewed-by: Andreas Sandberg <>
Maintainer: Jason Lowe-Power <>
Maintainer: Andreas Sandberg <>
Tested-by: kokoro <>
diff --git a/src/python/m5/stats/ b/src/python/m5/stats/
index 77ed5e8..4b118ea 100644
--- a/src/python/m5/stats/
+++ b/src/python/m5/stats/
@@ -257,7 +257,19 @@
             for idx, obj in enumerate(obj):
                 _bind_obj("{}{}".format(name, idx), obj)
-            root.addStatGroup(name, obj.getCCObject())
+            # We need this check because not all obj.getCCObject() is an
+            # instance of Stat::Group. For example, sc_core::sc_module, the C++
+            # class of SystemC_ScModule, is not a subclass of Stat::Group. So
+            # it will cause a type error if obj is a SystemC_ScModule when
+            # calling addStatGroup().
+            if isinstance(obj.getCCObject(), _m5.stats.Group):
+                parent = root
+                while parent:
+                    if hasattr(parent, 'addStatGroup'):
+                        parent.addStatGroup(name, obj.getCCObject())
+                        break
+                    parent = parent.get_parent();
     for name, obj in root._children.items():