Jason Lowe-Power has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/41603 )
Change subject: python: Add find function to pystats groups
......................................................................
python: Add find function to pystats groups
The `find` function allows users to "search" for a statistic or group
within a group. For instance, you might want to find all of the groups
within the system which have the name "cpu{i}". This is useful for
aggregate statistic values across multiple components.
Example:
total_instruuctions = sum([cpu.exec_context.thread_0.numInsts.value
for cpu in simstat.system.find('cpu')])
The find functino matches based on substring. If the name given the find
function is a substring of the stat name or the group name the
stat/group will be returned. I considered making this perform the same
as the `like` operator in SQL or as a full regex, but decided this
simple implementation will cover almost all use cases.
Change-Id: I31c2a029d8a6b1d97225ab4efa34a4d13147ea32
Signed-off-by: Jason Lowe-Power <ja...@lowepower.com>
---
M src/python/m5/pystats/group.py
1 file changed, 26 insertions(+), 2 deletions(-)
diff --git a/src/python/m5/pystats/group.py b/src/python/m5/pystats/group.py
index 0316d23..b72ab2f 100644
--- a/src/python/m5/pystats/group.py
+++ b/src/python/m5/pystats/group.py
@@ -24,7 +24,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-from typing import Dict, List, Optional, Union
+from typing import Dict, Iterator, List, Optional, Union
from .jsonserializable import JsonSerializable
from .statistic import Scalar, Statistic
@@ -53,6 +53,30 @@
for key,value in kwargs.items():
setattr(self, key, value)
+ def find(self, name: str) -> Iterator[Union["Group", Statistic]]:
+ """ Find all stats that match the name
+
+ This function searches all of the "children" in this group. It
yields
+ the set of attributes (children) that have the `name` as a
substring.
+ The order of the objects returned by the generator is arbitrary.
+
+ ```
+ system.find('cpu') -> [cpu0, cpu1, cpu2, cpu3, other_cpu, ...]
+ ```
+
+ This is useful for performing aggregates over substats. For
instance:
+
+ ```
+ total_instruuctions = sum([cpu.exec_context.thread_0.numInsts.value
+ for cpu in simstat.system.find('cpu')])
+ ```
+ """
+ for attr in self.__dict__:
+ if name in attr:
+ obj = getattr(self, attr)
+ if isinstance(obj, Group) or isinstance(obj, Statistic):
+ yield obj
+
class Vector(Group):
"""
This Vector class is used to store vector information. However, in gem5
@@ -66,4 +90,4 @@
type="Vector",
timeConversion=None,
**scalar_map,
- )
\ No newline at end of file
+ )
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/41603
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: I31c2a029d8a6b1d97225ab4efa34a4d13147ea32
Gerrit-Change-Number: 41603
Gerrit-PatchSet: 1
Gerrit-Owner: Jason Lowe-Power <power...@gmail.com>
Gerrit-MessageType: newchange
_______________________________________________
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