Bobby Bruce has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/63271?usp=email )

 (

9 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.
 )Change subject: stdlib: Add __repr__ to pystats
......................................................................

stdlib: Add __repr__ to pystats

For Statistics the value is returned. E.g.:

```
print(simstats.board.core.some_integer)
5
```

For Groups the names of the stats in that group are listed.
E.g.:

```
print(stats.board.core)
[Group: [some_integer, another_stat, another_group]]
```

Change-Id: I94cea907608fba622f4fc141d5b22ac95d8cde40
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/63271
Tested-by: kokoro <noreply+kok...@google.com>
Maintainer: Bobby Bruce <bbr...@ucdavis.edu>
Reviewed-by: Bobby Bruce <bbr...@ucdavis.edu>
---
M src/python/m5/ext/pystats/group.py
M src/python/m5/ext/pystats/statistic.py
2 files changed, 44 insertions(+), 1 deletion(-)

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




diff --git a/src/python/m5/ext/pystats/group.py b/src/python/m5/ext/pystats/group.py
index 6e2da87..680a5d5 100644
--- a/src/python/m5/ext/pystats/group.py
+++ b/src/python/m5/ext/pystats/group.py
@@ -56,7 +56,7 @@
         time_conversion: Optional[TimeConversion] = None,
         **kwargs: Dict[
str, Union["Group", Statistic, List["Group"], List["Statistic"]]
-        ]
+        ],
     ):
         if type is None:
             self.type = "Group"
@@ -140,6 +140,15 @@
             pattern = regex
         yield from self.children(lambda _name: bool(pattern.search(_name)))

+    def _repr_name(self) -> str:
+        return "Group"
+
+    def __repr__(self) -> str:
+        stats_list = []
+        for key in self.__dict__:
+            stats_list.append(key)
+        return f"{self._repr_name()}: {stats_list}"
+

 class Vector(Group):
     """
@@ -152,3 +161,6 @@

     def __init__(self, scalar_map: Mapping[str, Scalar]):
         super().__init__(type="Vector", time_conversion=None, **scalar_map)
+
+    def _repr_name(self) -> str:
+        return "Vector"
diff --git a/src/python/m5/ext/pystats/statistic.py b/src/python/m5/ext/pystats/statistic.py
index 446c9ba..b018060 100644
--- a/src/python/m5/ext/pystats/statistic.py
+++ b/src/python/m5/ext/pystats/statistic.py
@@ -56,6 +56,9 @@
         self.description = description
         self.datatype = datatype

+    def __repr__(self):
+        return str(self.value)
+

 class Scalar(Statistic):
     """

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/63271?usp=email 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: I94cea907608fba622f4fc141d5b22ac95d8cde40
Gerrit-Change-Number: 63271
Gerrit-PatchSet: 14
Gerrit-Owner: Bobby Bruce <bbr...@ucdavis.edu>
Gerrit-Reviewer: Bobby Bruce <bbr...@ucdavis.edu>
Gerrit-Reviewer: Jason Lowe-Power <power...@gmail.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org

Reply via email to