目录

Introduction to HiTraceMeter

This topic describes how to use the HiTraceMeter APIs. You can call the HiTraceMeter APIs in your code to log traces, and then use the hitrace command-line tool or the trace collection APIs provided by hidebug to obtain the trace data generated during program execution. The collected data includes information such as processes, threads, timestamps, and CPU usage, helping you analyze issues and optimize performance.

HiTraceMeter provides ArkTS and C/C++ APIs. You can select the APIs as required.

Implementation Principles

The kernel sets a buffer to record the logs generated during device running and provides the trace_marker and trace nodes in sysfs.

The trace_marker node is a write-only node. After the application writes the logs to the trace_marker node, the logs are stored in the kernel buffer. The HiTraceMeter APIs encapsulate the write operation. Applications can call these APIs to write trace data to the kernel node.

The trace node is a read-only node, from which you can read all records in the current system buffer. hitrace encapsulates the read operation on the node. You can use commands to display the collected trace data in the CLI or save it to the device file.

For details about the format of trace data generated by calling HiTraceMeter APIs, see User-Mode Trace Format.

HiTraceMeter Tag: category of trace data. Each tag uniquely identifies a software subsystem. You can run the hdc command hitrace -l to view all tag names and their descriptions. When using HiTrace to collect trace data, you need to specify a tag. The collection result contains only the trace data of the specified tag. To call HiTraceMeter in an application, use the app tag.