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