Allow EventHandlers to declare list of required events
This commit is contained in:
parent
694a0d852b
commit
e4d10e9e88
4 changed files with 46 additions and 1 deletions
|
@ -121,8 +121,9 @@ class EventHandler(Dependant):
|
|||
|
||||
:param handler_map: the mapping from event name to handling method
|
||||
"""
|
||||
assert handler_map is not None and len(handler_map) > 0, \
|
||||
assert handler_map is None or len(handler_map) > 0, \
|
||||
f'empty map: {self.__class__.__name__}'
|
||||
assert all(required_name in handler_map.keys() for required_name in self.required_events())
|
||||
self._handler_map = handler_map
|
||||
self.processor = None
|
||||
|
||||
|
@ -136,6 +137,16 @@ class EventHandler(Dependant):
|
|||
"""Get the data model."""
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def required_events() -> List[str]:
|
||||
"""
|
||||
Get the list of events required by this EventHandler.
|
||||
|
||||
Without these events, the EventHandler would be invalid/useless. Inheriting classes can
|
||||
decide not to declare that they require specific events.
|
||||
"""
|
||||
return []
|
||||
|
||||
def register_processor(self, processor: 'Processor') -> None:
|
||||
"""Register processor with this `EventHandler` so that it can query other handlers."""
|
||||
self.processor = processor
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
"""Module for CPU time events processing."""
|
||||
|
||||
from typing import Dict
|
||||
from typing import List
|
||||
|
||||
from tracetools_read import get_field
|
||||
|
||||
|
@ -51,6 +52,12 @@ class CpuTimeHandler(EventHandler):
|
|||
# cpu_id -> start timestamp of the running thread
|
||||
self._cpu_start: Dict[int, int] = {}
|
||||
|
||||
@staticmethod
|
||||
def required_events() -> List[str]:
|
||||
return [
|
||||
'sched_switch',
|
||||
]
|
||||
|
||||
@property
|
||||
def data(self) -> CpuTimeDataModel:
|
||||
return self._data_model
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
"""Module for memory usage events processing."""
|
||||
|
||||
from typing import Dict
|
||||
from typing import List
|
||||
|
||||
from tracetools_read import get_field
|
||||
|
||||
|
@ -96,6 +97,17 @@ class UserspaceMemoryUsageHandler(MemoryUsageHandler):
|
|||
# (used to know keep track of the memory size allocated at a given pointer)
|
||||
self._memory: Dict[int, int] = {}
|
||||
|
||||
@staticmethod
|
||||
def required_events() -> List[str]:
|
||||
return [
|
||||
'lttng_ust_libc:malloc',
|
||||
'lttng_ust_libc:calloc',
|
||||
'lttng_ust_libc:realloc',
|
||||
'lttng_ust_libc:free',
|
||||
'lttng_ust_libc:memalign',
|
||||
'lttng_ust_libc:posix_memalign',
|
||||
]
|
||||
|
||||
def _handle_malloc(
|
||||
self, event: Dict, metadata: EventMetadata
|
||||
) -> None:
|
||||
|
@ -200,6 +212,13 @@ class KernelMemoryUsageHandler(MemoryUsageHandler):
|
|||
**kwargs,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def required_events() -> List[str]:
|
||||
return [
|
||||
'kmem_mm_page_alloc',
|
||||
'kmem_mm_page_free',
|
||||
]
|
||||
|
||||
def _handle_malloc(
|
||||
self, event: Dict, metadata: EventMetadata
|
||||
) -> None:
|
||||
|
|
|
@ -86,6 +86,14 @@ class ProfileHandler(EventHandler):
|
|||
# ]
|
||||
self._current_funcs: Dict[int, List[List[Union[str, int]]]] = defaultdict(list)
|
||||
|
||||
@staticmethod
|
||||
def required_events() -> List[str]:
|
||||
return [
|
||||
'lttng_ust_cyg_profile_fast:func_entry',
|
||||
'lttng_ust_cyg_profile_fast:func_exit',
|
||||
'sched_switch',
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def addr_to_int(addr: Union[int, str]) -> int:
|
||||
"""Transform an address into an `int` if it's a hex `str`."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue