diff --git a/en/application-dev/dfx/Readme-EN.md b/en/application-dev/dfx/Readme-EN.md index 88e6d8259de26dc4a8ad5678ecb795e716a65c63..06b61fb2e8e733f0762e0f1f5ddae9ea81344396 100644 --- a/en/application-dev/dfx/Readme-EN.md +++ b/en/application-dev/dfx/Readme-EN.md @@ -2,5 +2,10 @@ - Application Event Logging - [Overview of Application Event Logging](hiappevent-overview.md) - - [Development Guidelines on Application Event Logging](hiappevent-guidelines.md) - + - [Development of Application Event Logging](hiappevent-guidelines.md) +- Performance Tracing + - [Overview of Performance Tracing](hitracemeter-overview.md) + - [Development of Performance Tracing](hitracemeter-guidelines.md) +- Distributed Call Chain Tracing + - [Overview of Distributed Call Chain Tracing](hitracechain-overview.md) + - [Development of Distributed Call Chain Tracing](hitracechain-guidelines.md) diff --git a/en/application-dev/dfx/hiappevent-guidelines.md b/en/application-dev/dfx/hiappevent-guidelines.md index 96222dc59426806989235632bcb1090006ebc1ff..414dc3c33099b8225a4a73bcd70fad79604583cf 100644 --- a/en/application-dev/dfx/hiappevent-guidelines.md +++ b/en/application-dev/dfx/hiappevent-guidelines.md @@ -1,4 +1,4 @@ -# Development Guidelines on Application Event Logging +# Development of Application Event Logging ## When to Use diff --git a/en/application-dev/dfx/hitracechain-guidelines.md b/en/application-dev/dfx/hitracechain-guidelines.md new file mode 100644 index 0000000000000000000000000000000000000000..06d849872941ab84a894224ef4e3d17ddb8d491d --- /dev/null +++ b/en/application-dev/dfx/hitracechain-guidelines.md @@ -0,0 +1,56 @@ +# Development of Distributed Call Chain Tracing + +## When to Use + +HiTraceChain is the module that provides APIs to implement call chain tracing throughout a service process. With HiTraceChain, you can quickly obtain the run log for the call chain of a specified service process and locate faults in inter-device, inter-process, or inter-thread communications. + +## Available APIs + +The APIs for distributed call chain tracing are provided by the **hiTraceChain** module. For details, see [API Reference](../reference/apis/js-apis-hitracechain.md). + +**APIs for distributed call chain tracing** + +| API| Return Value| Description| +| ------------------------------------------------------------------------------------------------------------------- | -------------- | ------------ | +| hiTraceChain.begin(name: string, flags: number = HiTraceFlag.DEFAULT) | HiTraceId | Starts call chain tracing.| +| hiTraceChain.tracepoint(mode: HiTraceCommunicationMode, type: HiTraceTracepointType, id: HiTraceId, msg?: string) | void | Creates a trace point.| +| hiTraceChain.end(id: HiTraceId) | void | Stops call chain tracing.| + +## How to Develop + +In this example, distributed call chain tracing begins when the application startup execution page is loaded and stops when the service usage is completed. + +1. 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 call chain tracing upon page loading. The sample code is as follows: + + ``` + import hiTraceChain from '@ohos.hiTraceChain' + + export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + + // 1. Enable distributed call chain tracing. + let asyncTraceId = hiTraceChain.begin("business", hiTraceChain.HiTraceFlag.INCLUDE_ASYNC | hiTraceChain.HiTraceFlag.DONOT_CREATE_SPAN); + + // 2. Start the service process. + console.log(`business start`); + + // 3. Add a trace point. + hiTraceChain.tracepoint(hiTraceChain.HiTraceCommunicationMode.THREAD, hiTraceChain.HiTraceTracepointType.SS, asyncTraceId, "Just an example"); + + // 4. Keep the service process running. + console.log(`business running`); + + // 5. End the service process. + console.log(`business end`); + + // 6. Stop call chain tracing. + hiTraceChain.end(asyncTraceId); + } + } + ``` + +2. Click the run button on the application page. Then, you'll obtain the log information for service analysis. diff --git a/en/application-dev/dfx/hitracechain-overview.md b/en/application-dev/dfx/hitracechain-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..64eae517ace23beb6e3ad80bc7b6f0df1ef9b34a --- /dev/null +++ b/en/application-dev/dfx/hitracechain-overview.md @@ -0,0 +1,17 @@ +# Overview of Distributed Call Chain Tracing + +hiTraceChain is a lightweight implementation of the cloud-based distributed call chain tracing. It allows applications to trace cross-thread, cross-process, and cross-device service calls. + +## Basic Concepts + +- **chainId** + + Distributed call chain tracing ID, which is a part of **HiTraceId** and is used to identify the service process being traced. + +## Working Principles + +The hiTraceChain module generates a unique **chainId** for a service process and passes it to various information (including application events, system time, and logs) specific to the service process. During debugging and fault locating, you can use the unique **chainId** to quickly correlate various information related to the service process. + +## Constraints + +All APIs provided by the hiTraceChain module work in synchronous mode. diff --git a/en/application-dev/dfx/hitracemeter-guidelines.md b/en/application-dev/dfx/hitracemeter-guidelines.md new file mode 100644 index 0000000000000000000000000000000000000000..e7e97631c240bb42358d3b0b630a92094f34bcfc --- /dev/null +++ b/en/application-dev/dfx/hitracemeter-guidelines.md @@ -0,0 +1,71 @@ +# Development of Performance Tracing + +## When to Use + +HiTraceMeter 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. + +## Available APIs + +The performance tracing APIs are provided by the **hiTraceMeter** module. For details, see [API Reference]( ../reference/apis/js-apis-hitracemeter.md). + +**APIs for performance tracing** + +| API| Return Value| Description| +| ---------------------------------------------------------------------------- | --------- | ------------ | +| 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.| +| 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**.| +| hiTraceMeter.traceByValue(name: string, value: number) | void | Traces the value changes of a variable.| + +## How to Develop + +In this example, distributed call chain tracing begins when the application startup execution page is loaded and stops when the service usage is completed. + +1. 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: + + ```js + import hiTraceMeter from '@ohos.hiTraceMeter' + + export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + + // The expected duration of the trace task is 5 ms. + hiTraceMeter.startTrace("business", 1); + hiTraceMeter.startTrace("business", 1, 5); + + // Start track tasks with the same name concurrently. + hiTraceMeter.startTrace("business", 1); + // Keep the service process running. + console.log(`business running`); + 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. + // Keep the service process running. + console.log(`business running`); + hiTraceMeter.finishTrace("business", 1); + // Keep the service process running. + console.log(`business running`); + hiTraceMeter.finishTrace("business", 2); + + // Start track tasks with the same name at different times. + hiTraceMeter.startTrace("business", 1); + // Keep the service process running. + console.log(`business running`); + hiTraceMeter.finishTrace("business", 1); // End the first trace task. + // Keep the service process running. + console.log(`business running`); + 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. + // Keep the service process running. + console.log(`business running`); + + let traceCount = 3; + hiTraceMeter.traceByValue("myTestCount", traceCount); + traceCount = 4; + hiTraceMeter.traceByValue("myTestCount", traceCount); + hiTraceMeter.finishTrace("business", 1); + } + } + ``` + +2. Click the run button on the application page. Then, you'll obtain the log information for service analysis. diff --git a/en/application-dev/dfx/hitracemeter-overview.md b/en/application-dev/dfx/hitracemeter-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..3683092b34fcd23a65245303406934b3fb8acad5 --- /dev/null +++ b/en/application-dev/dfx/hitracemeter-overview.md @@ -0,0 +1,18 @@ +# Overview of Performance Tracing + +hiTraceMeter is a tool for you to trace service processes and monitor system performance. Through encapsulating and extending the ftrace inside the kernel, hiTraceMeter supports performance tracing for code execution in the user space. You can use hiTraceMeter APIs to implement performance tracing and use the hiTraceMeter CLI tool to collect traced data. + +## Basic Concepts + +- **hiTraceMeter Tag** + + Tag used for tracing data categorization. It is also known as **hiTraceMeter Category**. Generally, one subsystem maps to a tag. The tag is passed as the **Tag** parameter in performance tracing APIs. When you use the hiTraceMeter CLI tool to collect tracing data, only the tracing data specified by the **Tag** parameter is collected. + +## Working Principles + +- The application calls hiTraceMeter APIs to perform performance tracing. The APIs output the tracing data to the kernel's ftrace data buffer through the kernel's sysfs file interface. +- The hiTraceMeter CLI tool reads the tracing data in the ftrace data buffer and saves the trace data as a text file on the device. + +## Constraints + +- Due to the asynchronous I/O feature of JS, the hiTraceMeter module provides only asynchronous APIs.