Make UST-related context fields optional

This commit is contained in:
Christophe Bedard 2019-07-30 11:19:42 +02:00
parent 6a6e2c6eed
commit 5e5bbe1564

View file

@ -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