1# Development of Performance Tracing 2 3## When to Use 4 5HiTraceMeter provides APIs for system performance tracing. You can call the APIs provided by HiTraceMeter module in your own service logic to effectively track service processes and check the system performance. 6 7## Available APIs 8 9The performance tracing APIs are provided by the **hiTraceMeter** module. For details, see [API Reference](../reference/apis/js-apis-hitracemeter.md). 10 11**APIs for performance tracing** 12 13| API| Return Value| Description| 14| ---------------------------------------------------------------------------- | --------- | ------------ | 15| hiTraceMeter.startTrace(name: string, taskId: number, expectedTime?: number) | void | Starts a trace task. 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 **startTrace**. If the trace tasks with the same name are not performed at the same time, the same task ID can be used.| 16| hiTraceMeter.finishTrace(name: string, taskId: number) | void | Stops a trace task. The values of **name** and **taskId** must be the same as those of **hiTraceMeter.startTrace**.| 17| hiTraceMeter.traceByValue(name: string, value: number) | void | Traces the value changes of a variable.| 18 19## How to Develop 20 21In this example, distributed call chain tracing begins when the application startup execution page is loaded and stops when the service usage is completed. 22 231. Create a JS application project. In the displayed **Project** window, choose **entry** > **src** > **main** > **js** > **default** > **pages** > **index**, and double-click **index.js**. Add the code to implement performance tracing upon page loading. The sample code is as follows: 24 25 ```js 26 import hiTraceMeter from '@ohos.hiTraceMeter' 27 28 export default { 29 data: { 30 title: "" 31 }, 32 onInit() { 33 this.title = this.$t('strings.world'); 34 35 // The expected duration of the trace task is 5 ms. 36 hiTraceMeter.startTrace("business", 1); 37 hiTraceMeter.startTrace("business", 1, 5); 38 39 // Start track tasks with the same name concurrently. 40 hiTraceMeter.startTrace("business", 1); 41 // Keep the service process running. 42 console.log(`business running`); 43 hiTraceMeter.startTrace("business", 2); // Start the second trace task while the first task is still running. The first and second tasks have the same name but different task IDs. 44 // Keep the service process running. 45 console.log(`business running`); 46 hiTraceMeter.finishTrace("business", 1); 47 // Keep the service process running. 48 console.log(`business running`); 49 hiTraceMeter.finishTrace("business", 2); 50 51 // Start track tasks with the same name at different times. 52 hiTraceMeter.startTrace("business", 1); 53 // Keep the service process running. 54 console.log(`business running`); 55 hiTraceMeter.finishTrace("business", 1); // End the first trace task. 56 // Keep the service process running. 57 console.log(`business running`); 58 hiTraceMeter.startTrace("business", 1); // Start the second trace task after the first trace task ends. The two tasks have the same name and task ID. 59 // Keep the service process running. 60 console.log(`business running`); 61 62 let traceCount = 3; 63 hiTraceMeter.traceByValue("myTestCount", traceCount); 64 traceCount = 4; 65 hiTraceMeter.traceByValue("myTestCount", traceCount); 66 hiTraceMeter.finishTrace("business", 1); 67 } 68 } 69 ``` 70 712. Click the run button on the application page. Then, you'll obtain the log information for service analysis. 72