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+kokoro@google.com> Maintainer: Bobby Bruce <bbruce@ucdavis.edu> Reviewed-by: Bobby Bruce <bbruce@ucdavis.edu>
This commit is contained in:
committed by
Bobby Bruce
parent
be33be87da
commit
4a06375212
@@ -56,7 +56,7 @@ class Group(SerializableStat):
|
||||
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 @@ class Group(SerializableStat):
|
||||
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 @@ class Vector(Group):
|
||||
|
||||
def __init__(self, scalar_map: Mapping[str, Scalar]):
|
||||
super().__init__(type="Vector", time_conversion=None, **scalar_map)
|
||||
|
||||
def _repr_name(self) -> str:
|
||||
return "Vector"
|
||||
|
||||
@@ -56,6 +56,9 @@ class Statistic(ABC, SerializableStat):
|
||||
self.description = description
|
||||
self.datatype = datatype
|
||||
|
||||
def __repr__(self):
|
||||
return str(self.value)
|
||||
|
||||
|
||||
class Scalar(Statistic):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user