Introduction to HiTraceMeter

This topic describes how to use the HitraceMeter APIs. You can call them to log traces, and then use the trace collection APIs provided by hitrace or hidebug to obtain the trace information generated during application running. In this way, you can learn about the application running process, thread, timestamp, and CPU information for performance profiling and optimization.

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 the format of logging information generated by calling the HitraceMeter API, 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.