diff --git a/src/radical/analytics/entity.py b/src/radical/analytics/entity.py index 8b3916f..1abf634 100644 --- a/src/radical/analytics/entity.py +++ b/src/radical/analytics/entity.py @@ -28,6 +28,10 @@ def __init__(self, _uid, _profile, _details): self._cfg = self._details.get('cfg', dict()) self._resources = self._details.get('resources', dict()) + self._name = self._description.get('name') \ + or self._description.get('job_name') \ + or self._uid + # if have no etype tree information, guess the etype from uid if not self._etype: self._etype = self._uid.split('.')[0] @@ -64,6 +68,7 @@ def __getstate__(self): state = { 'uid' : self._uid, + 'name' : self._name, 'etype' : self._etype, 'details' : self._details, 'description' : self._description, @@ -101,6 +106,10 @@ def __setstate__(self, state): self._t_stop = state['t_stop'] self._ttc = state['ttc'] + self._name = self._description.get('name') \ + or self._description.get('job_name') \ + or self._uid + # -------------------------------------------------------------------------- # @@ -124,6 +133,10 @@ def t_range(self): def uid(self): return self._uid + @property + def name(self): + return self._name + @property def etype(self): return self._etype diff --git a/src/radical/analytics/session.py b/src/radical/analytics/session.py index 9ef7798..560c1c4 100644 --- a/src/radical/analytics/session.py +++ b/src/radical/analytics/session.py @@ -478,14 +478,15 @@ def _initialize_properties(self): # -------------------------------------------------------------------------- # - def _apply_filter(self, etype=None, uid=None, state=None, - event=None, time=None): + def _apply_filter(self, etype=None, uid=None, name=None, + state=None, event=None, time=None): # iterate through all self._entities and collect UIDs of all entities # which match the given set of filters (after removing all events which # are not in the given time ranges) etype = ru.as_list(etype) uids = ru.as_list(uid) + names = ru.as_list(name) state = ru.as_list(state) event = ru.as_list(event) time = ru.as_list(time ) @@ -519,6 +520,30 @@ def _apply_filter(self, etype=None, uid=None, state=None, if not keep: continue + if names: + try: + re_pattern = re.Pattern + except AttributeError: + re_pattern = None + self._log.warn('re.Pattern is not supported within this ' + 'python version') + + keep = False + for name in names: + if re_pattern and isinstance(name, re_pattern): + # name is actually a regex we use for matching + if name.match(entity.name): + keep = True + break + else: + # name is a specific string to look out for + if entity.name == name: + keep = True + break + + if not keep: + continue + if state: match = False for s,stuple in list(entity.states.items()): @@ -588,20 +613,21 @@ def list(self, pname=None): # -------------------------------------------------------------------------- # - def get(self, etype=None, uid=None, state=None, event=None, time=None): + def get(self, etype=None, uid=None, name=None, + state=None, event=None, time=None): - uids = self._apply_filter(etype=etype, uid=uid, state=state, - event=event, time=time) + uids = self._apply_filter(etype=etype, uid=uid, name=name, + state=state, event=event, time=time) return [self._entities[_uid] for _uid in uids] # -------------------------------------------------------------------------- # - def filter(self, etype=None, uid=None, state=None, event=None, time=None, - inplace=True): + def filter(self, etype=None, uid=None, name=None, + state=None, event=None, time=None, inplace=True): - uids = self._apply_filter(etype=etype, uid=uid, state=state, - event=event, time=time) + uids = self._apply_filter(etype=etype, uid=uid, name=name, + state=state, event=event, time=time) if inplace: # filter our own entity list, and refresh the entity based on diff --git a/src/radical/analytics/utils/plot.py b/src/radical/analytics/utils/plot.py index f96e505..a9c9128 100644 --- a/src/radical/analytics/utils/plot.py +++ b/src/radical/analytics/utils/plot.py @@ -6,6 +6,7 @@ import pandas as pd import numpy as np import matplotlib as mpl + import radical.utils as ru