python: Add search functions to pystats groups
This change adds three functions, a `children` function which will
iterate through all of the children of group based (optionally) on some
predicate. Then, it implements a `find` function and a `find_re`
function using the `children` function.
The `find` function allows users to match statistics or groups
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 function 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.
The `find_re` function is the same as find, but matches a regular
expression instead of a simple substring match.
Change-Id: I31c2a029d8a6b1d97225ab4efa34a4d13147ea32
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/41603
Reviewed-by: Bobby R. Bruce <bbruce@ucdavis.edu>
Maintainer: Bobby R. Bruce <bbruce@ucdavis.edu>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
committed by
Jason Lowe-Power
parent
3a1eadc04d
commit
649e5cd8e0
@@ -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,26 @@ class Group(JsonSerializable):
|
||||
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):
|
||||
"""
|
||||
The Vector class is used to store vector information. However, in gem5
|
||||
|
||||
Reference in New Issue
Block a user