harmony 鸿蒙Viewing HiTraceMeter Logs
Viewing HiTraceMeter Logs
Viewing Logs on DevEco Studio
In CPU Insight of DevEco Studio Profiler, you can display HiTraceMeter logs for analyzing the CPU usage and thread running status of applications and services and viewing the CPU consumption in a specified period. For details, see CPU Activity Analysis: CPU.
Viewing Logs Using a Command Line Tool
Set up the environment for OpenHarmony Device Connector (hdc). For details, see Environment Setup.
In the Terminal window of DevEco Studio or the CLI on the host, run the hdc shell command to connect to the device, and run the HiTrace command on the device to enable the HiTraceMeter logging service.
PS D:\xxx\xxx> hdc shell
$ hitrace --trace_begin app
Run the program that enables the HiTraceMeter logging on the device.
Dump the HiTraceMeter log file that contains the HiTraceMeter logging information in step 3.
- Logs are printed in the window by default.
$ hitrace --trace_dump
- You can create a file to save logs in the /data/local/tmp/ directory (other directories are unavailable).
$ hitrace --trace_dump -o /data/local/tmp/trace.ftrace
- Run the HiTrace command on the device to stop the HiTraceMeter logging service.
$ hitrace --trace_finish
- Exit the device, enter the host, and export the HiTraceMeter text file to the current directory.
$ exit
PS D:\xxx\xxx> hdc file recv /data/local/tmp/trace.ftrace ./
Search for keywords such as the logging name in the HiTraceMeter text file to check whether the logging is successful.
Display and analyze the HiTraceMeter text file.
- Import the file to DevEco Studio. In DevEco Studio Profiler, select Open File to import the HiTraceMeter log file. For details, see CPU Activity Analysis: CPU.
- Use HiSmartPerf for analysis. You can download the tool from developtools_smartperf_host Release.
User-mode Trace Format
You can run the HiTrace command to collect user-mode trace logs generated by the HiTraceMeter API to analyze application performance. The following describes the format and extension rule for user-mode traces of the synchronous, asynchronous, and integer value types, including the field composition, description, and relationship between fields and input parameters, as well as Sample Trace Logs in Different Scenarios for reference.
For details about the user-mode trace format since API version 19, see User-mode Trace Format Since API Version 19. For details about the user-mode trace format in versions earlier than API version 19, see User-mode Trace Format Before API Version 19.
User-mode Trace Format Since API Version 19
Synchronous Trace
Start trace: [Type identifier]|[Process ID]|H:[ID of the distributed call chain tracing task]#[Content]|[Level and tag set]|[Custom key-value pair]
End trace: [Type identifier]|[Process ID]|[Level and tag set]
A synchronous trace consists of a start trace (Type identifier: B) and an end trace (Type identifier: E).
Asynchronous Trace
Start trace: [Type identifier]|[Process ID]|H:[ID of the distributed call chain tracing task]#[Content]|[Asynchronous task ID]|[Level and tag set]|[Custom category name]|[Custom key-value pair]
End trace: [Type identifier]|[Process ID]|H:[ID of the distributed call chain tracing task]#[Content]|[Asynchronous task ID]|[Level and tag set]
An asynchronous trace consists of a start trace (Type identifier: S) and an end trace (Type identifier: F).
Integer Value Trace
- Trace format: [Type identifier]|[Process ID]|H:[ID of the distributed call chain tracing task]#[Content]|[Integer value]|[Level and tag set]
An integer value trace contains only one independent trace whose type identifier is C.
NOTE
- A valid and complete synchronous trace or asynchronous trace contains a start trace and an end trace. You need to ensure that the API calls match. Otherwise, the performance trace may be abnormal. For details, see the ArkTS APIs @ohos.hiTraceMeter (Performance Tracing) or C++ APIs HiTrace.
- The maximum length of a user-mode trace is 512 characters. Excess characters will be truncated.
Fields
This following describes fields of the user-mode trace, including the field composition, description, and relationship between fields and logging input parameters. For details, see @ohos.hiTraceMeter (Performance Tracing).
Type Identifier
The type identifier is associated with the called @ohos.hiTraceMeter (Performance Tracing) API. The mappings are as follows:
- B: Identifies the start of a synchronous time slice trace.
- E: Identifies the end of a synchronous time slice trace.
- S: Identifies the start of an asynchronous time slice trace.
- F: Identifies the end of an asynchronous time slice trace.
- C: Identifies the integer trace event.
ID of the Distributed Call Chain Tracing Task
When HiTraceChain (Distributed Tracing) is enabled, the HiTraceId information is recorded in the trace logs in the format of [ChainId,SpanId,ParentSpanId]. The HiTraceId information is separated from the content field by the hash (#) separator.
When HiTraceChain (Distributed Tracing) is not enabled, this field is not included in the trace logs.
- ChainId: Chain ID of HiTraceId.
- SpanId: Span ID of HiTraceId.
- ParentSpanId: Parent span ID of HiTraceId.
For details about how to use HiTraceChain, see Using HiTraceChain (ArkTS/JS) and Using HiTraceChain (C/C++).
- Content
This field indicates the name of a trace task or an integer variable. It corresponds to the name parameter of the @ohos.hiTraceMeter (Performance Tracing) API.
- Asynchronous Task ID
This field and the content field are used to match the start and end of the same asynchronous trace. This field corresponds to the taskId parameter in the @ohos.hiTraceMeter (Performance Tracing) API.
- Integer Value
This field is the value of the integer variable to trace and is contained only in the integer value trace task. This field corresponds to count parameter in the @ohos.hiTraceMeter (Performance Tracing) API.
- Level and Tag Set
This field consists of the level and tag.
The level is passed through the logging API, whose value can be D, I, C, or M. It corresponds to the level parameter in the @ohos.hiTraceMeter (Performance Tracing) API. For details about the description and mappings, seeHiTrace Output Levels.
The tag set indicates the tags of the trace, each of which is represented by a two-digit number. The tag set can contain multiple two-digit numbers in ascending order.
For example, in B|1314|H:TestFunction|I3062, I indicates that the logging level is Info, and 3062 indicates the tag set of the logging trace. According to the mappings between tag names and values, 30 corresponds to the ohos tag, and 62 corresponds to the app tag. For details, see HiTraceMeter Tags.
NOTE
Since API version 19, the output level can be customized. In versions earlier than API version 19, the output level is COMMERCIAL by default.
In the system, a user-mode trace may have multiple tags. However, the tag set cannot be specified in the application-side user-mode trace APIs provided by @ohos.hiTraceMeter (Performance Tracing) and HiTrace, whose tag is app and tag value is 62.
- Custom Category Name
This field can be used for custom trace collection. It corresponds to the customCategory parameter in the @ohos.hiTraceMeter (Performance Tracing) API. The value of this field may be empty, which changes the log format. For details, see Empty Field Scenarios.
In the trace analysis tool, asynchronous traces with the same category name in the same process are displayed in the same lane.
- Custom Key-Value Pair
This field is in the format of key=value. Multiple key-value pairs are separated by commas (,), for example, key1=value1,key2=value2. It corresponds to the customArgs parameter of the @ohos.hiTraceMeter (Performance Tracing) API. The value of this field may be empty, which changes the log format. For details, see Empty Field Scenarios.
In the trace analysis tool, the parsing results of custom key-value pairs that meet the format requirements are displayed in key-value pairs.
Field Extension Rule
Since API version 19, new fields are added to the end of the current user-mode trace format in the format of |field.
Sample Trace Logs in Different Scenarios
Trace Type | Format When HiTraceChain is Enabled | Format When HiTraceChain is Disabled |
---|---|---|
Start of a synchronous trace | B|1234|H:[a92ab94c18e1341,0,0]#tracename|M62|user=root,type=2 | B|1234|H:tracename|M62|user=root,type=2 |
End of a synchronous trace | E|1234|M62 | E|1234|M62 |
Start of an asynchronous trace | S|1234|H:[a92ab94c18e1341,0,0]#tracename|428|M62|appcategory01|user=root,type=2 | S|1234|H:tracename|428|M62|appcategory01|user=root,type=2 |
End of an asynchronous trace | F|1234|H:[a92ab94c18e1341,0,0]#tracename|428|M62 | F|1234|H:tracename|428|M62 |
Trace of an integer | C|1234|H:[a92ab94c18e1341,0,0]#tracename|5678|M62 | C|1234|H:tracename|5678|M62 |
In the preceding samples, the process ID is 1234, the content is tracename, the level is M, indicating the COMMERCIAL level, the tag set is 62, corresponding to the app tag. When HiTraceChain is enabled, the ID of the distributed call chain tracing task is [a92ab94c18e1341,0,0]. The custom key-value pairs of synchronous and asynchronous traces are both user=root,type=2. The asynchronous task ID is 428, and the custom category name is appcategory01. The value of the integer variable to trace is 5678.
NOTE
The maximum length of a user-mode trace is 512 characters. Excess characters will be truncated. Therefore, it is recommended that the total length of the tracename, customCategory, and customArgs fields be less than or equal to 420 characters.
Empty Field Scenarios
In the user-mode trace, if the middle field is empty, the vertical bar (|) is retained. If the last field is empty, the vertical bar (|) is removed. The following shows examples when the customCategory and customArgs parameters of the hiTraceMeter.startAsyncTrace19+ and hiTraceMeter.startSyncTrace19+ APIs are empty.
Start of a synchronous trace
- The value of customArgs is not empty:
B|[Process ID]|H:[ID of the distributed call chain tracing task]#[Content]|[Level and tag set]|[Custom key-value pair]
- The value of customArgs is empty:
B|[Process ID]|H:[ID of the distributed call chain tracing task]#[Content]|[Level and tag set]
Start of an asynchronous trace
- The values of customCategory and customArgs are not empty:
S|[Process ID]|H:[ID of the distributed call chain tracing task]#[Content]|[Asynchronous task ID]|[Level and tag set]|[Custom category name]|[Custom key-value pair]
- The value of customCategory is empty while the value of customArgs is not empty:
S|[Process ID]|H:[ID of the distributed call chain tracing task]#[Content]|[Asynchronous task ID]|[Level and tag set]||[Custom key-value pair]
- The value of customCategory is not empty while the value of customArgs is empty:
S|[Process ID]|H:[ID of the distributed call chain tracing task]#[Content]|[Asynchronous task ID]|[Level and tag set]|[Custom category name]
- The values of customCategory and customArgs are empty:
S|[Process ID]|H:[ID of the distributed call chain tracing task]#[Content]|[Asynchronous task ID]|[Level and tag set]
HiTraceMeter Tags
The following is the user-mode tag collection of HiTraceMeter. The tag values are the left shift values based on the digit 1 at the actual code layer. You can run the hitrace -l command to obtain the description of the user-mode tag. always is the default tag and commercial is the custom tag for the commercial version.
Name | Constant Value at the Code Layer | Value |
---|---|---|
always | 1ULL << 0 | 00 |
commercial | 1ULL << 5 | 05 |
drm | 1ULL << 6 | 06 |
security | 1ULL << 7 | 07 |
animation | 1ULL << 9 | 09 |
push | 1ULL << 10 | 10 |
virse | 1ULL << 11 | 11 |
ffrt | 1ULL << 13 | 13 |
musl | 1ULL << 12 | 12 |
cloud | 1ULL << 14 | 14 |
deviceauth | 1ULL << 15 | 15 |
commonlibrary | 1ULL << 16 | 16 |
hdcd | 1ULL << 17 | 17 |
hdf | 1ULL << 18 | 18 |
usb | 1ULL << 19 | 19 |
interconn | 1ULL << 20 | 20 |
dlpcre | 1ULL << 21 | 21 |
accesscontrol | 1ULL << 22 | 22 |
net | 1ULL << 23 | 23 |
nweb | 1ULL << 24 | 24 |
huks | 1ULL << 25 | 25 |
useriam | 1ULL << 26 | 26 |
daudio | 1ULL << 27 | 27 |
dlsm | 1ULL << 28 | 28 |
filemanagement | 1ULL << 29 | 29 |
ohos | 1ULL << 30 | 30 |
ability | 1ULL << 31 | 31 |
zcamera | 1ULL << 32 | 32 |
zmedia | 1ULL << 33 | 33 |
zimage | 1ULL << 34 | 34 |
zaudio | 1ULL << 35 | 35 |
distributeddatamgr | 1ULL << 36 | 36 |
mdfs | 1ULL << 37 | 37 |
graphic | 1ULL << 38 | 38 |
ace | 1ULL << 39 | 39 |
notification | 1ULL << 40 | 40 |
misc | 1ULL << 41 | 41 |
multimodalinput | 1ULL << 42 | 42 |
sensors | 1ULL << 43 | 43 |
msdp | 1ULL << 44 | 44 |
dsoftbus | 1ULL << 45 | 45 |
rpc | 1ULL << 46 | 46 |
ark | 1ULL << 47 | 47 |
window | 1ULL << 48 | 48 |
account | 1ULL << 49 | 49 |
dscreen | 1ULL << 50 | 50 |
dcamera | 1ULL << 51 | 51 |
dhfwk | 1ULL << 52 | 52 |
gresource | 1ULL << 53 | 53 |
devicemanager | 1ULL << 54 | 54 |
samgr | 1ULL << 55 | 55 |
power | 1ULL << 56 | 56 |
dsched | 1ULL << 57 | 57 |
deviceprofile | 1ULL << 58 | 58 |
dinput | 1ULL << 59 | 59 |
bluetooth | 1ULL << 60 | 60 |
accessibility | 1ULL << 61 | 61 |
app | 1ULL << 62 | 62 |
HiTrace Output Levels
Enum Name (C/C++) | Enum Name (ArkTS/JS) | Value | Trace Level |
---|---|---|---|
HITRACE_LEVEL_DEBUG | DEBUG | 0 | D |
HITRACE_LEVEL_INFO | INFO | 1 | I |
HITRACE_LEVEL_CRITICAL | CRITICAL | 2 | C |
HITRACE_LEVEL_COMMERCIAL | COMMERCIAL | 3 | M |
User-mode Trace Format Before API version 19
Synchronous Trace
Start format: [Type identifier]|[Process ID]|H:[ID of the distributed call chain tracing task]#[Content]
End format: [Type identifier]|[Process ID]
Asynchronous Trace
Start format: [Type identifier]|[Process ID]|H:[ID of the distributed call chain tracing task]#[Content] [Asynchronous task ID]
End format: [Type identifier]|[Process ID]|H:[ID of the distributed call chain tracing task]#[Content] [Asynchronous task ID]
Integer Value Trace
- Trace format: [Type identifier]|[Process ID]|H:[ID of the distributed call chain tracing task]#[Content] [Integer value]
NOTE
The start and end formats of an asynchronous trace are the same. In versions earlier than API version 19, the Asynchronous task ID and Integer value fields are separated from the Content field by spaces.
Sample Trace Logs in Different Scenarios Before API Version 19
Trace Type | Format When HiTraceChain is Enabled | Format When HiTraceChain is Disabled |
---|---|---|
Start of a synchronous trace | B|1234|H:[a92ab94c18e1341,0,0]#tracename | B|1234|H:tracename |
End of a synchronous trace | E|1234| | E|1234| |
Start of an asynchronous trace | S|1234|H:[a92ab94c18e1341,0,0]#tracename 428 | S|1234|H:tracename 428 |
End of an asynchronous trace | F|1234|H:[a92ab94c18e1341,0,0]#tracename 428 | F|1234|H:tracename 428 |
Trace of an integer value | C|1234|H:[a92ab94c18e1341,0,0]#tracename 5678 | C|1234|H:tracename 5678 |
In the preceding samples, the process ID is 1234 and the content is tracename. When HiTraceChain is enabled, the ID of the distributed call chain tracing task is [a92ab94c18e1341,0,0]. The asynchronous task ID is 428, and the integer value to trace is 5678.
你可能感兴趣的鸿蒙文章
harmony 鸿蒙Performance Analysis Kit
harmony 鸿蒙Analyzing Application Freeze
harmony 鸿蒙Development of Application Recovery
harmony 鸿蒙Development of Error Manager
harmony 鸿蒙Introduction to HiAppEvent
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦