1# @ohos.hiTraceMeter (Performance Tracing)
2
3The **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.
4For details about the development process, see [Development of Performance Tracing](../../dfx/hitracemeter-guidelines-arkts.md).
5
6> **NOTE**
7>
8> 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.
9
10
11## Modules to Import
12
13```js
14import { hiTraceMeter } from '@kit.PerformanceAnalysisKit';
15```
16
17
18## hiTraceMeter.startTrace
19
20startTrace(name: string, taskId: number): void
21
22Marks the start of a trace task.
23
24If 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**.
25
26If 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).
27
28**System capability**: SystemCapability.HiviewDFX.HiTrace
29
30**Parameters**
31
32| Name | Type | Mandatory | Description |
33| -------- | -------- | -------- | -------- |
34| name | string | Yes | Name of the trace task to start. |
35| taskId | number | Yes | Task ID. |
36
37**Example**
38
39```js
40hiTraceMeter.startTrace("myTestFunc", 1);
41```
42
43
44## hiTraceMeter.finishTrace
45
46finishTrace(name: string, taskId: number): void
47
48Stops a trace task.
49
50To stop a trace task, the values of name and task ID in **finishTrace** must be the same as those in [startTrace](#hitracemeterstarttrace).
51
52**System capability**: SystemCapability.HiviewDFX.HiTrace
53
54**Parameters**
55
56| Name | Type | Mandatory | Description |
57| -------- | -------- | -------- | -------- |
58| name | string | Yes | Name of the trace task to start. |
59| taskId | number | Yes | Task ID. |
60
61**Example**
62
63```js
64hiTraceMeter.finishTrace("myTestFunc", 1);
65```
66
67```js
68// Start trace tasks with the same name concurrently.
69hiTraceMeter.startTrace("myTestFunc", 1);
70// Service flow...
71hiTraceMeter.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.
72// Service flow...
73hiTraceMeter.finishTrace("myTestFunc", 1);
74// Service flow...
75hiTraceMeter.finishTrace("myTestFunc", 2);
76```
77
78```js
79// Start trace tasks with the same name in serial mode.
80hiTraceMeter.startTrace("myTestFunc", 1);
81// Service flow...
82hiTraceMeter.finishTrace("myTestFunc", 1);  // End the first trace task.
83// Service flow...
84hiTraceMeter.startTrace("myTestFunc", 1);   // Start the second trace task with the same name in serial mode.
85// Service flow...
86hiTraceMeter.finishTrace("myTestFunc", 1);
87```
88
89
90## hiTraceMeter.traceByValue
91
92traceByValue(name: string, count: number): void
93
94Marks the value changes of a numeric variable in a trace task.
95
96**System capability**: SystemCapability.HiviewDFX.HiTrace
97
98**Parameters**
99
100| Name | Type | Mandatory | Description |
101| -------- | -------- | -------- | -------- |
102| name | string | Yes | Name of the variable. |
103| count | number | Yes | Value of the variable. |
104
105**Example**
106```js
107let traceCount = 3;
108hiTraceMeter.traceByValue("myTestCount", traceCount);
109traceCount = 4;
110hiTraceMeter.traceByValue("myTestCount", traceCount);
111// Service flow...
112```
113