2019-07-01 10:29:11 +02:00
# tracetools_analysis
2020-01-26 11:40:07 -05:00
[](https://gitlab.com/micro-ROS/ros_tracing/tracetools_analysis/commits/master)
2019-07-05 13:57:07 +02:00
Analysis tools for [ROS 2 tracing ](https://gitlab.com/micro-ROS/ros_tracing/ros2_tracing ).
2019-07-01 10:29:11 +02:00
2019-10-13 15:30:29 -07:00
## Trace analysis
2019-07-01 10:29:11 +02:00
2019-10-13 15:30:29 -07:00
After generating a trace (see [`ros2_tracing` ](https://gitlab.com/micro-ROS/ros_tracing/ros2_tracing#tracing )), we can analyze it to extract useful execution data.
2019-10-13 16:11:00 -07:00
### Commands
2019-10-13 15:30:29 -07:00
Since CTF traces (the output format of the [LTTng ](https://lttng.org/ ) tracer) are very slow to read, we first convert them into a single file which can be read much faster.
```
$ ros2 trace-analysis convert /path/to/trace/directory
```
Then we can process it to create a data model which could be queried for analysis.
```
$ ros2 trace-analysis process /path/to/trace/directory
```
2019-10-13 16:11:00 -07:00
### Jupyter
The last command will process and output the raw data models, but to actually display results, process and analyze using a Jupyter Notebook.
2019-07-01 10:29:11 +02:00
2020-05-23 09:18:36 -04:00
```shell
2019-07-01 10:29:11 +02:00
$ jupyter notebook
```
Then navigate to the [`analysis/` ](./tracetools_analysis/analysis/ ) directory, and select one of the provided notebooks, or create your own!
2019-10-13 15:30:12 -07:00
2019-10-13 16:11:00 -07:00
For example:
```python
2019-11-17 13:24:36 -08:00
from tracetools_analysis import loading
from tracetools_analysis import processor
2019-10-13 16:11:00 -07:00
from tracetools_analysis import utils
2019-12-31 21:44:14 -05:00
# Load trace directory or converted trace file
events = loading.load_file('/path/to/trace/or/converted/file')
2019-10-13 16:11:00 -07:00
# Process
2019-11-17 13:24:36 -08:00
ros2_handler = processor.Ros2Handler()
cpu_handler = processor.CpuTimeHandler()
2019-10-13 16:11:00 -07:00
2019-11-17 13:24:36 -08:00
processor.Processor(ros2_handler, cpu_handler).process(events)
2019-10-13 16:11:00 -07:00
# Use data model utils to extract information
2019-11-17 13:24:36 -08:00
ros2_util = utils.ros2.Ros2DataModelUtil(ros2_handler.data)
cpu_util = utils.cpu_time.CpuTimeDataModelUtil(cpu_handler.data)
2019-10-13 16:11:00 -07:00
callback_durations = ros2_util.get_callback_durations()
time_per_thread = cpu_util.get_time_per_thread()
# ...
# Display, e.g. with bokeh or matplotlib
# ...
```
2019-10-13 15:30:12 -07:00
## Design
2019-12-31 21:45:43 -05:00
See the [`ros2_tracing` design document ](https://gitlab.com/micro-ROS/ros_tracing/ros2_tracing/blob/master/doc/design_ros_2.md ), especially the [*Goals and requirements* ](https://gitlab.com/micro-ROS/ros_tracing/ros2_tracing/blob/master/doc/design_ros_2.md#goals-and-requirements ) and [*Analysis* ](https://gitlab.com/micro-ROS/ros_tracing/ros2_tracing/blob/master/doc/design_ros_2.md#analysis ) sections.