1# Hitrace 2 3 4## Overview 5 6hiTraceMeter provides APIs for system performance tracing. 7 8You can call the APIs provided by hiTraceMeter in your own service logic to effectively track service processes and check the system performance. 9 10\@syscap SystemCapability.HiviewDFX.HiTrace 11 12**Since** 13 1410 15 16 17## Summary 18 19 20### File 21 22| Name| Description| 23| -------- | -------- | 24| [trace.h](trace_8h.md) | Defines APIs of the HiTraceMeter module for performance trace.<br>**File to include**: <hitrace/trace.h><br>**Library**: libhitrace_ndk.z.so| 25 26### Functions 27 28| Name| Description| 29| -------- | -------- | 30| [OH_HiTrace_StartTrace](#oh_hitrace_starttrace) (const char \*name) | Marks the start of a synchronous trace.| 31| [OH_HiTrace_FinishTrace](#oh_hitrace_finishtrace) (void) | Marks the end of a synchronous trace.| 32| [OH_HiTrace_StartAsyncTrace](#oh_hitrace_startasynctrace) (const char \*name, int32_t taskId) | Marks the start of an asynchronous trace.| 33| [OH_HiTrace_FinishAsyncTrace](#oh_hitrace_finishasynctrace) (const char \*name, int32_t taskId) | Marks the end of an asynchronous trace.| 34| [OH_HiTrace_CountTrace](#oh_hitrace_counttrace) (const char \*name, int64_t count) | Traces the value change of an integer variable based on its name.| 35 36 37## Function Description 38 39 40### OH_HiTrace_CountTrace() 41 42 43``` 44void OH_HiTrace_CountTrace (const char * name, int64_t count ) 45``` 46 47**Description** 48 49Traces the value change of an integer variable based on its name. 50 51This API can be executed for multiple times to trace the value change of a given integer variable at different time points. 52 53**Parameters** 54 55| Name| Description| 56| -------- | -------- | 57| name | Name of the integer variable. It does not need to be the same as the real variable name.| 58| count | Integer value. Generally, an integer variable can be specified.| 59 60**Since** 61 6210 63 64 65### OH_HiTrace_FinishAsyncTrace() 66 67 68``` 69void OH_HiTrace_FinishAsyncTrace (const char * name, int32_t taskId ) 70``` 71 72**Description** 73 74Marks the end of an asynchronous trace. 75 76This API is called in the callback function after an asynchronous trace is complete. It is used with **OH_HiTrace_StartAsyncTrace** in pairs. Its name and task ID must be the same as those of **OH_HiTrace_StartAsyncTrace**. 77 78**Parameters** 79 80| Name| Description| 81| -------- | -------- | 82| name | Name of the asynchronous trace.| 83| taskId | ID of the asynchronous trace. The start and end of an asynchronous trace task do not occur in sequence. Therefore, the start and end of an asynchronous trace need to be matched based on the task name and the unique task ID together.| 84 85**Since** 86 8710 88 89 90### OH_HiTrace_FinishTrace() 91 92 93``` 94void OH_HiTrace_FinishTrace (void ) 95``` 96 97**Description** 98 99Marks the end of a synchronous trace. 100 101This API must be used with **OH_HiTrace_StartTrace** in pairs. During trace data parsing, the system matches it with the **OH_HiTrace_StartTrace** API recently invoked in the service process. 102 103**Since** 104 10510 106 107 108### OH_HiTrace_StartAsyncTrace() 109 110 111``` 112void OH_HiTrace_StartAsyncTrace (const char * name, int32_t taskId ) 113``` 114 115**Description** 116 117Marks the start of an asynchronous trace. 118 119This API is called to implement performance trace in asynchronous manner. The start and end of an asynchronous trace task do not occur in sequence. Therefore, a unique **taskId** is required to ensure proper data parsing. It is passed as an input parameter for the asynchronous API. This API is used with **OH_HiTrace_FinishAsyncTrace** in pairs. The two APIs that have the same name and task ID together form an asynchronous trace. If multiple trace tasks with the same name need to be performed at the same time or a trace task needs to be performed multiple times concurrently, different task IDs must be specified in **OH_HiTrace_StartTrace**. If the trace tasks with the same name are not performed at the same time, the same taskId can be used. 120 121**Parameters** 122 123| Name| Description| 124| -------- | -------- | 125| name | Name of an asynchronous trace.| 126| taskId | ID of the asynchronous trace. The start and end of an asynchronous trace task do not occur in sequence. Therefore, the start and end of an asynchronous trace need to be matched based on the task name and the unique task ID together.| 127 128**Since** 129 13010 131 132 133### OH_HiTrace_StartTrace() 134 135 136``` 137void OH_HiTrace_StartTrace (const char * name) 138``` 139 140**Description** 141 142Marks the start of a synchronous trace. 143 144This API is used with **OH_HiTrace_FinishTrace** in pairs. The two APIs can be used in nested mode. The stack data structure is used for matching during trace data parsing. 145 146**Parameters** 147 148| Name| Description| 149| -------- | -------- | 150| name | Name of the synchronous trace.| 151 152**Since** 153 15410 155