From 5e5bbe156444f8312abf772eef7250e601f458d1 Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Tue, 30 Jul 2019 11:19:42 +0200 Subject: [PATCH] Make UST-related context fields optional --- .../tracetools_analysis/processor/handler.py | 63 ++++++++++++------- 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/tracetools_analysis/tracetools_analysis/processor/handler.py b/tracetools_analysis/tracetools_analysis/processor/handler.py index b0944d9..04dca2c 100644 --- a/tracetools_analysis/tracetools_analysis/processor/handler.py +++ b/tracetools_analysis/tracetools_analysis/processor/handler.py @@ -25,18 +25,44 @@ from tracetools_read.utils import get_field class EventMetadata(): """Container for event metadata.""" - def __init__(self, event_name, pid, tid, timestamp, procname, cpu_id) -> None: + def __init__( + self, + event_name, + timestamp, + cpu_id, + procname = None, + pid = None, + tid = None, + ) -> None: + """ + Constructor. + + Parameters with a default value of `None` are not mandatory, + since they are not always present. + """ self._event_name = event_name + self._timestamp = timestamp + self._cpu_id = cpu_id + self._procname = procname self._pid = pid self._tid = tid - self._timestamp = timestamp - self._procname = procname - self._cpu_id = cpu_id @property def event_name(self): return self._event_name + @property + def timestamp(self): + return self._timestamp + + @property + def cpu_id(self): + return self._cpu_id + + @property + def procname(self): + return self._procname + @property def pid(self): return self._pid @@ -45,18 +71,6 @@ class EventMetadata(): def tid(self): return self._tid - @property - def timestamp(self): - return self._timestamp - - @property - def procname(self): - return self._procname - - @property - def cpu_id(self): - return self._cpu_id - class EventHandler(): """Base event handling class.""" @@ -83,24 +97,29 @@ class EventHandler(): event_name = get_event_name(event) handler_function = self._handler_map.get(event_name, None) if handler_function is not None: + timestamp = get_field(event, '_timestamp') + cpu_id = get_field(event, 'cpu_id') + # TODO perhaps validate fields depending on the type of event, + # i.e. all UST events should have procname, (v)pid and (v)tid + # context info, since analyses might not work otherwise + procname = get_field(event, 'procname', raise_if_not_found=False) pid = get_field( event, 'vpid', default=get_field( event, 'pid', - raise_if_not_found=False)) + raise_if_not_found=False), + raise_if_not_found=False) tid = get_field( event, 'vtid', default=get_field( event, 'tid', - raise_if_not_found=False)) - timestamp = get_field(event, '_timestamp') - procname = get_field(event, 'procname') - cpu_id = get_field(event, 'cpu_id') - metadata = EventMetadata(event_name, pid, tid, timestamp, procname, cpu_id) + raise_if_not_found=False), + raise_if_not_found=False) + metadata = EventMetadata(event_name, timestamp, cpu_id, procname, pid, tid) handler_function(event, metadata) @classmethod