提交 d9f3c49e 编写于 作者: S shawn_he

update doc

Signed-off-by: Nshawn_he <shawn.he@huawei.com>
上级 74c14397
......@@ -37,18 +37,15 @@ No error will be thrown if the preceding APIs are used in the troubleshooting sc
### Application State Management
Since API version 10, application recovery is not limited to automatic restart in the case of an exception. Therefore, you need to understand when the application will load the saved state.
If the last exit of an application is not initiated by a user and a saved state is available for recovery, the startup reason is set to **APP_RECOVERY** when the application is started by the user next time, and the recovery state of the application is cleared.
The application recovery status flag is set when **saveAppState** is actively or passively called. The flag is cleared when the application exits normally or the saved state is consumed. (A normal exit is usually triggered by pressing the back key or clearing recent tasks.)
![Application recovery status management](./figures/application_recovery_status_management.png)
### Application State Saving and Restore
API version 10 or later supports saving of the application state when an application is suspended. If a JsError occurs, **onSaveState** is called in the main thread. If an AppFreeze occurs, however, the main thread may be suspended, and therefore **onSaveState** is called in a non-main thread. The following figure shows the main service flow.
![Application recovery from the freezing state](./figures/application_recovery_from_freezing.png)
When the application is suspended, the callback is not executed in the JS thread. Therefore, you are advised not to use the imported dynamic Native library or access the **thread_local** object created by the main thread in the code of the **onSaveState** callback.
### Framework Fault Management
......@@ -62,13 +59,9 @@ Fault management is an important way for applications to deliver a better user e
- Fault query is the process of calling APIs of [faultLogger](../reference/apis/js-apis-faultLogger.md) to obtain the fault information.
The figure below does not illustrate the time when [faultLogger](../reference/apis/js-apis-faultLogger.md) is called. You can refer to the [LastExitReason](../reference/apis/js-apis-app-ability-abilityConstant.md#abilityconstantlastexitreason) passed during application initialization to determine whether to call [faultLogger](../reference/apis/js-apis-faultLogger.md) to query information about the previous fault.
![Fault rectification process](./figures/fault_rectification.png)
It is recommended that you call [errorManager](../reference/apis/js-apis-app-ability-errorManager.md) to handle the exception. After the processing is complete, you can call the **saveAppState** API and restart the application.
If you do not register [ErrorObserver](../reference/apis/js-apis-inner-application-errorObserver.md) or enable application recovery, the application process will exit according to the default processing logic of the system. Users can restart the application from the home screen.
If you have enabled application recovery, the recovery framework first checks whether application state saving is supported and whether the application state saving is enabled. If so, the recovery framework invokes [onSaveState](../reference/apis/js-apis-app-ability-uiAbility.md#uiabilityonsavestate) of the [Ability](../reference/apis/js-apis-app-ability-uiAbility.md). Finally, the application is restarted.
### Supported Application Recovery Scenarios
......
......@@ -4,108 +4,121 @@
## Overview
### Function
### Function Introduction
FaultLogger is a maintenance and debugging log framework provided by OpenHarmony. It enables unified detection, log collection, log storage, and log reporting for application, ability, and system service process crashes. It is available for the standard system and the Linux kernel-based small system.
FaultLogger is responsible for fault recording of OpenHarmony. It runs on the following two components based on the service object:
- HiView: serves functional modules at the application layer and native layer. It manages various fault information in the system and provides APIs for modules to query faults.
- Hiview: serves functional modules at the application layer and native layer. It manages various fault information in the system and provides APIs for modules to query faults.
- FaultLoggerd: serves the crash process. It collects information about abnormal daemon processes in C/C++ and obtains the process call stack.
- Faultloggerd: serves the crash process. It collects information about the abnormal daemon process in C/C++ and obtains call stack information of the process.
The following figure shows the process of handling a process crash based on the FaultLogger service.
**Figure 1** Process crash handling flowchart
![process_crash_handling](figures/process_crash_handling.png)
![Process crash handling flowchart](figures/process_crash_handling_flowchart.png)
1. After the signal processor is installed, the **DFX_SignalHandler** function detects and responds to the process crash exception signal.
1. After the signal processor is installed, SignalHandler uses the **DFX_SignalHandler** function to detect and respond to the process crash exception signal thrown by the kernel.
2. **SignalHandler** forks a child process after detecting the exception signal and runs **ProcessDump** to dump the stack information of the crashed process and thread.
2. When detecting a process crash exception signal, SignalHandler forks a child process and runs ProcessDump to dump the stack information of the crashed process and thread.
3. **ProcessDump** then writes a log to the temporary storage directory in FaultLoggerd, generating a full crash log.
3. ProcessDump applies to Faultloggerd for a file handle for storing fault logs. After reading the exception stack information, ProcessDump writes the information to the file to generate a complete crash log.
4. FaultLoggerd reports the fault through the **AddFaultLog()** API provided by HiView. HiView handles the fault, generates a simple crash log, and reports a HiSysEvent.
4. After collecting the complete crash log, ProcessDump reports the log to Hiview by using the **AddFaultLog()** API. Hiview generates a simplified crash log and reports a system event through HiSysEvent.
With this design, a small-system with limited resources can obtain logs for locating crash faults as long as FaultLoggerd is deployed.
With this design, a small-system with limited resources can obtain logs for locating crash faults as long as Faultloggerd is deployed.
### Use Cases
FaultLoggerd provides a lightweight approach for you to locate crash or suspension problems during development and testing.
Faultloggerd provides a lightweight approach for you to locate crash or suspension problems during development and testing.
It is applicable to the following scenarios:
The following table describes the application scenarios.
**Table 1** Application scenarios of the Faultloggerd module
| Scenario| Tool| Usage|
| Scenario| Tool| Usage|
| -------- | -------- | -------- |
| To understand the function call sequence| DumpCatcher&nbsp;API | See [Using DumpCatcher to Obtain the Call Stack](#using-dumpcatcher-to-obtain-the-call-stack).|
| Application suspension or high CPU usage| ProcessDump | See [Using ProcessDump to Obtain the Call Stack](#using-processdump-to-obtain-the-call-stack).|
| Signal crash not handled by the process| Crash log and addr2line tool| See [Locating Faults Based on Crash Logs](#locating-faults-based-on-crash-logs).|
| Understanding of the function call sequence| DumpCatcher API | See [Using DumpCatcher APIs to Obtain Call Stack Information](#using-dumpcatcher-apis-to-obtain-call-stack-information).|
| Application suspension or high CPU usage| DumpCatcher Command Tool | See [Using DumpCatcher Commands to Obtain Call Stack Information](#using-dumpcatcher-commands-to-obtain-call-stack-information).|
| Crash fault location| Crash log and addr2line tool| For details, see [Locating Faults Based on the Crash Log](#locating-faults-based-on-the-crash-log).|
## Using DumpCatcher to Obtain the Call Stack
## Using DumpCatcher APIs to Obtain the Call Stack Information
### Available APIs
DumpCatcher can capture the call stack of a specified process (thread) on OpenHarmony.
DumpCatcher can capture the call stack information of the specified process (thread) on OpenHarmony.
Table 2 DumpCatcher APIs
**Table 2** DumpCatcher APIs
| Class| API| Description|
| Class| API| Description|
| -------- | -------- | -------- |
| DfxDumpCatcher | bool&nbsp;DumpCatch(const&nbsp;int&nbsp;pid,&nbsp;const&nbsp;int&nbsp;tid,&nbsp;std::string&amp;&nbsp;msg) | Return value:<br>**true**: Back trace is successful. Related information is stored in the **msg** string object.<br>**false**: Back trace failed.<br>Input arguments:<br>**pid**: target process ID.<br>**tid**: target thread ID. If all threads in the process need to be back traced, set **tid** to **0**.<br>Output argument:<br>**msg**: return message. If back trace is successful, the call stack information is returned through **msg**.|
| DfxDumpCatcher | bool DumpCatch(const int pid, const int tid, std::string&amp; msg) | Return value:<br>- **true**: Dumping of stack information is successful. Related information is stored in the msg string object.<br>- **false**: Dumping of stack information has failed.<br> Input arguments:<br>- **pid**: target process ID.<br>- **tid**: target thread ID. If all threads in the process need to be back traced, set **tid** to **0**.<br> Output arguments:<br>- **msg**: If back trace is successful, call stack information is returned through **msg**.|
| DfxDumpCatcher | bool DumpCatchMix(const int pid, const int tid, std::string&amp; msg) | Return value:<br>- **true**: Dumping of stack information is successful. Related information is stored in the msg string object.<br>- **false**: Dumping of stack information has failed.<br> Input arguments:<br>**pid**: target process ID.<br>- **tid**: target thread ID. If all threads in the process need to be back traced, set **tid** to **0**.<br> Output arguments:<br>- **msg**: If back trace is successful, hybrid stack information is returned through **msg**.|
| DfxDumpCatcher | bool DumpCatchFd(const int pid, const int tid, std::string&amp; msg, int fd) | Return value:<br>- **true**: Dumping of stack information is successful. Related information is stored in the msg string object.<br>- **false**: Dumping of stack information has failed.<br> Input arguments:<br>**pid**: target process ID.<br>- **tid**: target thread ID. If all threads in the process need to be back traced, set **tid** to **0**.<br>- **fd**: handle of the file to be written.<br> Output parameters:<br>- **msg**: If back trace is successful, call stack information is returned through **msg**.|
| DfxDumpCatcher | bool DumpCatchMultiPid(const std::vector\<int> pidV, std::string&amp; msg) | Return value:<br>- **true**: Dumping of stack information is successful. Related information is stored in the msg string object.<br>- **false**: Dumping of stack information has failed.<br> Input arguments:<br>- **pidV**: target process ID list.<br> Output arguments:<br>- **msg**: If back trace is successful, call stack information is returned through **msg**.|
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>
> If the PID that calls this API is different from the target PID, the caller must be the **system** or **root** user. To capture the call stack of a process that does not belong to the current user group, ensure that you have permissions to read **/proc/pid/maps** and implement **ptrace** on the peer process.
> **NOTE**
> If the PID that calls this API is different from the target PID, the caller must be the **system** or **root** user.
### Development Example
### How to Develop
You can use DumpCatcher to obtain call stack information for the specified process (thread) of an application. The following uses the **dumpcatcherdemo** module as an example to describe how to use the DumpCatcher APIs to obtain the call stack information.
You can use DumpCatcher to obtain the call stack of a specified process (thread) in your applications. The following uses the **dumpcatcherdemo** module as an example to describe how to use the DumpCatcher API to obtain the call stack.
1. Add the DumpCatcher dependency to the build file. Take /base/hiviewdfx/faultloggerd/example/BUILD.gn as an example. Add the **dump_catcher.h** file path to **include_dirs** and add the required **//base/hiviewdfx/faultloggerd/interfaces/innerkits/dump_catcher:lib_dfx_dump_catcher** module to **deps**.
1. Add the DumpCatcher dependency to the build file. Take /base/hiviewdfx/faultloggerd/example/BUILD.gn as an example. Add the **dfx_dump_catcher.h** file path to **include_dirs** and add the required **//base/hiviewdfx/faultloggerd/interfaces/innerkits/dump_catcher:lib_dfx_dump_catcher** module to **deps**.
```
import("//base/hiviewdfx/faultloggerd/faultloggerd.gni")
import("//build/ohos.gni")
config("dumpcatcherdemo_config") {
visibility = [ ":*" ]
include_dirs = [
".",
"//utils/native/base/include",
"//base/hiviewdfx/faultloggerd/interfaces/innerkits/dump_catcher/include/", # Add the path of the dump_catcher header file.
]
}
ohos_executable("dumpcatcherdemo") { sources = [ "dump_catcher_demo.cpp" ] configs = [ ":dumpcatcherdemo_config" ] deps = [ "//base/hiviewdfx/faultloggerd/interfaces/innerkits/dump_catcher:lib_dfx_dump_catcher", # Add the DumpCatcher module dependency. "//utils/native/base:utils", ] external_deps = [ "hilog_native:libhilog" ] install_enable = true part_name = "faultloggerd" subsystem_name = "hiviewdfx"
ohos_executable("dumpcatcherdemo") {
sources = [ "dump_catcher_demo.cpp" ]
configs = [ ":dumpcatcherdemo_config" ]
deps = [
"//base/hiviewdfx/faultloggerd/interfaces/innerkits/dump_catcher:lib_dfx_dump_catcher", # Add the DumpCatcher module dependency.
"//utils/native/base:utils",
]
external_deps = [ "hilog_native:libhilog" ]
install_enable = true
part_name = "faultloggerd"
subsystem_name = "hiviewdfx"
}
```
2. Define the header file. Take **/base/hiviewdfx/faultloggerd/example/dump_catcher_demo.h** as an example. In the sample code, the function of the stack depth test is called to construct a call stack with a specified depth.
```
#ifndef DUMP_CATCHER_DEMO_H
#define DUMP_CATCHER_DEMO_H
#include <inttypes.h>
#define NOINLINE __attribute__((noinline))
// Define the macro function to automatically generate a function call chain.
#define GEN_TEST_FUNCTION(FuncNumA, FuncNumB) \
__attribute__((noinline)) int TestFunc##FuncNumA() \
{ \
return TestFunc##FuncNumB(); \
}
// Call the function of the stack depth test.
int TestFunc0(void);
int TestFunc1(void);
......@@ -118,33 +131,33 @@ You can use DumpCatcher to obtain the call stack of a specified process (thread)
int TestFunc8(void);
int TestFunc9(void);
int TestFunc10(void);
#endif // DUMP_CATCHER_DEMO_H
```
3. Call the **DumpCatch** API in the source file. Take **/base/hiviewdfx/faultloggerd/example/dump_catcher_demo.cpp** as an example. Include the **dfx_dump_catcher.h** file, declare the **DfxDumpCatcher** object, use the macro function to construct a function call chain, call the **DumpCatch** method, and pass the required process ID and thread ID of the call stack into this method.
```
#include "dump_catcher_demo.h"
#include <iostream>
#include <string>
#include <unistd.h>
// Include the dfx_dump_catcher.h file.
#include "dfx_dump_catcher.h"
using namespace std;
NOINLINE int TestFunc10(void)
{
OHOS::HiviewDFX::DfxDumpCatcher dumplog;
string msg = "";
bool ret = dumplog.DumpCatch(getpid(), gettid(), msg); // Call the DumpCatch API to obtain the call stack.
bool ret = dumplog.DumpCatch(getpid(), gettid(), msg); // Call the DumpCatch API to obtain the call stack information.
if (ret) {
cout << msg << endl;
}
return 0;
}
// Use the macro function to automatically generate a function call chain.
GEN_TEST_FUNCTION(0, 1)
GEN_TEST_FUNCTION(1, 2)
......@@ -156,7 +169,7 @@ You can use DumpCatcher to obtain the call stack of a specified process (thread)
GEN_TEST_FUNCTION(7, 8)
GEN_TEST_FUNCTION(8, 9)
GEN_TEST_FUNCTION(9, 10)
int main(int argc, char *argv[])
{
TestFunc0();
......@@ -165,55 +178,57 @@ You can use DumpCatcher to obtain the call stack of a specified process (thread)
```
## Using ProcessDump to Obtain the Call Stack
## Using DumpCatcher Commands to Obtain Call Stack Information
### Tool Description
ProcessDump is a command line interface (CLI) based tool for capturing call stacks on OpenHarmony. It uses the **-p** and **-t** parameters to specify the process and thread. After the command is executed, the thread stack information of the specified process is displayed in the CLI window.
DumpCatcher Command Tool is a command line interface (CLI)-based tool for capturing call stack information on OpenHarmony. It uses the **-p** and **-t** parameters to specify the process and thread. After the command is executed, the thread stack information of the specified process is displayed in the CLI window. By specifying the **-m** parameter, you can also capture the JS and Native hybrid stack information of an application process.
**Table 3** Usage of the CLI-based ProcessDump
**Table 3** Usage of the DumpCatcher Command Tool
| Tool| Path| Command| Description|
| Tool| Path| Command| Description|
| -------- | -------- | -------- | -------- |
| processdump | /system/bin | -&nbsp;processdump&nbsp;-p&nbsp;[pid]<br>-&nbsp;processdump&nbsp;-p&nbsp;[pid]&nbsp;-t&nbsp;[tid] | **Arguments:**<br>**- -p [pid]**: prints stack information for all threads of the specified process.<br>**- -p [pid] -t [tid]**: prints information for the specified thread of the specified process.<br>**Return value:**<br>If the stack information is parsed successfully, the information is displayed in the standard output. If the stack information fails to be parsed, error information is displayed.|
| dumpcatcher | /system/bin | - dumpcatcher -p [pid]<br>- dumpcatcher -p [pid] -t [tid]<br>- dumpcatcher -m -p [pid]<br>- dumpcatcher -m -p [pid] -t [tid]<br>| **Description:**<br>- **-p [pid]**: prints all thread stack information of the specified process.<br>- **-p [pid] -t [tid]**: prints stack information for the specified thread of the specified process.<br>- **-m -p [pid]**: prints hybrid stack information for all threads of the specified process.<br>- **-m -p [pid] -t [tid]**: prints hybrid stack information for the specified thread of the specified process.<br>**Return value:**<br>If the stack information is parsed successfully, the information is displayed in the standard output. If the stack information fails to be parsed, error information is displayed.|
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>
> This tool must be used by the **root** user, or the caller must have the permission to ptrace the target process and read the smaps of the target process.
### Development Example
### Example
Print call stack information of the **hiview** process.
Use ProcessDump to print the call stack of the **hiview** process.
```
# ps -A | grep hiview
114 ? 00:00:00 hiview
# processdump -p 114 -t 114
Tid:114, Name:hiview
#00 pc 0000000000089824(00000000b6f44824) /system/lib/ld-musl-arm.so.1(ioctl+68)
#01 pc 000000000002a709(00000000b6c56709) /system/lib/libipc_core.z.so(_ZN4OHOS15BinderConnector11WriteBinderEmPv+16)
#02 pc 000000000002ba75(00000000b6c57a75) /system/lib/libipc_core.z.so(_ZN4OHOS13BinderInvoker18TransactWithDriverEb+224)
#03 pc 000000000002bb37(00000000b6c57b37) /system/lib/libipc_core.z.so(_ZN4OHOS13BinderInvoker13StartWorkLoopEv+22)
#04 pc 000000000002c211(00000000b6c58211) /system/lib/libipc_core.z.so(_ZN4OHOS13BinderInvoker10JoinThreadEb+36)
#05 pc 0000000000038d07(00000000004bcd07) /system/bin/hiview(_ZNSt3__h6vectorINS_9sub_matchINS_11__wrap_iterIPKcEEEENS_9allocatorIS6_EEE8__appendEj+596)
#06 pc 0000000000028655(00000000004ac655) /system/bin/hiview
#07 pc 00000000000c2b08(00000000b6f7db08) /system/lib/ld-musl-arm.so.1(__libc_start_main+116)
#08 pc 00000000000285f4(00000000004ac5f4) /system/bin/hiview
#09 pc 0000000000028580(00000000004ac580) /system/bin/hiview
# ps -ef |grep hiview
hiview 240 1 0 17:01:49 ? 00:00:14 hiview
root 1822 1560 7 20:56:36 pts/0 00:00:00 grep hiview
# dumpcatcher -p 240 -t 240
Result: 0 ( no error )
Timestamp:2017-08-05 20:56:43.000
Pid:240
Uid:1201
Process name:/system/bin/hiview
Tid:240, Name:hiview
#00 pc 00098f8c /system/lib/ld-musl-arm.so.1(ioctl+68)
#01 pc 0000e2a1 /system/lib/chipset-pub-sdk/libipc_single.z.so
#02 pc 0000ed59 /system/lib/chipset-pub-sdk/libipc_single.z.so
#03 pc 0000ee1f /system/lib/chipset-pub-sdk/libipc_single.z.so
#04 pc 0000f745 /system/lib/chipset-pub-sdk/libipc_single.z.so
#05 pc 00037577 /system/bin/hiview
#06 pc 00025973 /system/bin/hiview
#07 pc 000db210 /system/lib/ld-musl-arm.so.1
#08 pc 000258d8 /system/bin/hiview
#09 pc 0002587c /system/bin/hiview
```
## Locating Faults Based on Crash Logs
## Locating Faults Based on the Crash Log
You can locate faults based on the crash stack logs generated by FaultLoggerd. This section describes how to use the addr2line tool to locate a crash fault.
You can locate faults based on the crash stack logs generated by Faultloggerd. This section describes how to use the addr2line tool to locate a crash fault.
1. Find a program crash or construct a crash.
For example, insert the following code into your code to trigger an invalid memory access fault (SIGSEGV).
```
NOINLINE int TriggerSegmentFaultException()
{
......@@ -228,40 +243,41 @@ You can locate faults based on the crash stack logs generated by FaultLoggerd. T
2. Obtain the crash function call stack log.
The process generates a temporary log file in the** /data/log/faultlog/temp** directory due to an exception that is not handled. The naming rule of the temporary log file is as follows:
```
cppcrash-pid-time
```
The generated call stack is as follows:
The generated call stack information is as follows:
```
Timestamp:2017-08-05 17:35:03.000
Pid:816
Uid:0
Process name:./crasher
Process name:./crasher_c
Reason:Signal:SIGSEGV(SEGV_ACCERR)@0x0042d33d
Fault thread Info:
Tid:816, Name:crasher
#00 pc 0000332c /data/crasher(TriggerSegmentFaultException+15)(8bc37ceb8d6169e919d178fdc7f5449e)
#01 pc 000035c7 /data/crasher(ParseAndDoCrash+277)(8bc37ceb8d6169e919d178fdc7f5449e)
#02 pc 00003689 /data/crasher(main+39)(8bc37ceb8d6169e919d178fdc7f5449e)
#03 pc 000c3b08 /system/lib/ld-musl-arm.so.1(__libc_start_main+116)
#04 pc 000032f8 /data/crasher(_start_c+112)(8bc37ceb8d6169e919d178fdc7f5449e)
#05 pc 00003284 /data/crasher(_start+32)(8bc37ceb8d6169e919d178fdc7f5449e)
Registers:
r0:0042d33d r1:0000000b r2:1725d4c4 r3:b6f9fa84
r4:bec97e69 r5:b6fc0268 r6:0042d661 r7:bec97d60
r8:00000000 r9:00000000 r10:00000000
fp:bec97d20 ip:00000020 sp:bec97cd0 lr:b6f9fae4 pc:0042d32c
#00 pc 000000000000332c(000000000042d32c) /data/crasher(TriggerSegmentFaultException+15)
#01 pc 00000000000035c7(000000000042d5c7) /data/crasher(ParseAndDoCrash+277)
#02 pc 0000000000003689(000000000042d689) /data/crasher(main+39)
#03 pc 00000000000c3b08(00000000b6fbbb08) /system/lib/ld-musl-arm.so.1(__libc_start_main+116)
#04 pc 00000000000032f8(000000000042d2f8) /data/crasher(_start_c+112)
#05 pc 0000000000003284(000000000042d284) /data/crasher(_start+32)
```
3. Use the addr2line tool to analyze the call stack.
3. Use the addr2line tool to analyze the call stack information.
Then, parse the line number based on the offset address.
```
root:~/OpenHarmony/out/hi3516dv300/exe.unstripped/hiviewdfx/faultloggerd$ addr2line -e crasher 000332c
root:~/OpenHarmony/out/hi3516dv300/exe.unstripped/hiviewdfx/faultloggerd$ addr2line -e crasher 0000332c
base/hiviewdfx/faultloggerd/tools/crasher/dfx_crasher.c:57
```
......
......@@ -28,8 +28,7 @@ Constraints on the event domain, event name, and parameter
- Zero or more event names can be defined for one event domain. The event names in the same event domain must be unique.
- Multiple parameters can be defined for one event name. The parameters in the same event name must be unique. There must be only one parameter named **__BASE** in each event name. See Table 1 for the fields of this parameter and Table 2 for the fields of other custom parameters.
- Multiple parameters can be defined for one event name. The parameters in the same event name must be unique. There must be only one parameter named **\__BASE** in each event name. See Table 1 for the fields of this parameter and Table 2 for the fields of other custom parameters.
**Table 1** Fields in the \__BASE parameter
| Field| Description|
......@@ -47,8 +46,10 @@ Constraints on the event domain, event name, and parameter
| arrsize | Length of the parameter of the array type. This field is optional.<br>Value:<br>1-100|
| desc | Parameter description. This field is mandatory.<br>Rule:<br>The description contains 3 to 128 characters, including a to z, A to Z, 0 to 9, and underscores (_).|
## How to Develop
### Writing a YAML File
......
# HiSysEvent Overview
# HiSysEvent
## Introduction
......
......@@ -2,530 +2,235 @@
## Overview
HiTraceChain tracks the call chain with the same **traceid** throughout the inter-device, inter-process, and inter-thread service processes. It associates and displays the call relationship and various output information during the entire process, helping you analyze and locate faults and optimize the system.
HiTraceChain tracks the call chain with the same **traceid** throughout the inter-device, inter-process, and inter-thread service processes. It associates and displays the call relationship and various output information during the entire process, helping you analyze and locate faults and optimize the system.
## Use Cases
## When to Use
HiTraceChain can be used for the following purposes:
- Associates and reports service process information \(such as logs and events\) on the device.
- Associates and reports service process information (such as logs and events) on the device.
- Displays and analyzes reported information on the cloud to facilitate fault location.
- Works with the IDE to debug the detailed service process and time consumption distribution for system optimization.
- Works with the IDE to debug the detailed service process and time consumption distribution for system optimization.
**Figure 1** Use cases of HiTraceChain
**Figure 1** Use cases of HiTraceChain
![](figures/use-cases-of-hitrace.png "use-cases-of-hitrace")
### Usage Example
**Figure 2** Service calling process \(inter-device and inter-process synchronous call\)
**Figure 2** Service calling process \(inter-device and inter-process synchronous call\)
![](figures/service-calling-process-(inter-device-and-inter-process-synchronous-call).png "service-calling-process-(inter-device-and-inter-process-synchronous-call)")
![](figures/service-calling-process-(inter-device-and-inter-process-synchronous-call).png "service-calling-process-(inter-device-and-inter-process-synchronous-call)")
1. Display the call relationship in the service process, analyze key paths and function dependency, and determine the time consumption and call frequency at each call point to detect performance bottlenecks.
**Figure 3** Service calling process
**Figure 3** Service calling process
![](figures/service-calling-process.png "service-calling-process")
![](figures/service-calling-process.png "service-calling-process")
**Figure 4** Time delay in the service calling process
**Figure 4** Time delay in the service calling process
![](figures/time-delay-in-the-service-calling-process.png "time-delay-in-the-service-calling-process")
![](figures/time-delay-in-the-service-calling-process.png "time-delay-in-the-service-calling-process")
2. Add **traceid** to logs and events automatically to facilitate comprehensive analysis and quick fault location.
2. Add **traceid** to logs and events automatically to facilitate comprehensive analysis and quick fault location.
## Available APIs
HiTraceChain provides C++ and C APIs. The upper-layer services mainly use HiTraceChain to start and stop call chain tracing.
HiTraceChain provides C++ and C APIs. The upper-layer services mainly use HiTraceChain to start and stop call chain trace.
HiTraceChain is implemented at layer C. It works by transferring **traceid** throughout the service calling process. Before service processing, HiTrace sets **traceid** in the thread local storage (TLS) of the calling thread. During service processing, HiTrace obtains **traceid** from the contextual TLS of the calling thread and automatically adds it to the log and event information. After service processing is complete, HiTrace clears **traceid** from the TLS of the calling thread.
HiTraceChain is implemented at layer C. It works by transferring **traceid** throughout the service calling process. Before service processing, HiTraceChain sets **traceid** in the thread local storage \(TLS\) of the calling thread. During service processing, HiTraceChain obtains **traceid** from the contextual TLS of the calling thread and automatically adds it to the log and event information. After service processing is complete, HiTraceChain clears **traceid** from the TLS of the calling thread.
### Java, C++, and C APIs
**Table 1** Description of C++ and C APIs
<a name="table0218014155811"></a>
<table><thead align="left"><tr id="row3218171455817"><th class="cellrowborder" valign="top" width="12.540000000000001%" id="mcps1.2.4.1.1">&nbsp;&nbsp;</th>
<th class="cellrowborder" valign="top" width="41.42%" id="mcps1.2.4.1.2"><p id="p17257112417232"><a name="p17257112417232"></a><a name="p17257112417232"></a><strong id="b7257324122319"><a name="b7257324122319"></a><a name="b7257324122319"></a>C++</strong></p>
</th>
<th class="cellrowborder" valign="top" width="46.04%" id="mcps1.2.4.1.3"><p id="p13218151413588"><a name="p13218151413588"></a><a name="p13218151413588"></a><strong id="b5218181416588"><a name="b5218181416588"></a><a name="b5218181416588"></a>C</strong></p>
</th>
</tr>
</thead>
<tbody><tr id="row1218714155816"><td class="cellrowborder" valign="top" width="12.540000000000001%" headers="mcps1.2.4.1.1 "><p id="p10218121475811"><a name="p10218121475811"></a><a name="p10218121475811"></a><strong id="b9680556"><a name="b9680556"></a><a name="b9680556"></a>Class</strong></p>
</td>
<td class="cellrowborder" valign="top" width="41.42%" headers="mcps1.2.4.1.2 "><p id="p112189146582"><a name="p112189146582"></a><a name="p112189146582"></a><strong id="b134318387"><a name="b134318387"></a><a name="b134318387"></a>API</strong></p>
</td>
<td class="cellrowborder" valign="top" width="46.04%" headers="mcps1.2.4.1.3 "><p id="p19219151413589"><a name="p19219151413589"></a><a name="p19219151413589"></a><strong id="b989888034"><a name="b989888034"></a><a name="b989888034"></a>API</strong></p>
</td>
</tr>
<tr id="row1219111415585"><td class="cellrowborder" rowspan="8" valign="top" width="12.540000000000001%" headers="mcps1.2.4.1.1 "><p id="p15219101455812"><a name="p15219101455812"></a><a name="p15219101455812"></a>HiTraceChain</p>
<p id="p1945616211310"><a name="p1945616211310"></a><a name="p1945616211310"></a></p>
<p id="p1645619231317"><a name="p1645619231317"></a><a name="p1645619231317"></a></p>
<p id="p94562024134"><a name="p94562024134"></a><a name="p94562024134"></a></p>
<p id="p745619221317"><a name="p745619221317"></a><a name="p745619221317"></a></p>
<p id="p184562212136"><a name="p184562212136"></a><a name="p184562212136"></a></p>
<p id="p2045613210139"><a name="p2045613210139"></a><a name="p2045613210139"></a></p>
<p id="p12456192161319"><a name="p12456192161319"></a><a name="p12456192161319"></a></p>
</td>
<td class="cellrowborder" valign="top" width="41.42%" headers="mcps1.2.4.1.2 "><p id="p821971495820"><a name="p821971495820"></a><a name="p821971495820"></a>HiTraceId Begin(const std::string&amp; name, int flags)</p>
</td>
<td class="cellrowborder" valign="top" width="46.04%" headers="mcps1.2.4.1.3 "><p id="p2219914195817"><a name="p2219914195817"></a><a name="p2219914195817"></a>HiTraceIdStruct HiTraceChainBegin(const char* name, int flags)</p>
</td>
</tr>
<tr id="row16219171417584"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p021971414588"><a name="p021971414588"></a><a name="p021971414588"></a>void End(const HiTraceId&amp; id)</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p16219191435814"><a name="p16219191435814"></a><a name="p16219191435814"></a>void HiTraceChainEnd(const HiTraceIdStruct* pId)</p>
</td>
</tr>
<tr id="row02191414115819"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p42191143585"><a name="p42191143585"></a><a name="p42191143585"></a>HiTraceId GetId();</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1221901419588"><a name="p1221901419588"></a><a name="p1221901419588"></a>HiTraceIdStruct HiTraceChainGetId()</p>
</td>
</tr>
<tr id="row11219131415582"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p6219111415812"><a name="p6219111415812"></a><a name="p6219111415812"></a>void SetId(const HiTraceId&amp; id)</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p221971465818"><a name="p221971465818"></a><a name="p221971465818"></a>void HiTraceChainSetId(const HiTraceIdStruct* pId)</p>
</td>
</tr>
<tr id="row162191814105815"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p12191147586"><a name="p12191147586"></a><a name="p12191147586"></a>void ClearId()</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p18219181445813"><a name="p18219181445813"></a><a name="p18219181445813"></a>void HiTraceChainClearId()</p>
</td>
</tr>
<tr id="row12219151475812"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1721981418580"><a name="p1721981418580"></a><a name="p1721981418580"></a>HiTraceId CreateSpan()</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1121981420584"><a name="p1121981420584"></a><a name="p1121981420584"></a>HiTraceIdStruct HiTraceChainCreateSpan()</p>
</td>
</tr>
<tr id="row1721911140582"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p18219514195814"><a name="p18219514195814"></a><a name="p18219514195814"></a>void Tracepoint(HiTraceTracepointType type, const HiTraceId&amp; id, const char* fmt, ...)</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p3219914175813"><a name="p3219914175813"></a><a name="p3219914175813"></a>void HiTraceChainTracepoint(HiTraceTracepointType type, const HiTraceIdStruct* pId, const char* fmt, ...)</p>
</td>
</tr>
<tr id="row521911410582"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p2219101415814"><a name="p2219101415814"></a><a name="p2219101415814"></a>void Tracepoint(HiTraceCommunicationMode mode, HiTraceTracepointType type, const HiTraceId&amp; id, const char* fmt, ...)</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p2220141413584"><a name="p2220141413584"></a><a name="p2220141413584"></a>void HiTraceChainTracepointEx(HiTraceCommunicationMode mode, HiTraceTracepointType type, const HiTraceIdStruct* pId, const char* fmt, ...)</p>
</td>
</tr>
<tr id="row8220181411586"><td class="cellrowborder" rowspan="14" valign="top" width="12.540000000000001%" headers="mcps1.2.4.1.1 "><p id="p522018149588"><a name="p522018149588"></a><a name="p522018149588"></a>HiTraceId</p>
<p id="p14704748133"><a name="p14704748133"></a><a name="p14704748133"></a></p>
<p id="p147041042134"><a name="p147041042134"></a><a name="p147041042134"></a></p>
<p id="p2070415431318"><a name="p2070415431318"></a><a name="p2070415431318"></a></p>
<p id="p870404101319"><a name="p870404101319"></a><a name="p870404101319"></a></p>
<p id="p27049417138"><a name="p27049417138"></a><a name="p27049417138"></a></p>
<p id="p870534121314"><a name="p870534121314"></a><a name="p870534121314"></a></p>
<p id="p370512420136"><a name="p370512420136"></a><a name="p370512420136"></a></p>
<p id="p197055481320"><a name="p197055481320"></a><a name="p197055481320"></a></p>
<p id="p970512471317"><a name="p970512471317"></a><a name="p970512471317"></a></p>
<p id="p1170554191318"><a name="p1170554191318"></a><a name="p1170554191318"></a></p>
<p id="p770564191312"><a name="p770564191312"></a><a name="p770564191312"></a></p>
<p id="p87057421315"><a name="p87057421315"></a><a name="p87057421315"></a></p>
<p id="p570518416139"><a name="p570518416139"></a><a name="p570518416139"></a></p>
</td>
<td class="cellrowborder" valign="top" width="41.42%" headers="mcps1.2.4.1.2 "><p id="p102201914105811"><a name="p102201914105811"></a><a name="p102201914105811"></a>HiTraceId();</p>
</td>
<td class="cellrowborder" valign="top" width="46.04%" headers="mcps1.2.4.1.3 "><p id="p16220161419581"><a name="p16220161419581"></a><a name="p16220161419581"></a>void HiTraceChainInitId(HiTraceIdStruct* pId)</p>
</td>
</tr>
<tr id="row8220191405817"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p162201314155813"><a name="p162201314155813"></a><a name="p162201314155813"></a>HiTraceId(const uint8_t* pIdArray, int len)</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p122011425814"><a name="p122011425814"></a><a name="p122011425814"></a>HiTraceIdStruct HiTraceChainBytesToId(const uint8_t* pIdArray, int len)</p>
</td>
</tr>
<tr id="row1522041435820"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1422012146587"><a name="p1422012146587"></a><a name="p1422012146587"></a>bool IsValid()</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1322016149586"><a name="p1322016149586"></a><a name="p1322016149586"></a>int HiTraceChainIsValid(const HiTraceIdStruct* pId)</p>
</td>
</tr>
<tr id="row8220714155810"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p322021485814"><a name="p322021485814"></a><a name="p322021485814"></a>bool IsFlagEnabled(HiTraceFlag flag)</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p922010148583"><a name="p922010148583"></a><a name="p922010148583"></a>int HiTraceChainIsFlagEnabled(const HiTraceIdStruct* pId, HiTraceFlag flag)</p>
</td>
</tr>
<tr id="row12220161485814"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1122011140588"><a name="p1122011140588"></a><a name="p1122011140588"></a>void EnableFlag(HiTraceFlag flag)</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p152201146583"><a name="p152201146583"></a><a name="p152201146583"></a>void HiTraceChainEnableFlag(HiTraceIdStruct* pId, HiTraceFlag flag)</p>
</td>
</tr>
<tr id="row922061411589"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p202208143588"><a name="p202208143588"></a><a name="p202208143588"></a>int GetFlags()</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p182206142587"><a name="p182206142587"></a><a name="p182206142587"></a>int HiTraceChainGetFlags(const HiTraceIdStruct* pId)</p>
</td>
</tr>
<tr id="row82204145589"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p12201414205815"><a name="p12201414205815"></a><a name="p12201414205815"></a>void SetFlags(int flags)</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p162201514175813"><a name="p162201514175813"></a><a name="p162201514175813"></a>void HiTraceChainSetFlags(HiTraceIdStruct* pId, int flags)</p>
</td>
</tr>
<tr id="row152204143585"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p722113147580"><a name="p722113147580"></a><a name="p722113147580"></a>uint64_t GetChainId()</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p322119149584"><a name="p322119149584"></a><a name="p322119149584"></a>uint64_t HiTraceChainGetChainId(const HiTraceIdStruct* pId)</p>
</td>
</tr>
<tr id="row1221214175815"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p922131445815"><a name="p922131445815"></a><a name="p922131445815"></a>void SetChainId(uint64_t chainId)</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p922101411588"><a name="p922101411588"></a><a name="p922101411588"></a>void HiTraceChainSetChainId(HiTraceIdStruct* pId, uint64_t chainId)</p>
</td>
</tr>
<tr id="row1922115142588"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1122141414588"><a name="p1122141414588"></a><a name="p1122141414588"></a>uint64_t GetSpanId()</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p32211145584"><a name="p32211145584"></a><a name="p32211145584"></a>uint64_t HiTraceChainGetSpanId(const HiTraceIdStruct* pId)</p>
</td>
</tr>
<tr id="row4221171414587"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p10221191412588"><a name="p10221191412588"></a><a name="p10221191412588"></a>void SetSpanId(uint64_t spanId)</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p42211614105810"><a name="p42211614105810"></a><a name="p42211614105810"></a>void HiTraceChainSetSpanId(HiTraceIdStruct* pId, uint64_t spanId)</p>
</td>
</tr>
<tr id="row322171425818"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1722111418582"><a name="p1722111418582"></a><a name="p1722111418582"></a>uint64_t GetParentSpanId()</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p8221314195817"><a name="p8221314195817"></a><a name="p8221314195817"></a>uint64_t HiTraceChainGetParentSpanId(const HiTraceIdStruct* pId)</p>
</td>
</tr>
<tr id="row622114147589"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p92219145589"><a name="p92219145589"></a><a name="p92219145589"></a>void SetParentSpanId(uint64_t parentSpanId)</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p922191435813"><a name="p922191435813"></a><a name="p922191435813"></a>void HiTraceChainSetParentSpanId(HiTraceIdStruct* pId, uint64_t parentSpanId)</p>
</td>
</tr>
<tr id="row5221614135814"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p11221121435820"><a name="p11221121435820"></a><a name="p11221121435820"></a>int ToBytes(uint8_t* pIdArray, int len)</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1122131415814"><a name="p1122131415814"></a><a name="p1122131415814"></a>int HiTraceChainIdToBytes(const HiTraceIdStruct* pId, uint8_t* pIdArray, int len)</p>
</td>
</tr>
</tbody>
</table>
**Table 1** Description of C++ and C APIs
| | **C++** | **C** |
| -------- | -------- | -------- |
| **Class**| **Function**| **Function**|
| HiTraceChain | HiTraceId Begin(const std::string&amp; name, int flags) | HiTraceIdStruct HiTraceChainBegin(const char* name, int flags) |
| | void End(const HiTraceId&amp; id) | void HiTraceChainEnd(const HiTraceIdStruct* pId) |
| | HiTraceId GetId(); | HiTraceIdStruct HiTraceChainGetId() |
| | void SetId(const HiTraceId&amp; id) | void HiTraceChainSetId(const HiTraceIdStruct* pId) |
| | void ClearId() | void HiTraceChainClearId() |
| | HiTraceId CreateSpan() | HiTraceIdStruct HiTraceChainCreateSpan() |
| | void Tracepoint(HiTraceTracepointType type, const HiTraceId&amp; id, const char* fmt, ...) | void HiTraceChainTracepoint(HiTraceTracepointType type, const HiTraceIdStruct* pId, const char* fmt, ...) |
| | void Tracepoint(HiTraceCommunicationMode mode, HiTraceTracepointType type, const HiTraceId&amp; id, const char* fmt, ...) | void HiTraceChainTracepointEx(HiTraceCommunicationMode mode, HiTraceTracepointType type, const HiTraceIdStruct* pId, const char* fmt, ...) |
| HiTraceId | HiTraceId(); | void HiTraceChainInitId(HiTraceIdStruct* pId) |
| | HiTraceId(const uint8_t* pIdArray, int len) | HiTraceIdStruct HiTraceChainBytesToId(const uint8_t* pIdArray, int len) |
| | bool IsValid() | int HiTraceChainIsValid(const HiTraceIdStruct* pId) |
| | bool IsFlagEnabled(HiTraceFlag flag) | int HiTraceChainIsFlagEnabled(const HiTraceIdStruct* pId, HiTraceFlag flag) |
| | void EnableFlag(HiTraceFlag flag) | void HiTraceChainEnableFlag(HiTraceIdStruct* pId, HiTraceFlag flag) |
| | int GetFlags() | int HiTraceChainGetFlags(const HiTraceIdStruct* pId) |
| | void SetFlags(int flags) | void HiTraceChainSetFlags(HiTraceIdStruct* pId, int flags) |
| | uint64_t GetChainId() | uint64_t HiTraceChainGetChainId(const HiTraceIdStruct* pId) |
| | void SetChainId(uint64_t chainId) | void HiTraceChainSetChainId(HiTraceIdStruct* pId, uint64_t chainId) |
| | uint64_t GetSpanId() | uint64_t HiTraceChainGetSpanId(const HiTraceIdStruct* pId) |
| | void SetSpanId(uint64_t spanId) | void HiTraceChainSetSpanId(HiTraceIdStruct* pId, uint64_t spanId) |
| | uint64_t GetParentSpanId() | uint64_t HiTraceChainGetParentSpanId(const HiTraceIdStruct* pId) |
| | void SetParentSpanId(uint64_t parentSpanId) | void HiTraceChainSetParentSpanId(HiTraceIdStruct* pId, uint64_t parentSpanId) |
| | int ToBytes(uint8_t* pIdArray, int len) | int HiTraceChainIdToBytes(const HiTraceIdStruct_ pId, uint8_t* pIdArray, int len) |
### Parameters of C++ APIs
**Table 2** Parameters of C++ APIs
<a name="table19597131833715"></a>
<table><thead align="left"><tr id="row7839141817375"><th class="cellrowborder" valign="top" width="9.8%" id="mcps1.2.4.1.1"><p id="p383919182379"><a name="p383919182379"></a><a name="p383919182379"></a><strong id="b18963437162313"><a name="b18963437162313"></a><a name="b18963437162313"></a>Class</strong></p>
</th>
<th class="cellrowborder" valign="top" width="31.430000000000003%" id="mcps1.2.4.1.2"><p id="p168392018203711"><a name="p168392018203711"></a><a name="p168392018203711"></a><strong id="b1368417396233"><a name="b1368417396233"></a><a name="b1368417396233"></a>API</strong></p>
</th>
<th class="cellrowborder" valign="top" width="58.77%" id="mcps1.2.4.1.3"><p id="p168391618193717"><a name="p168391618193717"></a><a name="p168391618193717"></a><strong id="b1137714428236"><a name="b1137714428236"></a><a name="b1137714428236"></a>Description</strong></p>
</th>
</tr>
</thead>
<tbody><tr id="row383911183378"><td class="cellrowborder" rowspan="8" valign="top" width="9.8%" headers="mcps1.2.4.1.1 "><p id="p10839318133713"><a name="p10839318133713"></a><a name="p10839318133713"></a>HiTraceChain</p>
<p id="p1544019164131"><a name="p1544019164131"></a><a name="p1544019164131"></a></p>
<p id="p14440191615134"><a name="p14440191615134"></a><a name="p14440191615134"></a></p>
<p id="p6440161631310"><a name="p6440161631310"></a><a name="p6440161631310"></a></p>
<p id="p174411167135"><a name="p174411167135"></a><a name="p174411167135"></a></p>
<p id="p2441141651310"><a name="p2441141651310"></a><a name="p2441141651310"></a></p>
<p id="p1944151618133"><a name="p1944151618133"></a><a name="p1944151618133"></a></p>
<p id="p1744121610131"><a name="p1744121610131"></a><a name="p1744121610131"></a></p>
</td>
<td class="cellrowborder" valign="top" width="31.430000000000003%" headers="mcps1.2.4.1.2 "><p id="p198391118193717"><a name="p198391118193717"></a><a name="p198391118193717"></a>HiTraceId Begin(const std::string&amp; name, int flags)</p>
</td>
<td class="cellrowborder" valign="top" width="58.77%" headers="mcps1.2.4.1.3 "><p id="p684013182375"><a name="p684013182375"></a><a name="p684013182375"></a>Starts HiTraceChain, generates a <strong id="b2063619462230"><a name="b2063619462230"></a><a name="b2063619462230"></a>HiTraceId</strong> object, and sets it in the TLS of the calling thread.</p>
<p id="p1384081812377"><a name="p1384081812377"></a><a name="p1384081812377"></a>Input arguments:</p>
<a name="ul1537854218177"></a><a name="ul1537854218177"></a><ul id="ul1537854218177"><li><strong id="b1566312131676"><a name="b1566312131676"></a><a name="b1566312131676"></a>name</strong>: Indicates the name of the service process.</li><li><strong id="b75512128711"><a name="b75512128711"></a><a name="b75512128711"></a>flags</strong>: Indicates tracing flags, which can be used in combination. <a name="ul18842248101915"></a><a name="ul18842248101915"></a><ul id="ul18842248101915"><li>HITRACE_FLAG_INCLUDE_ASYNC: Traces both synchronous and asynchronous calls. By default, only synchronous calls are traced.</li><li><strong id="b724616241477"><a name="b724616241477"></a><a name="b724616241477"></a>HITRACE_FLAG_DONOT_CREATE_SPAN</strong>: Do not create a span. By default, a span is created.</li><li><strong id="b136181926479"><a name="b136181926479"></a><a name="b136181926479"></a>HITRACE_FLAG_TP_INFO</strong>: Outputs the tracepoint information. By default, the information is not output.</li><li><strong id="b358818291777"><a name="b358818291777"></a><a name="b358818291777"></a>HITRACE_FLAG_NO_BE_INFO</strong>: Do not output the start and end information. By default, the information is output.</li><li><strong id="b38571331974"><a name="b38571331974"></a><a name="b38571331974"></a>HITRACE_FLAG_DONOT_ENABLE_LOG</strong>: Do not associate logs for output. By default, logs are associated for output.</li><li><strong id="b17320371870"><a name="b17320371870"></a><a name="b17320371870"></a>HITRACE_FLAG_FAULT_TRIGGER</strong>: Triggers tracing by fault. By default, tracing is triggered normally.</li><li><strong id="b876915381711"><a name="b876915381711"></a><a name="b876915381711"></a>HITRACE_FLAG_D2D_TP_INFO</strong>: Outputs the device-to-device tracepoint information. By default, the information is not output.</li><li><strong id="b66510421776"><a name="b66510421776"></a><a name="b66510421776"></a>HITRCE_FLAG_DEFAULT</strong>: Indicates the default flag.</li></ul>
</li><li>Output arguments: none</li><li>Return value: Returns a valid <strong id="b7411101522917"><a name="b7411101522917"></a><a name="b7411101522917"></a>HiTraceId</strong> object if call chain tracing is triggered successfully; returns an invalid object otherwise.</li></ul>
<p id="p188401918203713"><a name="p188401918203713"></a><a name="p188401918203713"></a>Note: In nested tracing mode, an invalid object will be returned if tracing is started at the nested layer.</p>
</td>
</tr>
<tr id="row16840101803720"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p13840191893718"><a name="p13840191893718"></a><a name="p13840191893718"></a>void End(const HiTraceId&amp; id)</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p3840181820372"><a name="p3840181820372"></a><a name="p3840181820372"></a>Stops HiTraceChain based on the <strong id="b1605239122415"><a name="b1605239122415"></a><a name="b1605239122415"></a>HiTraceId</strong> object returned by the <strong id="b7610183992419"><a name="b7610183992419"></a><a name="b7610183992419"></a>Begin</strong> API, and clears the <strong id="b1610173918241"><a name="b1610173918241"></a><a name="b1610173918241"></a>HiTraceId</strong> object in the TLS of the calling thread.</p>
<p id="p9840718103720"><a name="p9840718103720"></a><a name="p9840718103720"></a>Input arguments:</p>
<a name="ul2917140133015"></a><a name="ul2917140133015"></a><ul id="ul2917140133015"><li><strong id="b8201185118711"><a name="b8201185118711"></a><a name="b8201185118711"></a>id</strong>: Indicates the <strong id="b2071183114331"><a name="b2071183114331"></a><a name="b2071183114331"></a>HiTraceId</strong> object.</li></ul>
<p id="p14840151803718"><a name="p14840151803718"></a><a name="p14840151803718"></a>Output arguments: none</p>
<p id="p2840201893719"><a name="p2840201893719"></a><a name="p2840201893719"></a>Return value: none</p>
</td>
</tr>
<tr id="row198401818193712"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p20840191893718"><a name="p20840191893718"></a><a name="p20840191893718"></a>HiTraceId GetId();</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p98401818123720"><a name="p98401818123720"></a><a name="p98401818123720"></a>Obtains the <strong id="b98371719256"><a name="b98371719256"></a><a name="b98371719256"></a>HiTraceId</strong> object from the TLS of the calling thread.</p>
<p id="p984001893712"><a name="p984001893712"></a><a name="p984001893712"></a>Input arguments: none</p>
<p id="p2084021817379"><a name="p2084021817379"></a><a name="p2084021817379"></a>Output arguments: none</p>
<p id="p9840418133716"><a name="p9840418133716"></a><a name="p9840418133716"></a>Return value: Returns the <strong id="b73911122162613"><a name="b73911122162613"></a><a name="b73911122162613"></a>HiTraceId</strong> object in the contextual TLS of the calling thread.</p>
</td>
</tr>
<tr id="row118401118203714"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1840151843715"><a name="p1840151843715"></a><a name="p1840151843715"></a>void SetId(const HiTraceId&amp; id)</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p384061893715"><a name="p384061893715"></a><a name="p384061893715"></a>Purpose: Sets the <strong id="b7405852152614"><a name="b7405852152614"></a><a name="b7405852152614"></a>HiTraceId</strong> object in the TLS of the calling thread.</p>
<p id="p16840718153717"><a name="p16840718153717"></a><a name="p16840718153717"></a>Input arguments:</p>
<a name="ul1355016467304"></a><a name="ul1355016467304"></a><ul id="ul1355016467304"><li><strong id="b648307174"><a name="b648307174"></a><a name="b648307174"></a>id</strong>: Indicates the <strong id="b492669584"><a name="b492669584"></a><a name="b492669584"></a>HiTraceId</strong> object.</li></ul>
<p id="p684051817376"><a name="p684051817376"></a><a name="p684051817376"></a>Output arguments: none</p>
<p id="p884091812374"><a name="p884091812374"></a><a name="p884091812374"></a>Return value: none</p>
</td>
</tr>
<tr id="row3840171813374"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p18840131873717"><a name="p18840131873717"></a><a name="p18840131873717"></a>void ClearId()</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p584019184379"><a name="p584019184379"></a><a name="p584019184379"></a>Clears the <strong id="b8445182151511"><a name="b8445182151511"></a><a name="b8445182151511"></a>HiTraceId</strong> object in the TLS of the current thread.</p>
<p id="p108401718173714"><a name="p108401718173714"></a><a name="p108401718173714"></a>Input arguments: none </p>
<p id="p1784014183377"><a name="p1784014183377"></a><a name="p1784014183377"></a>Output arguments: none</p>
<p id="p2084041811377"><a name="p2084041811377"></a><a name="p2084041811377"></a>Return value: none</p>
</td>
</tr>
<tr id="row6840818193716"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p16840171823719"><a name="p16840171823719"></a><a name="p16840171823719"></a>HiTraceId CreateSpan()</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p984031812378"><a name="p984031812378"></a><a name="p984031812378"></a>Obtains the span ID from the current <strong id="b186741420142718"><a name="b186741420142718"></a><a name="b186741420142718"></a>HiTraceId</strong> object.</p>
<p id="p5840101814371"><a name="p5840101814371"></a><a name="p5840101814371"></a>Input arguments: none</p>
<p id="p20840111843718"><a name="p20840111843718"></a><a name="p20840111843718"></a>Output arguments: none</p>
<p id="p88401218193710"><a name="p88401218193710"></a><a name="p88401218193710"></a>Return value: Returns the current span ID.</p>
</td>
</tr>
<tr id="row198401118123714"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p178411618183711"><a name="p178411618183711"></a><a name="p178411618183711"></a>void Tracepoint(HiTraceTracepointType type, const HiTraceId&amp; id, const char* fmt, ...)</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p88419184373"><a name="p88419184373"></a><a name="p88419184373"></a>Outputs HiTraceChain call chain information based on the information type. The information includes the timestamp and <strong id="b185817437323"><a name="b185817437323"></a><a name="b185817437323"></a>HiTraceId</strong> object information of the span.</p>
<p id="p1984116184376"><a name="p1984116184376"></a><a name="p1984116184376"></a>Input arguments:</p>
<a name="ul18619103153812"></a><a name="ul18619103153812"></a><ul id="ul18619103153812"><li><strong id="b7818831083"><a name="b7818831083"></a><a name="b7818831083"></a>type</strong>: Indicates the information type. The options are as follows:<a name="ul1941510328297"></a><a name="ul1941510328297"></a><ul id="ul1941510328297"><li><strong id="b18809161180"><a name="b18809161180"></a><a name="b18809161180"></a>HITRACE_TP_CS</strong>: Client Send, which indicates the messages sent by the synchronous/asynchronous communication client.</li><li><strong id="b327281271319"><a name="b327281271319"></a><a name="b327281271319"></a>HITRACE_TP_SR</strong>: Server Receive, which indicates the messages received by the server in synchronous/asynchronous communication.</li><li><strong id="b10154742682"><a name="b10154742682"></a><a name="b10154742682"></a>HITRACE_TP_SS</strong>: Server Send, which indicates the response messages sent by the server in synchronous communication.</li><li><strong id="b152598127810"><a name="b152598127810"></a><a name="b152598127810"></a>HITRACE_TP_CR</strong>: Client Receive, which indicates the response messages received by the synchronous communication client.</li><li><strong id="b82631512817"><a name="b82631512817"></a><a name="b82631512817"></a>HITRACE_TP_GENERAL</strong>: Indicates the common output information.</li></ul>
</li><li><strong id="b117401716584"><a name="b117401716584"></a><a name="b117401716584"></a>id</strong>: Indicates the ID of the current span.</li><li><strong id="b392172019813"><a name="b392172019813"></a><a name="b392172019813"></a>fmt</strong>: Indicates the string describing the format variable parameter.</li><li><strong id="b986771717818"><a name="b986771717818"></a><a name="b986771717818"></a>args</strong>: Indicates the variable parameter.</li></ul>
<p id="p11841121863717"><a name="p11841121863717"></a><a name="p11841121863717"></a>Output arguments: none</p>
<p id="p16841161816376"><a name="p16841161816376"></a><a name="p16841161816376"></a>Return value: none</p>
</td>
</tr>
<tr id="row11841191811379"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p08411318163716"><a name="p08411318163716"></a><a name="p08411318163716"></a>void Tracepoint(HiTraceCommunicationMode mode, HiTraceTracepointType type, const HiTraceId&amp; id, const char* fmt, ...)</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p68411618153713"><a name="p68411618153713"></a><a name="p68411618153713"></a>Outputs HiTraceChain call chain information based on the communication mode and information type. The information includes the timestamp and <strong id="b8151210123912"><a name="b8151210123912"></a><a name="b8151210123912"></a>HiTraceId</strong> object information of the span.</p>
<p id="p98418189375"><a name="p98418189375"></a><a name="p98418189375"></a>Input arguments:</p>
<a name="ul914264413811"></a><a name="ul914264413811"></a><ul id="ul914264413811"><li><strong id="b76471824183"><a name="b76471824183"></a><a name="b76471824183"></a>mode</strong>: Indicates the communication mode. The options are as follows:<a name="ul137382469451"></a><a name="ul137382469451"></a><ul id="ul137382469451"><li><strong id="b13732297812"><a name="b13732297812"></a><a name="b13732297812"></a>HITRACE_CM_DEFAULT</strong>: default communication mode used when no communication mode is specified</li><li><strong id="b1820115271789"><a name="b1820115271789"></a><a name="b1820115271789"></a>HITRACE_CM_THREAD</strong>: inter-thread communication</li><li><strong id="b27781831488"><a name="b27781831488"></a><a name="b27781831488"></a>HITRACE_CM_PROCESS</strong>: inter-process communication</li><li><strong id="b15657113313819"><a name="b15657113313819"></a><a name="b15657113313819"></a>HITRACE_CM_DEVICE</strong>: inter-device communication</li></ul>
</li><li><strong id="b172723513812"><a name="b172723513812"></a><a name="b172723513812"></a>type</strong>: Indicates the information type. The options are as follows:<a name="ul19648426458"></a><a name="ul19648426458"></a><ul id="ul19648426458"><li><strong id="b26421037382"><a name="b26421037382"></a><a name="b26421037382"></a>HITRACE_TP_CS</strong>: Client Send, which indicates the messages sent by the synchronous/asynchronous communication client.</li><li><strong id="b66504018818"><a name="b66504018818"></a><a name="b66504018818"></a>HITRACE_TP_SR</strong>: Server Receive, which indicates the messages received by the server in synchronous/asynchronous communication.</li><li><strong id="b285283761"><a name="b285283761"></a><a name="b285283761"></a>HITRACE_TP_SS</strong>: Server Send, which indicates the response messages sent by the server in synchronous communication.</li><li><strong id="b148684447814"><a name="b148684447814"></a><a name="b148684447814"></a>HITRACE_TP_CR</strong>: Client Receive, which indicates the response messages received by the synchronous communication client.</li><li><strong id="b17875164618816"><a name="b17875164618816"></a><a name="b17875164618816"></a>HITRACE_TP_GENERAL</strong>: Indicates the common output information.</li></ul>
</li><li><strong id="b1216749882"><a name="b1216749882"></a><a name="b1216749882"></a>id</strong>: Indicates the ID of the current span.</li><li><strong id="b82757501383"><a name="b82757501383"></a><a name="b82757501383"></a>fmt</strong>: Indicates the string describing the format variable parameter.</li><li><strong id="b15518145114817"><a name="b15518145114817"></a><a name="b15518145114817"></a>args</strong>: Indicates the variable parameter.</li></ul>
<p id="p784111810377"><a name="p784111810377"></a><a name="p784111810377"></a>Output arguments: none</p>
<p id="p1984181810374"><a name="p1984181810374"></a><a name="p1984181810374"></a>Return value: none</p>
</td>
</tr>
<tr id="row15841191813371"><td class="cellrowborder" rowspan="14" valign="top" width="9.8%" headers="mcps1.2.4.1.1 "><p id="p28411718143712"><a name="p28411718143712"></a><a name="p28411718143712"></a>HiTraceId</p>
<p id="p8337626151312"><a name="p8337626151312"></a><a name="p8337626151312"></a></p>
<p id="p16337182615134"><a name="p16337182615134"></a><a name="p16337182615134"></a></p>
<p id="p333712613136"><a name="p333712613136"></a><a name="p333712613136"></a></p>
<p id="p1337192616133"><a name="p1337192616133"></a><a name="p1337192616133"></a></p>
<p id="p203373267134"><a name="p203373267134"></a><a name="p203373267134"></a></p>
<p id="p23371265134"><a name="p23371265134"></a><a name="p23371265134"></a></p>
<p id="p173372267139"><a name="p173372267139"></a><a name="p173372267139"></a></p>
<p id="p143377266138"><a name="p143377266138"></a><a name="p143377266138"></a></p>
<p id="p13374265133"><a name="p13374265133"></a><a name="p13374265133"></a></p>
<p id="p18337162610137"><a name="p18337162610137"></a><a name="p18337162610137"></a></p>
<p id="p1833742613131"><a name="p1833742613131"></a><a name="p1833742613131"></a></p>
<p id="p93371026101319"><a name="p93371026101319"></a><a name="p93371026101319"></a></p>
<p id="p13337426121311"><a name="p13337426121311"></a><a name="p13337426121311"></a></p>
</td>
<td class="cellrowborder" valign="top" width="31.430000000000003%" headers="mcps1.2.4.1.2 "><p id="p158414182379"><a name="p158414182379"></a><a name="p158414182379"></a>HiTraceId();</p>
</td>
<td class="cellrowborder" valign="top" width="58.77%" headers="mcps1.2.4.1.3 "><p id="p48419181372"><a name="p48419181372"></a><a name="p48419181372"></a>Represents the default constructor used to generate an invalid <strong id="b1235325844115"><a name="b1235325844115"></a><a name="b1235325844115"></a>HiTraceId</strong> object. </p>
<p id="p16841121815372"><a name="p16841121815372"></a><a name="p16841121815372"></a>Input arguments: none</p>
<p id="p17841161803713"><a name="p17841161803713"></a><a name="p17841161803713"></a>Output arguments: none</p>
<p id="p1884121818375"><a name="p1884121818375"></a><a name="p1884121818375"></a>Return value: none</p>
</td>
</tr>
<tr id="row138418186374"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p19841111813712"><a name="p19841111813712"></a><a name="p19841111813712"></a>HiTraceId(const uint8_t* pIdArray, int len)</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p684110183377"><a name="p684110183377"></a><a name="p684110183377"></a>Represents the constructor used to create a <strong id="b1488144194216"><a name="b1488144194216"></a><a name="b1488144194216"></a>HiTraceId</strong> object based on the specified byte array. </p>
<div class="p" id="p9841151833711"><a name="p9841151833711"></a><a name="p9841151833711"></a>Input arguments:<a name="ul783818256482"></a><a name="ul783818256482"></a><ul id="ul783818256482"><li><strong id="b1725445715818"><a name="b1725445715818"></a><a name="b1725445715818"></a>pIdArray</strong>: Indicates the pointer to a byte array.</li><li><strong id="b3437458486"><a name="b3437458486"></a><a name="b3437458486"></a>len</strong>: Indicates the length of the byte array.</li></ul>
</div>
<p id="p484121893716"><a name="p484121893716"></a><a name="p484121893716"></a>Output arguments: none</p>
<p id="p984161813376"><a name="p984161813376"></a><a name="p984161813376"></a>Return value: none</p>
</td>
</tr>
<tr id="row2084112189377"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1184271814377"><a name="p1184271814377"></a><a name="p1184271814377"></a>bool IsValid()</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1084251893713"><a name="p1084251893713"></a><a name="p1084251893713"></a>Checks whether the <strong id="b18546440145116"><a name="b18546440145116"></a><a name="b18546440145116"></a>HiTraceId</strong> object is valid.</p>
<p id="p1084231815374"><a name="p1084231815374"></a><a name="p1084231815374"></a>Input arguments: none</p>
<p id="p15842121815376"><a name="p15842121815376"></a><a name="p15842121815376"></a>Output arguments: none</p>
<p id="p884261893710"><a name="p884261893710"></a><a name="p884261893710"></a>Return value: Returns <strong id="b20386195514314"><a name="b20386195514314"></a><a name="b20386195514314"></a>true</strong> if the <strong id="b1899544174516"><a name="b1899544174516"></a><a name="b1899544174516"></a>HiTraceId</strong> object is valid; returns <strong id="b1273655294313"><a name="b1273655294313"></a><a name="b1273655294313"></a>false</strong> otherwise.</p>
</td>
</tr>
<tr id="row7842161873716"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p88422188379"><a name="p88422188379"></a><a name="p88422188379"></a>bool IsFlagEnabled(HiTraceFlag flag)</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p128421518153712"><a name="p128421518153712"></a><a name="p128421518153712"></a>Checks whether the tracing flag of the <strong id="b1014619442447"><a name="b1014619442447"></a><a name="b1014619442447"></a>HiTraceId</strong> object is enabled.</p>
<p id="p12842518113714"><a name="p12842518113714"></a><a name="p12842518113714"></a>Input arguments:</p>
<a name="ul9760031103115"></a><a name="ul9760031103115"></a><ul id="ul9760031103115"><li><strong id="b136731441791"><a name="b136731441791"></a><a name="b136731441791"></a>flag</strong>: Indicates the tracing flag. For details, see the description in the <strong id="b186672319452"><a name="b186672319452"></a><a name="b186672319452"></a>Begin</strong> function.</li></ul>
<p id="p784217189379"><a name="p784217189379"></a><a name="p784217189379"></a>Output arguments: none</p>
<p id="p98421318143720"><a name="p98421318143720"></a><a name="p98421318143720"></a>Return value: Returns <strong id="b151944819455"><a name="b151944819455"></a><a name="b151944819455"></a>true</strong> if the tracing flag is enabled; returns <strong id="b1619204874513"><a name="b1619204874513"></a><a name="b1619204874513"></a>false</strong> otherwise.</p>
</td>
</tr>
<tr id="row4842318123713"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p8842818103712"><a name="p8842818103712"></a><a name="p8842818103712"></a>void EnableFlag(HiTraceFlag flag)</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1084221893717"><a name="p1084221893717"></a><a name="p1084221893717"></a>Enables the tracing flag of the <strong id="b118041135213"><a name="b118041135213"></a><a name="b118041135213"></a>HiTraceId</strong> object.</p>
<p id="p484241853710"><a name="p484241853710"></a><a name="p484241853710"></a>Input arguments:</p>
<a name="ul144862816319"></a><a name="ul144862816319"></a><ul id="ul144862816319"><li><strong id="b430319434"><a name="b430319434"></a><a name="b430319434"></a>flag</strong>: Indicates the tracing flag. For details, see the description in the <strong id="b1067701187"><a name="b1067701187"></a><a name="b1067701187"></a>Begin</strong> function.</li></ul>
<p id="p18421018153710"><a name="p18421018153710"></a><a name="p18421018153710"></a>Output arguments: none</p>
<p id="p138421618163715"><a name="p138421618163715"></a><a name="p138421618163715"></a>Return value: none</p>
</td>
</tr>
<tr id="row128421918153717"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p4842218193714"><a name="p4842218193714"></a><a name="p4842218193714"></a>int GetFlags()</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p12842151803718"><a name="p12842151803718"></a><a name="p12842151803718"></a>Obtains the tracing flag set in the <strong id="b36515674811"><a name="b36515674811"></a><a name="b36515674811"></a>HiTraceId</strong> object.</p>
<p id="p108421018193716"><a name="p108421018193716"></a><a name="p108421018193716"></a>Input arguments: none</p>
<p id="p284271843715"><a name="p284271843715"></a><a name="p284271843715"></a>Output arguments: none</p>
<p id="p19842101853716"><a name="p19842101853716"></a><a name="p19842101853716"></a>Return value: Returns the combination of tracing flags. For details, see the description in the <strong id="b12693139144817"><a name="b12693139144817"></a><a name="b12693139144817"></a>Begin</strong> function.</p>
</td>
</tr>
<tr id="row18842181863712"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p13842718153717"><a name="p13842718153717"></a><a name="p13842718153717"></a>void SetFlags(int flags)</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p7842141823718"><a name="p7842141823718"></a><a name="p7842141823718"></a>Sets a tracing flag in the <strong id="b9174314814"><a name="b9174314814"></a><a name="b9174314814"></a>HiTraceId</strong> object.</p>
<p id="p784214187374"><a name="p784214187374"></a><a name="p784214187374"></a>Input arguments:</p>
<a name="ul6490121183115"></a><a name="ul6490121183115"></a><ul id="ul6490121183115"><li><strong id="b1556719154919"><a name="b1556719154919"></a><a name="b1556719154919"></a>flags</strong>: Indicates the combination of tracing flags. For details, see the description in the <strong id="b469312329341"><a name="b469312329341"></a><a name="b469312329341"></a>Begin</strong> function.</li></ul>
<p id="p17842141833710"><a name="p17842141833710"></a><a name="p17842141833710"></a>Output arguments: none</p>
<p id="p1842718203716"><a name="p1842718203716"></a><a name="p1842718203716"></a>Return value: none</p>
</td>
</tr>
<tr id="row68421418163715"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p484221810371"><a name="p484221810371"></a><a name="p484221810371"></a>uint64_t GetChainId()</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1784231833713"><a name="p1784231833713"></a><a name="p1784231833713"></a>Obtains the call chain ID.</p>
<p id="p48428188373"><a name="p48428188373"></a><a name="p48428188373"></a>Input arguments: none</p>
<p id="p158421418163710"><a name="p158421418163710"></a><a name="p158421418163710"></a>Output arguments: none</p>
<p id="p1484217183376"><a name="p1484217183376"></a><a name="p1484217183376"></a>Return value: Returns the call chain ID.</p>
</td>
</tr>
<tr id="row2842818153719"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p158422182376"><a name="p158422182376"></a><a name="p158422182376"></a>void SetChainId(uint64_t chainId)</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p784271815372"><a name="p784271815372"></a><a name="p784271815372"></a>Sets the call chain ID in the <strong id="b1319041125416"><a name="b1319041125416"></a><a name="b1319041125416"></a>HiTraceId</strong> object.</p>
<p id="p3842131883718"><a name="p3842131883718"></a><a name="p3842131883718"></a>Input arguments:</p>
<a name="ul45791717103118"></a><a name="ul45791717103118"></a><ul id="ul45791717103118"><li><strong id="b492411164116"><a name="b492411164116"></a><a name="b492411164116"></a>chainId</strong>: Indicates the call chain ID.</li></ul>
<p id="p9842171818371"><a name="p9842171818371"></a><a name="p9842171818371"></a>Output arguments: none</p>
<p id="p2842141853718"><a name="p2842141853718"></a><a name="p2842141853718"></a>Return value: none</p>
</td>
</tr>
<tr id="row1484217185372"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p12843161817378"><a name="p12843161817378"></a><a name="p12843161817378"></a>uint64_t GetSpanId()</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1484351820374"><a name="p1484351820374"></a><a name="p1484351820374"></a>Obtains the span ID from the current <strong id="b8123101515516"><a name="b8123101515516"></a><a name="b8123101515516"></a>HiTraceId</strong> object.</p>
<p id="p584391823715"><a name="p584391823715"></a><a name="p584391823715"></a>Input arguments: none</p>
<p id="p198431418153714"><a name="p198431418153714"></a><a name="p198431418153714"></a>Output arguments: none</p>
<p id="p19843161833719"><a name="p19843161833719"></a><a name="p19843161833719"></a>Return value: Returns the current span ID.</p>
</td>
</tr>
<tr id="row48438182378"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p184361810373"><a name="p184361810373"></a><a name="p184361810373"></a>void SetSpanId(uint64_t spanId)</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p14843171816375"><a name="p14843171816375"></a><a name="p14843171816375"></a>Sets the span ID in the <strong id="b13643024185512"><a name="b13643024185512"></a><a name="b13643024185512"></a>HiTraceId</strong> object.</p>
<p id="p1684381811375"><a name="p1684381811375"></a><a name="p1684381811375"></a>Input arguments:</p>
<a name="ul1799516134316"></a><a name="ul1799516134316"></a><ul id="ul1799516134316"><li><strong id="b43891187116"><a name="b43891187116"></a><a name="b43891187116"></a>spanId</strong>: Indicates the span ID.</li></ul>
<p id="p6843181820372"><a name="p6843181820372"></a><a name="p6843181820372"></a>Output arguments: none</p>
<p id="p8843518113714"><a name="p8843518113714"></a><a name="p8843518113714"></a>Return value: none</p>
</td>
</tr>
<tr id="row178435181375"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p10843141816371"><a name="p10843141816371"></a><a name="p10843141816371"></a>uint64_t GetParentSpanId()</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p884381819373"><a name="p884381819373"></a><a name="p884381819373"></a>Obtains the parent span ID from the current <strong id="b5851839615"><a name="b5851839615"></a><a name="b5851839615"></a>HiTraceId</strong> object.</p>
<p id="p1684321812371"><a name="p1684321812371"></a><a name="p1684321812371"></a>Input arguments: none</p>
<p id="p8843131803711"><a name="p8843131803711"></a><a name="p8843131803711"></a>Output arguments: none</p>
<p id="p1584371833710"><a name="p1584371833710"></a><a name="p1584371833710"></a>Return value: Returns the parent span ID.</p>
</td>
</tr>
<tr id="row18843161893718"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p6843151819377"><a name="p6843151819377"></a><a name="p6843151819377"></a>void SetParentSpanId(uint64_t parentSpanId)</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1884361803719"><a name="p1884361803719"></a><a name="p1884361803719"></a>Sets the parent span ID in the <strong id="b1660960324"><a name="b1660960324"></a><a name="b1660960324"></a>HiTraceId</strong> object.</p>
<p id="p0843318113715"><a name="p0843318113715"></a><a name="p0843318113715"></a>Input arguments:</p>
<a name="ul1393128173120"></a><a name="ul1393128173120"></a><ul id="ul1393128173120"><li><strong id="b1923980171114"><a name="b1923980171114"></a><a name="b1923980171114"></a>parentSpanId</strong>: Indicates the parent span ID.</li></ul>
<p id="p138431518153712"><a name="p138431518153712"></a><a name="p138431518153712"></a>Output arguments: none</p>
<p id="p108431418163710"><a name="p108431418163710"></a><a name="p108431418163710"></a>Return value: none</p>
</td>
</tr>
<tr id="row128435182379"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p5843181816371"><a name="p5843181816371"></a><a name="p5843181816371"></a>int ToBytes(uint8_t* pIdArray, int len)</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p8843171818378"><a name="p8843171818378"></a><a name="p8843171818378"></a>Converts the <strong id="b68851225439"><a name="b68851225439"></a><a name="b68851225439"></a>HiTraceId</strong> object into a byte array to facilitate caching or communication transfer.</p>
<p id="p1884391819376"><a name="p1884391819376"></a><a name="p1884391819376"></a>Input arguments:</p>
<a name="ul169461002314"></a><a name="ul169461002314"></a><ul id="ul169461002314"><li><strong id="b960934311010"><a name="b960934311010"></a><a name="b960934311010"></a>pIdArray</strong>: Indicates the pointer to a byte array. The minimum length of the byte array is <strong id="b96124430106"><a name="b96124430106"></a><a name="b96124430106"></a>HITRACE_ID_LEN</strong>.</li><li><strong id="b13672164941019"><a name="b13672164941019"></a><a name="b13672164941019"></a>len</strong>: Indicates the length of the byte array.</li></ul>
<p id="p8843101819379"><a name="p8843101819379"></a><a name="p8843101819379"></a>Output arguments</p>
<a name="ul116274319312"></a><a name="ul116274319312"></a><ul id="ul116274319312"><li><strong id="b12376938695"><a name="b12376938695"></a><a name="b12376938695"></a>pIdArray</strong>: Indicates the pointer to a byte array. If the object is valid, the object data after conversion is stored.</li></ul>
<p id="p8843618143720"><a name="p8843618143720"></a><a name="p8843618143720"></a>Return value: Returns a value greater than 0 (indicating a valid array of object data) if the conversion is successful; returns <strong id="b2156170234"><a name="b2156170234"></a><a name="b2156170234"></a>0</strong> otherwise.</p>
</td>
</tr>
</tbody>
</table>
## Call Chain Processing
Inter-device, inter-process, and inter-thread calls are implemented through the communication mechanism. **HiTraceChain** requires transfer of **traceid** in the communication mechanism.
Some built-in communication mechanisms \(such as ZIDL\) of OpenHarmony already support the transfer of **traceid**.
The following figure shows the process of transferring **traceid** in synchronous call. The process of transferring **traceid** in asynchronous call is similar.
Extended communication mechanisms can also follow this implementation.
**Figure 5** Call chain tracing in synchronous communication
![](figures/call-chain-tracing-in-synchronous-communication.png "call-chain-tracing-in-synchronous-communication")
**Table 2** Trace flag combination types
| **Name**| **Value**| **Description**|
| -------- | -------- | -------- |
| HITRACE_FLAG_DEFAULT | 0 | Default flag. |
| HITRACE_FLAG_INCLUDE_ASYNC | 1 | Asynchronous call flag. By default, only synchronous calls are traced. If this flag is set, both synchronous and asynchronous calls will be traced. |
| HITRACE_FLAG_DONOT_CREATE_SPAN | 1 << 1 | No span flag. By default, spans are created within a trace of synchronous and asynchronous service calls. If this flag is set, no spans are created. |
| HITRACE_FLAG_TP_INFO | 1 << 2 | Trace point flag. By default, no trace point is added when trace is enabled. This flag is used for debugging. If this flag is set, trace points will be automatically added on the TX and RX sides of synchronous and asynchronous calls to output trace point and timestamp information. Trace points are classified into four types: client send (CS), server receive (SR), server send (SS), and client receive (CR). For a synchronous call, the output trace points are CS, SR, SS, and CR; for an asynchronous call, the output trace points are CS, SR, and SS. |
| HITRACE_FLAG_NO_BE_INFO | 1 << 3 | No begin/end flag. By default, information about the start and end of the trace task is printed. If this flag is set, information about the start and end of the trace task will not be printed.|
| HITRACE_FLAG_DONOT_ENABLE_LOG | 1 << 4 | Log association flag. If this flag is set, information about the trace task will not be printed. |
| HITRACE_FLAG_FAULT_TRIGGER | 1 << 5 | Failure trigger flag. This flag is reserved for future use. |
| HITRACE_FLAG_D2D_TP_INFO | 1 << 6 | Device-to-device trace point flag. It is a subset of **TP_INFO**. If this flag is set, trace points are added only for call chain trace between devices.|
**Table 3** Trace point types
| **Name**| **Value**| **Description**|
| -------- | -------- | -------- |
| HITRACE_TP_CS | 0 | CS trace point. |
| HITRACE_TP_CR | 1 | CR trace point. |
| HITRACE_TP_SS | 2 | SS trace point. |
| HITRACE_TP_SR | 3 | SR trace point. |
| HITRACE_TP_GENERAL | 4 | General trace points except CS, CR, SS, and SR.|
**Table 4** Communication modes
| **Name**| **Value**| **Description**|
| -------- | -------- | -------- |
| HITRACE_CM_DEFAULT | 0 | Default communication mode. |
| HITRACE_CM_THREAD | 1 | Inter-thread communication. |
| HITRACE_CM_PROCESS | 2 | Inter-process communication. |
| HITRACE_CM_DEVICE | 3 | Inter-device communication. |
**Table 5** Description of C++ APIs
| **Class**| **API**| **Description**|
| -------- | -------- | -------- |
| HiTraceChain | HiTraceId Begin(const std::string&amp; name, int flags) | Starts HiTraceChain, generates a **HiTraceId** object, and sets it in the TLS of the calling thread.<br>Input arguments:<br>- **name**: name of the service process.<br>- **flags**: trace flags, which can be used in combination. For details, see Table 2.<br>Output arguments: none<br>Return value: a valid **HiTraceId** object if call chain trace is triggered successfully; returns an invalid object otherwise.<br>Note: In nested trace mode, an invalid object will be returned if trace is started at the nested layer.|
| | void End(const HiTraceId&amp; id) | Stops HiTraceChain based on the **HiTraceId** object returned by the **Begin** API, and clears the **HiTraceId** object in the TLS of the calling thread.<br>Input arguments:<br>- **id**: **HiTraceId** object.<br>Output arguments: none<br>Return value: none|
| | HiTraceId GetId(); | Obtains the **HiTraceId** object from the TLS of the calling thread.<br>Input arguments: none<br>Output arguments: none<br>Return value: **HiTraceId** object in the contextual TLS of the calling thread.|
| | void SetId(const HiTraceId&amp; id) | Purpose: Sets the **HiTraceId** object in the TLS of the calling thread.<br>Input arguments:<br>- **id**: **HiTraceId** object.<br>Output arguments: none<br>Return value: none|
| | void ClearId() | Clears the **HiTraceId** object in the TLS of the calling thread.<br>Input arguments: none<br>Output arguments: none<br>Return value: none|
| | HiTraceId CreateSpan() | Obtains the span ID from the current **HiTraceId** object.<br>Input arguments: none<br>Output arguments: none<br>Return value: current span ID.|
| | void Tracepoint(HiTraceTracepointType type, const HiTraceId&amp; id, const char* fmt, ...) | Outputs HiTraceChain trace point information based on the information type. The information includes the timestamp and **HiTraceId** object of the span.<br>Input arguments:<br>- **type**: trace point type. For details, see Table 3.<br>- **id**: ID of the current span.<br>- **fmt**: string describing the format variable parameter.<br>- **args**: variable parameter.<br>Output arguments: none<br>Return value: none|
| | void Tracepoint(HiTraceCommunicationMode mode, HiTraceTracepointType type, const HiTraceId&amp; id, const char* fmt, ...) | Outputs HiTraceChain trace point information based on the communication mode and information type. The information includes the timestamp and **HiTraceId** object of the span.<br>Input arguments:<br>- **mode**: communication mode. For details, see Table 4.<br>- **type**: trace point type. For details, see Table 3.<br>- **id**: ID of the current span.<br>- **fmt**: string describing the format variable parameter.<br>- **args**: variable parameter.<br>Output arguments: none<br>Return value: none|
| HiTraceId | HiTraceId(); | Represents the default constructor used to generate an invalid **HiTraceId** object. <br>Input arguments: none<br>Output arguments: none<br>Return value: none|
| | HiTraceId(const uint8_t* pIdArray, int len) | Represents the constructor used to create a **HiTraceId** object based on the specified byte array. <br>Input arguments:<br>- **pIdArray**: pointer to a byte array.<br>- **len**: length of the byte array.<br>Output arguments: none<br>Return value: none|
| | bool IsValid() | Checks whether the **HiTraceId** object is valid.<br>Input arguments: none<br>Output arguments: none<br>Return value: **true** if the **HiTraceId** object is valid; **false** otherwise.|
| | bool IsFlagEnabled(HiTraceFlag flag) | Checks whether the trace flag of the **HiTraceId** object is enabled.<br>Input arguments:<br>- **flag**: trace flag. For details, see the description in the **Begin** function.<br>Output arguments: none<br>Return value: **true** if the trace flag is enabled; **false** otherwise.|
| | void EnableFlag(HiTraceFlag flag) | Enables the trace flag of the **HiTraceId** object.<br>Input arguments:<br>- **flag**: trace flag. For details, see the description in the **Begin** function.<br>Output arguments: none<br>Return value: none|
| | int GetFlags() | Obtains the trace flag set in the **HiTraceId** object.<br>Input arguments: none<br>Output arguments: none<br>Return value: Returns the combination of trace flags. For details, see the description in the **Begin** function.|
| | void SetFlags(int flags) | Sets a trace flag in the **HiTraceId** object.<br>Input arguments:<br>- **flags**: combination of trace flags. For details, see the description in the **Begin** function.<br>Output arguments: none<br>Return value: none|
| | uint64_t GetChainId() | Obtains the call chain ID.<br>Input arguments: none<br>Output arguments: none<br>Return value: call chain ID.|
| | void SetChainId(uint64_t chainId) | Sets the call chain ID in the **HiTraceId** object.<br>Input arguments:<br>- **chainId**: call chain ID.<br>Output arguments: none<br>Return value: none|
| | uint64_t GetSpanId() | Obtains the span ID from the current **HiTraceId** object.<br>Input arguments: none<br>Output arguments: none<br>Return value: current span ID.|
| | void SetSpanId(uint64_t spanId) | Sets the span ID in the **HiTraceId** object.<br>Input arguments:<br>- **spanId**: span ID.<br>Output arguments: none<br>Return value: none|
| | uint64_t GetParentSpanId() | Obtains the parent span ID from the current **HiTraceId** object.<br>Input arguments: none<br>Output arguments: none<br>Return value: parent span ID.|
| | void SetParentSpanId(uint64_t parentSpanId) | Sets the parent span ID in the **HiTraceId** object.<br>Input arguments:<br>- **parentSpanId**: parent span ID.<br>Output arguments: none<br>Return value: none|
| | int ToBytes(uint8_t* pIdArray, int len) | Converts the **HiTraceId** object into a byte array to facilitate caching or communication transfer.<br>Input arguments:<br>- **pIdArray**: pointer to a byte array. The minimum length of the byte array is **HITRACE_ID_LEN**.<br>- **len**: length of the byte array.<br>Output parameters:<br>- **pIdArray**: pointer to a byte array. If the object is valid, the object data after conversion is stored.<br>Return value: a value greater than **0** (indicating a valid array of object data) if the conversion is successful; **0** otherwise.|
### Call Chain Processing
Inter-device, inter-process, and inter-thread calls are implemented through the communication mechanism. HiTraceChain requires transfer of **traceid** in the communication mechanism.
Some built-in communication mechanisms (such as ZIDL) of OpenHarmony already support the transfer of **traceid**.
The following figure shows the process of transferring **traceid** in synchronous call. The process of transferring **traceid** in asynchronous call is similar.
Extended communication mechanisms can also follow this implementation.
**Figure 5** Call chain trace in synchronous communication
![](figures/call-chain-trace-in-synchronous-communication.png "call-chain-trace-in-synchronous-communication")
The process is as follows:
1. The service module on the client calls the **begin\(\)** function to start call chain tracing.
2. The service module on the client synchronously calls the **transact** function to the communication component on the client.
3. The communication component on the client performs the following:
1. Obtains **traceid** from the TLS of the calling thread.
2. Generates child **traceid**.
3. Writes child **traceid** into the transaction data \(synchronous communication data\).
4. Performs Client Send \(CS\) tracing.
5. Sends communication data to the communication component on the server.
4. On receiving the communication data, the communication component on the server performs the following:
1. Obtains **traceid** from the data message package.
2. Sets **traceid** in the TLS of the calling thread.
3. Performs Server Receive \(SR\) tracing.
4. Synchronously call the **onTransact** callback to the service module on the server.
5. The service module on the server processes the service and sends the transact reply message carrying the processing result to the communication component.
6. The communication component on the server performs the following:
1. Performs Server Send \(SS\) tracing.
2. Sends communication data to the communication component on the client.
3. Clears **traceid** from the TLS of the calling thread.
7. On receiving the communication data, the communication component on the client performs the following:
1. Performs Client Receive \(CR\) tracing.
2. Sends a transact reply response to the service module on the client.
8. The service module on the client processes the transact reply response.
9. When the process ends, the service module on the client calls the **end\(\)** function to stop call chain tracing.
## How to Develop
### C++
1. Develop the source code.
1. The service module on the client calls the **begin()** function to start call chain trace.
Include the **hitracechain** header file in the class definition header file or class implementation source file. For example:
2. The service module on the client synchronously calls the **transact** function to the communication component on the client.
```
#include "hitrace/tracechain.h"
```
3. The communication component on the client performs the following:
1. Obtains **traceid** from the TLS of the calling thread.
2. Generates child **traceid**.
3. Writes child **traceid** into the transaction data (synchronous communication data).
4. Performs CS trace.
5. Sends communication data to the communication component on the server.
Add the code to start and stop call chain tracing in the class implementation source file.
4. On receiving the communication data, the communication component on the server performs the following:
1. Obtains **traceid** from the data message package.
2. Sets **traceid** in the TLS of the calling thread.
3. Performs SR trace.
4. Synchronously calls the **onTransact** callback to the service module on the server.
```
using namespace OHOS::HiviewDFX;
auto traceId = HiTraceChain::Begin("MyServiceFlow", HITRACE_FLAG_DEFAULT);
...
HiTraceChain::End(traceId);
```
5. The service module on the server processes the service and sends the transact reply message carrying the processing result to the communication component.
2. Configure compilation information. Specifically, add the subsystem SDK dependency to **BUILD.gn**.
6. The communication component on the server performs the following:
1. Performs SS trace.
2. Sends communication data to the communication component on the client.
3. Clears **traceid** from the TLS of the calling thread.
```
external_deps = [ "hiviewdfx:libhitracechain" ]
```
7. On receiving the communication data, the communication component on the client performs the following:
1. Performs CR trace.
2. Sends a transact reply response to the service module on the client.
8. The service module on the client processes the transact reply response.
### C
9. When the process ends, the service module on the client calls the **end()** function to stop call chain trace.
1. Develop the source code.
Include the **hitracechain** header file in the source file.
```
#include "hitrace/tracechain.h"
```
Add the code to start and stop call chain tracing in the class implementation source file.
```
HiTraceIdStruct traceId = HiTraceChainBegin("MyServiceFlow", HITRACE_FLAG_DEFAULT);
...
HiTraceChainEnd(traceId);
```
2. Configure compilation information. Specifically, add the subsystem SDK dependency to **BUILD.gn**.
```
external_deps = [ "hiviewdfx:libhitracechain" ]
```
## How to Develop
### **C++**
1. Develop the source code.
Include the **hitracechain** header file in the class definition header file or class implementation source file. For example:
```
#include "hitrace/tracechain.h"
```
Add the code to start and stop call chain trace in the class implementation source file.
```
using namespace OHOS::HiviewDFX;
auto traceId = HiTraceChain::Begin("MyServiceFlow", HITRACE_FLAG_DEFAULT);
......
HiTraceChain::End(traceId);
```
2. Configure compilation information. Specifically, add the subsystem SDK dependency to **BUILD.gn**.
```
external_deps = [ "hiviewdfx:libhitracechain" ]
```
### **C**
1. Develop the source code.
Include the **hitracechain** header file in the source file.
```
#include "hitrace/tracechain.h"
```
Add the code to start and stop call chain trace in the class implementation source file.
```
HiTraceIdStruct traceId = HiTraceChainBegin("MyServiceFlow", HITRACE_FLAG_DEFAULT);
......
HiTraceChainEnd(traceId);
```
2. Configure compilation information. Specifically, add the subsystem SDK dependency to **BUILD.gn**.
```
external_deps = [ "hiviewdfx:libhitracechain" ]
```
......@@ -2,7 +2,7 @@
## Introduction
HiTraceMeter is the OpenHarmony subsystem that provides APIs to implement call chain trace throughout a service process. With HiTraceMeter, you can quickly obtain the run log specific to the call chain of a service process and locate faults in inter-device, inter-process, or inter-thread communications. HiTraceMeter supports event logging in user mode and can collect trace data in user mode and kernel mode for performance tracing and analysis.
HiTraceMeter is the OpenHarmony subsystem that provides APIs to implement call chain trace throughout a service process. With HiTraceMeter, you can quickly obtain the run log specific to the call chain of a service process and locate faults in inter-device, inter-process, or inter-thread communications. HiTraceMeter supports event logging in user mode and can collect trace data in user mode and kernel mode for performance trace and analysis.
## Basic Concepts
......@@ -12,7 +12,7 @@ The HiTraceMeter subsystem consists of three parts:
- hitrace CLI tool for data collection
- smartperf tool for graphical data analysis
Wherein, HiTraceMeter APIs and the hitrace CLI tool run on the device side, and the smartperf tool runs on the PC side. HiTraceMeter APIs are provided in C++ and JS for event logging, which aims to generate the trace data necessary for performance tracing and analysis during the development process.
Wherein, HiTraceMeter APIs and the hitrace CLI tool run on the device side, and the smartperf tool runs on the PC side. HiTraceMeter APIs are provided in C++ and JS for event logging, which aims to generate the trace data necessary for performance trace and analysis during the development process.
The hitrace CLI tool is used to collect trace data. It captures trace data flows and saves the data as a text file.
......@@ -348,4 +348,4 @@ You can set **-t** to **60** and **-b** to **204800** to increase the trace time
# Reference
For details about HiTraceMeter, see [hiviewdfx_hitrace: Lightweight Distributed Tracing](https://gitee.com/openharmony/hiviewdfx_hitrace).
For details about HiTraceMeter, see [hiviewdfx_hitrace: Lightweight Distributed Trace](https://gitee.com/openharmony/hiviewdfx_hitrace).
# DFX Overview<a name="EN-US_TOPIC_0000001185974398"></a>
# DFX Overview
[Design for X](https://en.wikipedia.org/wiki/Design_for_X) \(DFX\) refers to the software design that aims to improve the quality attributes in OpenHarmony. It mainly consists of two parts: design for reliability \(DFR\) and design for testability \(DFT\).
## Introduction
[Design for X](https://en.wikipedia.org/wiki/Design_for_X) \(DFX\) refers to the software design that aims to improve the quality attributes in OpenHarmony. It mainly consists of two parts: design for reliability \(DFR\) and design for testability \(DFT\).
The DFX subsystem provides the following functions:
- HiLog: implements the logging function. It is applicable to mini-system devices \(reference memory ≥ 128 KiB\), small-system devices \(reference memory ≥ 1 MiB\), and standard-system devices \(reference memory ≥ 128 MB\).
- HiTraceChain: implements distributed call chain tracing. It is applicable to standard-system devices \(reference memory ≥ 128 MiB\).
- HiLog: implements the logging function. It is applicable to mini-system devices \(reference memory ≥ 128 KiB\), small-system devices \(reference memory ≥ 1 MiB\), and standard-system devices \(reference memory ≥ 128 MiB\).
- HiTraceChain: implements distributed call chain trace. It is applicable to standard-system devices \(reference memory ≥ 128 MiB\).
- HiTraceMeter: implements performance trace. It is applicable to standard-system devices \(reference memory ≥ 128 MiB\).
- HiCollie: implements thread suspension detection. It is applicable to standard-system devices \(reference memory ≥ 128 MiB\).
- HiSysEvent: implements system event logging. It is applicable to standard-system devices \(reference memory ≥ 128 MiB\).
- HiDumper: exports system information. It is applicable to standard-system devices \(reference memory ≥ 128 MiB\).
- FaultLogger: implements crash detection. It is applicable to standard-system devices \(reference memory ≥ 128 MiB\).
- Faultlogger: implements crash detection. It is applicable to standard-system devices \(reference memory ≥ 128 MiB\).
- Hiview: implements device maintenance across different platforms. It is applicable to standard-system devices \(reference memory ≥ 128 MiB\).
- HiAppEvent and HiChecker are only hap developer oriented。
- HiAppEvent and HiChecker are applicable only for HAP developers.
![dfx features overview](figure/dfx-overview.png)
## Basic Concepts<a name="section5635178134811"></a>
## Basic Concepts
**Logging**
Logging means to record the log information generated during system running so you can understand the running process and status of the system or applications.
**Distributed call chain tracing**
**Distributed call chain trace**
In a distributed system, the initiation of a service may involve multiple software modules, with control commands and data transmitted over intra-process, inter-process, and inter-device communication interfaces. To help you understand such complex communication processes and locate service faults efficiently, the DFX subsystem provides a distributed call chain tracing framework.
In a distributed system, the initiation of a service may involve multiple software modules, with control commands and data transmitted over intra-process, inter-process, and inter-device communication interfaces. To help you understand such complex communication processes and locate service faults efficiently, the DFX subsystem provides a distributed call chain trace framework.
**Thread suspension detection**
If a thread is trapped in an infinite loop or the kernel state \(for example, Uninterruptable Sleep, Traced, Zombie, or synchronous wait\) when it is running, the thread cannot respond to normal service requests and cannot detect and recover from faults by itself. To detect and locate this type of faults, the DFX subsystem provides a simple watchdog mechanism by inserting detection probes to the process nodes that are prone to suspension. This ensures that suspension faults can be detected and logs can be collected.
If a thread is trapped in an infinite loop or the kernel state (for example, Uninterruptable Sleep, Traced, Zombie, or synchronous wait) when it is running, the thread cannot respond to normal service requests and cannot detect and recover from faults by itself. To detect and locate this type of faults, the DFX subsystem provides a simple watchdog mechanism by inserting detection probes to the process nodes that are prone to suspension. This ensures that suspension faults can be detected and logs can be collected.
**Event logging**
**Logging**
Event logging means to collect and log events reported during system running. The log information will help you better analyze the product usage.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册