Skip to content

Commit

Permalink
lisa.analysis.notebook: Add NotebookAnalysis.df_all_events(error='rai…
Browse files Browse the repository at this point in the history
…se') parameter

FEATURE

Add an "error" parameter that allows logging the error instead of
raising an exception (default). This is useful when working with traces
containing events that cannot be successfully parsed.
  • Loading branch information
douglas-raillard-arm committed Feb 3, 2025
1 parent 401e787 commit 2f804b2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lisa/analysis/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def _make_fig_ui(self, fig, *, link_dataframes):
# dimension, such as residency bar graphs
if not link_dataframes and time_indexed:
link_dataframes = [
self.ana.notebook.df_all_events()
self.ana.notebook.df_all_events(error='log')
]

fig = _hv_link_dataframes(fig, dfs=link_dataframes)
Expand Down
58 changes: 40 additions & 18 deletions lisa/analysis/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def __getattr__(self, attr):
return x

@TraceAnalysisBase.df_method
def _df_all_events(self, events, field_sep=' ', fields_as_cols=None, event_as_col=True):
def _df_all_events(self, events, field_sep=' ', fields_as_cols=None, event_as_col=True, error='raise'):
"""
Split implementation to be able to use the cache
"""
Expand Down Expand Up @@ -143,23 +143,39 @@ def make_info_row(row, event):
)

def make_info_df(event):
df = trace.df_event(event)
df = pd.DataFrame(
{
'info': df.apply(make_info_row, axis=1, event=event),
**{
field: df[field]
for field in fields_as_cols
}
},
index=df.index,
)

if event_as_col:
df['event'] = event
return df

df = pd.concat(map(make_info_df, events) )
try:
df = trace.df_event(event)
except Exception as e:
if error == 'raise':
raise e
elif error == 'log':
self.logger.error(f'Error while loading event "{event}": {e}')
return None
elif error == 'ignore':
return None
else:
raise ValueError(f'Unknown error={error}')
else:
df = pd.DataFrame(
{
'info': df.apply(make_info_row, axis=1, event=event),
**{
field: df[field]
for field in fields_as_cols
}
},
index=df.index,
)

if event_as_col:
df['event'] = event
return df

df = pd.concat(
df
for event in events
if (df := make_info_df(event)) is not None
)
df.sort_index(inplace=True)
df_update_duplicates(df, inplace=True)

Expand Down Expand Up @@ -205,6 +221,12 @@ def df_all_events(self, events=None, **kwargs):
:param event_as_col: If ``True``, the event name is split in its own
column.
:type event_as_col: bool
:param error: Can be one of:
* ``raise``: any error while parsing an event will be raised.
* ``log``: the error will be logged at error level.
* ``ignore``: the error is simply ignored.
:type error: str
"""
if events is None:
events = sorted(self.trace.available_events)
Expand Down

0 comments on commit 2f804b2

Please sign in to comment.