UCP Trace Instructions
UCP Trace provides the ability to in-depth analysis of the scheduling logic of UCP applications by embedding trace recording on the critical path executed by UCP. When performance anomalies occur, it can quickly locate the time point of the anomaly by analyzing UCP trace.
UCP trace provides two trace backend options: Perfetto Trace and Chrome Trace.
You can choose between them by setting an environment variable to meet your sepecific performance tracking needs.
Perfetto tracecan retrieve ucp recorded traces, as well as system status, ftrace information, etc.Chrome tracecan only retrieve ucp recoreded traces and is mainly used to analyze UCP's scheduling logic.
The UCP trace tool and configuration files are located in the samples/ucp_tutorial/tools directory path, with a directory structures as follows:
Environmental Variable
Perfetto Trace has a higher priority and if export HB_UCP_ENABLE_PERFETTO=true while export UCP_TRACE_LOG_LEVEL=0 is also set,
then only perfetto trace will be started and the ucp trace log will be ignored.
UCP Trace Records
UCP add trace records in the application API and internal critical scheduling paths, including task trace records and operator records.
Task Trace Records
Operator Trace Records
Perfetto Trace
Overview
Perfetto is a system analysis tool developed and open-sourced by Google, which can collect performance data from different data sources and provides the Perfetto UI for data visualization and analysis.
For more details on Perfetto, please refer to the Perfetto offical document.
Configuration File
UCP Trace Configuration File
You can configure UCP to use the Perfetto by specifying it through the environment variable HB_UCP_PERFETTO_CONFIG_PATH.
Parameters Description
The UCP trace configuration file is not necessary when your application has already initiaized Perfetto, you only need to export HB_UCP_ENABLE_PERFETTO=true to enable Perfetto.
Example 1: in_process mode
Sample 2: system mode
When selecting the system for backend, there is no need to specify trace_config separately for UCP.
Perfetto Configuration File
For detailed information about perfetto configuration files, please refer to Perfetto TraceConfig Reference.
UCP provides reference configuration files ucp_in_process.cfg and ucp_system.cfg, which can be modified based on application scenario.
Example: ucp_in_process.cfg
Example
in_process mode
In the in_process mode, only trace within UCP process can be captured, and it is not necessary to start the background process of perfetto.
Operating Procedure
- Configure environment variables.
In the ucp_in_process.json, the configuration file for perfetto is specified as ucp_in_process.cfg, and the output_path specifies the path for output trace file.
Due to the fact that Perfetto does not support directly overwriting existing trace files, if the file already exists, it needs to be deleted first.
- Running the UCP application, using
hrt_model_execas an example.
Due to the specified file path is a relative path, the trace configuration file and scripts need to be placed in the same level directory as the running program. Also, you need to make sure that you configure the environment variables and run the program in the same shell environment.
- The generated trace is saved in the output file
ucp.pftracespecified by theperfettocommand, and you can use Perfetto UI to open it.
- Clicking on the task in the timeline will show the complete scheduling process from creation to release of the task.
- The common operations of
Perfetto UIare as follows, for more detailed operation Instructions, please refer to thehelpinterface.
system mode
In system mode, UCP trace is just one of the data sources, so it it necessary to run the corresponding commands for tracebox to complete the capture of trace.
Operating Procedure
- Running the perfetto background process.
- Trigger data capture.
- Open a new terminal and configure the UCP environment variables.
- Running the UCP application, using
hrt_model_execas an example.
To be able to capture complete data, it is necessary to ensure that the perfetto process does not exit before the hrt_model_exec execution is complete.
- The generated trace is saved in
ucp.pftrace, and you can use Perfetto UI to open it.
BPU Trace
In system mode, BPU trace capture is supported. Simply add BPU trace data source to the perfetto configuration file. The ucp_bpu_trace.cfg file has already defaultly included the BPU trace data source.
The specific configuration items are shown below.
The bpu_trace_period_ms is used to set the period for reading the BPU trace. You can adjust this parameter according to your actual usage scenario. When the BPU load is high,
you can appropriately shorted the reading period to avoid the problem of trace data being overwritten due to mismatched read and write speeds.
To demonstrate the BPU trace during the inference process of multiple models, an example of a multi-process application is provided here. Except for the different running programs being launched, the rest of the steps are the same as in the previous section.
Visualization of BPU trace requires the use of the hbperfetto tool, which is custom-developed by Horizon Robotics. You can obtain this tool by contacting the Horizon Robotics system software technical support personnel.
The effect of opening a trace file using hbperfetto is shown in the image below.
The scheduling of different model inference tasks presented in BPU trace is shown in the following figure.
hbperfetto supports the association of UCP trace and BPU trace. The following diagram illustrates the complete process from the creating, submission,
scheduling and execution, to the task's completion and eventual releases.
Additionally, you can query the raw data of BPU trace based on SQL.
Long Trace Configuration
By default, Perfetto stores trace data in an in-memory buffer until the trace session ends, at which point the data in the buffer is dumped to a file. If the trace data exceeds the buffer capacity, there is no guarantee of data integrity.
Perfetto supports periodically writing buffer data to a file, which can be achieved by adding the following fields to the trace configuration file.
Introduction to Common Data Sources
Chrome Trace
Chrome trace only supports capturing UCP trace, and does not support capturing data sources. For capturing multiple data sources, please use Perfetto trace. The characteristic of Chrome trace is simplicity and ease of use, using text logs to record traces without depending on any extra thrid-party libraries or tools. If you are only interested in the scheduling logic of UCP, you can use Chrome trace to capture it.
Example
- Configure environment variables.
Before starting new capture, it is recommended to delete the old log files to avoid interference from old data.
- Running the UCP application, using
hrt_model_execas an example.
- Execute trace capture script.
After capturing the trace logs, run the catch_trace.sh provided in the UCP distribution package to convert the raw trace logs into a json-formatted trace file.
- Open
ucp_trace_task.jsonanducp_trace_thread.jsonusing Perfetto UI or Chrome UI(chrome://tracing/).
Open ucp_trace_task.json by Chrome UI:
Open ucp_trace_thread.json by Perfetto UI:

