Merge branch 'extract-print-model-method' into 'master'
Extract print_model() methods to DataModel.print_data() See merge request micro-ROS/ros_tracing/tracetools_analysis!30
This commit is contained in:
commit
8231cabf33
7 changed files with 58 additions and 29 deletions
|
@ -69,7 +69,7 @@
|
|||
"# Process\n",
|
||||
"events = load_file(converted_file_path)\n",
|
||||
"handler = Ros2Handler.process(events)\n",
|
||||
"#handler.data.print_model()"
|
||||
"#handler.data.print_data()"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
@ -25,3 +25,7 @@ class DataModel():
|
|||
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
|
||||
def print_data(self) -> None:
|
||||
"""Print the data model."""
|
||||
return None
|
||||
|
|
|
@ -51,9 +51,9 @@ class CpuTimeDataModel(DataModel):
|
|||
}
|
||||
self.times = self.times.append(data, ignore_index=True)
|
||||
|
||||
def print_model(self) -> None:
|
||||
"""Debug method to print every contained df."""
|
||||
def print_data(self) -> None:
|
||||
print('====================CPU TIME DATA MODEL====================')
|
||||
tail = 20
|
||||
print(f'Times (tail={tail}):\n{self.times.tail(tail).to_string()}')
|
||||
print(f'Times (tail={tail}):')
|
||||
print(self.times.tail(tail).to_string())
|
||||
print('===========================================================')
|
||||
|
|
|
@ -61,9 +61,9 @@ class ProfileDataModel(DataModel):
|
|||
}
|
||||
self.times = self.times.append(data, ignore_index=True)
|
||||
|
||||
def print_model(self) -> None:
|
||||
"""Debug method to print every contained df."""
|
||||
def print_data(self) -> None:
|
||||
print('====================PROFILE DATA MODEL====================')
|
||||
tail = 20
|
||||
print(f'Times (tail={tail}):\n{self.times.tail(tail).to_string()}')
|
||||
print(f'Times (tail={tail}):')
|
||||
print(self.times.tail(tail).to_string())
|
||||
print('==========================================================')
|
||||
|
|
|
@ -154,28 +154,38 @@ class Ros2DataModel(DataModel):
|
|||
}
|
||||
self.callback_instances = self.callback_instances.append(data, ignore_index=True)
|
||||
|
||||
def print_model(self) -> None:
|
||||
"""Debug method to print every contained df."""
|
||||
print('====================ROS DATA MODEL====================')
|
||||
print(f'Contexts:\n{self.contexts.to_string()}')
|
||||
def print_data(self) -> None:
|
||||
print('====================ROS 2 DATA MODEL===================')
|
||||
print('Contexts:')
|
||||
print(self.contexts.to_string())
|
||||
print()
|
||||
print(f'Nodes:\n{self.nodes.to_string()}')
|
||||
print('Nodes:')
|
||||
print(self.nodes.to_string())
|
||||
print()
|
||||
print(f'Publishers:\n{self.publishers.to_string()}')
|
||||
print('Publishers:')
|
||||
print(self.publishers.to_string())
|
||||
print()
|
||||
print(f'Subscriptions:\n{self.subscriptions.to_string()}')
|
||||
print('Subscriptions:')
|
||||
print(self.subscriptions.to_string())
|
||||
print()
|
||||
print(f'Subscription objects:\n{self.subscription_objects.to_string()}')
|
||||
print('Subscription objects:')
|
||||
print(self.subscription_objects.to_string())
|
||||
print()
|
||||
print(f'Services:\n{self.services.to_string()}')
|
||||
print('Services:')
|
||||
print(self.services.to_string())
|
||||
print()
|
||||
print(f'Clients:\n{self.clients.to_string()}')
|
||||
print('Clients:')
|
||||
print(self.clients.to_string())
|
||||
print()
|
||||
print(f'Timers:\n{self.timers.to_string()}')
|
||||
print('Timers:')
|
||||
print(self.timers.to_string())
|
||||
print()
|
||||
print(f'Callback objects:\n{self.callback_objects.to_string()}')
|
||||
print('Callback objects:')
|
||||
print(self.callback_objects.to_string())
|
||||
print()
|
||||
print(f'Callback symbols:\n{self.callback_symbols.to_string()}')
|
||||
print('Callback symbols:')
|
||||
print(self.callback_symbols.to_string())
|
||||
print()
|
||||
print(f'Callback instances:\n{self.callback_instances.to_string()}')
|
||||
print('Callback instances:')
|
||||
print(self.callback_instances.to_string())
|
||||
print('==================================================')
|
||||
|
|
|
@ -25,6 +25,7 @@ from typing import Tuple
|
|||
from tracetools_analysis.convert import convert
|
||||
from tracetools_analysis.convert import DEFAULT_CONVERT_FILE_NAME
|
||||
from tracetools_analysis.loading import load_file
|
||||
from tracetools_analysis.processor import Processor
|
||||
from tracetools_analysis.processor.ros2 import Ros2Handler
|
||||
from tracetools_read.trace import is_trace_directory
|
||||
|
||||
|
@ -134,10 +135,11 @@ def process(
|
|||
start_time = time.time()
|
||||
|
||||
events = load_file(converted_file_path)
|
||||
ros2_handler = Ros2Handler.process(events)
|
||||
processor = Processor(Ros2Handler())
|
||||
processor.process(events)
|
||||
|
||||
time_diff = time.time() - start_time
|
||||
ros2_handler.data.print_model()
|
||||
processor.print_data()
|
||||
print(f'processed {len(events)} events in {time_diff_to_str(time_diff)}')
|
||||
|
||||
|
||||
|
|
|
@ -243,7 +243,7 @@ class DependencySolver():
|
|||
|
||||
|
||||
class Processor():
|
||||
"""Base processor class."""
|
||||
"""Processor class, which dispatches events to event handlers."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
@ -256,12 +256,14 @@ class Processor():
|
|||
:param handlers: the `EventHandler`s to use for processing
|
||||
:param kwargs: the parameters to pass on to new handlers
|
||||
"""
|
||||
self._initial_handlers = list(handlers)
|
||||
expanded_handlers = self._expand_dependencies(*handlers, **kwargs)
|
||||
self._handler_multimap = self._get_handler_maps(expanded_handlers)
|
||||
self._register_with_handlers(expanded_handlers)
|
||||
self._progress_display = ProcessingProgressDisplay(
|
||||
[type(handler).__name__ for handler in expanded_handlers],
|
||||
)
|
||||
self._processing_done = False
|
||||
|
||||
@staticmethod
|
||||
def _expand_dependencies(
|
||||
|
@ -304,16 +306,21 @@ class Processor():
|
|||
for handler in handlers:
|
||||
handler.register_processor(self)
|
||||
|
||||
def process(self, events: List[DictEvent]) -> None:
|
||||
def process(
|
||||
self,
|
||||
events: List[DictEvent],
|
||||
) -> None:
|
||||
"""
|
||||
Process all events.
|
||||
|
||||
:param events: the events to process
|
||||
"""
|
||||
if not self._processing_done:
|
||||
self._progress_display.set_work_total(len(events))
|
||||
for event in events:
|
||||
self._process_event(event)
|
||||
self._progress_display.did_work()
|
||||
self._processing_done = True
|
||||
|
||||
def _process_event(self, event: DictEvent) -> None:
|
||||
"""Process a single event."""
|
||||
|
@ -346,6 +353,12 @@ class Processor():
|
|||
metadata = EventMetadata(event_name, timestamp, cpu_id, procname, pid, tid)
|
||||
handler_function(event, metadata)
|
||||
|
||||
def print_data(self) -> None:
|
||||
"""Print processed data."""
|
||||
if self._processing_done:
|
||||
for handler in self._initial_handlers:
|
||||
handler.data.print_data()
|
||||
|
||||
|
||||
class ProcessingProgressDisplay():
|
||||
"""Display processing progress periodically on stdout."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue