1e41f4b71Sopenharmony_ci# @ohos.hiTraceMeter (HiTraceMeter) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **HiTraceMeter** module provides the functions of tracing service processes and monitoring the system performance. It provides the data needed for HiTraceMeter to carry out performance analysis. 4e41f4b71Sopenharmony_ciFor details about the development process, see [Development of Performance Tracing](../../dfx/hitracemeter-guidelines-arkts.md). 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ci> **NOTE** 7e41f4b71Sopenharmony_ci> 8e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci## Modules to Import 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci```js 14e41f4b71Sopenharmony_ciimport { hiTraceMeter } from '@kit.PerformanceAnalysisKit'; 15e41f4b71Sopenharmony_ci``` 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci## hiTraceMeter.startTrace 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_cistartTrace(name: string, taskId: number): void 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ciMarks the start of a trace task. 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ciIf 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**. 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ciIf the trace tasks with the same name are not performed at the same time, the same taskId can be used. For a specific example, refer to an example in [hiTraceMeter.finishTrace](#hitracemeterfinishtrace). 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiTrace 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci**Parameters** 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 33e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 34e41f4b71Sopenharmony_ci| name | string | Yes | Name of the trace task to start. | 35e41f4b71Sopenharmony_ci| taskId | number | Yes | Task ID. | 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci**Example** 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci```js 40e41f4b71Sopenharmony_cihiTraceMeter.startTrace("myTestFunc", 1); 41e41f4b71Sopenharmony_ci``` 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ci## hiTraceMeter.finishTrace 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_cifinishTrace(name: string, taskId: number): void 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ciStops a trace task. 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ciTo stop a trace task, the values of name and task ID in **finishTrace** must be the same as those in [startTrace](#hitracemeterstarttrace). 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiTrace 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci**Parameters** 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 57e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 58e41f4b71Sopenharmony_ci| name | string | Yes | Name of the trace task to start. | 59e41f4b71Sopenharmony_ci| taskId | number | Yes | Task ID. | 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci**Example** 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci```js 64e41f4b71Sopenharmony_cihiTraceMeter.finishTrace("myTestFunc", 1); 65e41f4b71Sopenharmony_ci``` 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci```js 68e41f4b71Sopenharmony_ci// Start trace tasks with the same name concurrently. 69e41f4b71Sopenharmony_cihiTraceMeter.startTrace("myTestFunc", 1); 70e41f4b71Sopenharmony_ci// Service flow... 71e41f4b71Sopenharmony_cihiTraceMeter.startTrace("myTestFunc", 2); // Start the second trace task with the same name while the first task is still running. The tasks are running concurrently and therefore their taskId must be different. 72e41f4b71Sopenharmony_ci// Service flow... 73e41f4b71Sopenharmony_cihiTraceMeter.finishTrace("myTestFunc", 1); 74e41f4b71Sopenharmony_ci// Service flow... 75e41f4b71Sopenharmony_cihiTraceMeter.finishTrace("myTestFunc", 2); 76e41f4b71Sopenharmony_ci``` 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci```js 79e41f4b71Sopenharmony_ci// Start trace tasks with the same name in serial mode. 80e41f4b71Sopenharmony_cihiTraceMeter.startTrace("myTestFunc", 1); 81e41f4b71Sopenharmony_ci// Service flow... 82e41f4b71Sopenharmony_cihiTraceMeter.finishTrace("myTestFunc", 1); // End the first trace task. 83e41f4b71Sopenharmony_ci// Service flow... 84e41f4b71Sopenharmony_cihiTraceMeter.startTrace("myTestFunc", 1); // Start the second trace task with the same name in serial mode. 85e41f4b71Sopenharmony_ci// Service flow... 86e41f4b71Sopenharmony_cihiTraceMeter.finishTrace("myTestFunc", 1); 87e41f4b71Sopenharmony_ci``` 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ci## hiTraceMeter.traceByValue 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_citraceByValue(name: string, count: number): void 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ciMarks the value changes of a numeric variable in a trace task. 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiTrace 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ci**Parameters** 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 101e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 102e41f4b71Sopenharmony_ci| name | string | Yes | Name of the variable. | 103e41f4b71Sopenharmony_ci| count | number | Yes | Value of the variable. | 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_ci**Example** 106e41f4b71Sopenharmony_ci```js 107e41f4b71Sopenharmony_cilet traceCount = 3; 108e41f4b71Sopenharmony_cihiTraceMeter.traceByValue("myTestCount", traceCount); 109e41f4b71Sopenharmony_citraceCount = 4; 110e41f4b71Sopenharmony_cihiTraceMeter.traceByValue("myTestCount", traceCount); 111e41f4b71Sopenharmony_ci// Service flow... 112e41f4b71Sopenharmony_ci``` 113