Update doc and fix lint errors

This commit is contained in:
Christophe Bedard 2019-08-02 13:59:29 +02:00
parent 2002190ade
commit 5f1d7cf90f
2 changed files with 27 additions and 14 deletions

View file

@ -21,7 +21,6 @@ import time
from tracetools_analysis.loading import load_pickle from tracetools_analysis.loading import load_pickle
from tracetools_analysis.processor.cpu_time import CpuTimeHandler from tracetools_analysis.processor.cpu_time import CpuTimeHandler
from tracetools_analysis.processor.profile import ProfileHandler from tracetools_analysis.processor.profile import ProfileHandler
from tracetools_analysis.processor.ros2 import Ros2Handler
from tracetools_analysis.utils import ProfileDataModelUtil from tracetools_analysis.utils import ProfileDataModelUtil

View file

@ -15,15 +15,14 @@
"""Base processor module.""" """Base processor module."""
from collections import defaultdict from collections import defaultdict
from typing import Any
from typing import Callable from typing import Callable
from typing import Dict from typing import Dict
from typing import List from typing import List
from typing import Type from typing import Type
from tracetools_read.utils import DictEvent
from tracetools_read.utils import get_event_name from tracetools_read.utils import get_event_name
from tracetools_read.utils import get_field from tracetools_read.utils import get_field
from tracetools_read.utils import DictEvent
class EventMetadata(): class EventMetadata():
@ -98,18 +97,23 @@ class EventHandler():
@property @property
def handler_map(self) -> HandlerMap: def handler_map(self) -> HandlerMap:
"""Get the handler functions map."""
return self._handler_map return self._handler_map
@property @property
def dependencies(self) -> List[Type['EventHandler']]: def dependencies(self) -> List[Type['EventHandler']]:
# Default: no dependencies """
# Subclasses should override this method id they want to declare dependencies Get the `EventHandler`s that should also exist along with this current one.
Subclasses should override this method id they want to declare dependencies
Default: no dependencies.
"""
return [] return []
@classmethod @classmethod
def process(cls, events: List[DictEvent]) -> 'EventHandler': def process(cls, events: List[DictEvent]) -> 'EventHandler':
""" """
Util method that creates a `Processor` calls `process()` with an instance of the class. Create a `Processor` and process an instance of the class.
:param events: the list of events :param events: the list of events
:return: the processor object after processing :return: the processor object after processing
@ -128,22 +132,31 @@ class Processor():
""" """
Constructor. Constructor.
:param :param handlers: the `EventHandler`s to use for processing
""" """
print('num handlers before:', len(handlers)) self._handlers = list(handlers)
self._add_dependant_handlers(handlers) print('handlers before:', [type(handler).__name__ for handler in self._handlers])
self._handlers = handlers self._add_dependant_handlers(self._handlers)
print('num handlers after:', len(handlers)) print('handlers after:', [type(handler).__name__ for handler in self._handlers])
self._register(self._handlers)
def _add_dependant_handlers(self, handlers: List[EventHandler]) -> None: def _add_dependant_handlers(self, handlers: List[EventHandler]) -> None:
"""Checks handlers and add dependant handlers if not included. Ordered.""" """
Check handlers and add dependant handlers if not included. Ordered.
:param handlers: the list of primary `EventHandler`s
"""
# TODO # TODO
# For each handler object, check if its dependants are included # For each handler object, check if its dependencies are included
# If not, add them _before_ # If not, add them _before_
pass pass
def _get_handler_maps(self) -> HandlerMultimap: def _get_handler_maps(self) -> HandlerMultimap:
"""Collects and merges `HandlerMap`s from all events handlers into a `HandlerMultimap`.""" """
Collect and merge `HandlerMap`s from all events handlers into a `HandlerMultimap`.
:return: the merged multimap
"""
handler_multimap = defaultdict(list) handler_multimap = defaultdict(list)
for handler in self._handlers: for handler in self._handlers:
handler_map = handler.handler_map handler_map = handler.handler_map
@ -164,6 +177,7 @@ class Processor():
self._process_event(event) self._process_event(event)
def _process_event(self, event: DictEvent) -> None: def _process_event(self, event: DictEvent) -> None:
"""Process a single event."""
event_name = get_event_name(event) event_name = get_event_name(event)
print(f"event name: {event_name}") print(f"event name: {event_name}")
handler_functions = self._handler_multimap.get(event_name, None) handler_functions = self._handler_multimap.get(event_name, None)