5ecdd3127e
Signed-off-by: stesen <stesen.ma@huawei.com> Change-Id: I7832f0230feb5a6c4276b72dabace81bc4b31dec |
||
---|---|---|
figures | ||
frameworks/native | ||
interfaces/native/innerkits | ||
lite | ||
LICENSE | ||
ohos.build | ||
README_zh.md | ||
README.md |
HiTrace
Overview
HiTrace provides APIs to implement call chain tracing throughout a service process. With HiTrace, you can quickly obtain the run log for the call chain of a specified service process and locate faults in cross-device, cross-process, or cross-thread communications.
Architecture
Figure 1 Architecture of HiTrace
HiTrace is the lightweight implementation based on the distributed call chain of cloud computing. HiTrace implements call chain tracing as follows:
- Transfers traceid in cross-device, cross-process, and cross-thread communications.
- Stores traceid in the thread local storage
TLS
at the Native layer of the process. - Automatically adds traceid to existing events and run logs.
Directory Structure
/base/hiviewdfx/hitrace
├── frameworks # Framework code
│ ├── java # HiTrace Java implementation code
│ ├── jni # HiTrace JNI implementation code
│ └── native # HiTrace Native implementation code
└── interfaces # APIs
├── java # Java APIs
│ ├── innerkits # JAR packages opened to internal subsystems
│ └── kits # JAR packages opened to applications
└── native # C/C++ APIs
└── innerkits # Header files opened to internal subsystems
Constraints
HiTrace is already supported by the IPC and EventHandler communication mechanisms. If you are using a custom communication mechanism, adaptation is required to use HiTrace.
Usage
Available APIs
Major APIs of HiTrace
Usage Guidelines
1
Enable call chain tracing for the service process.
Import the HiTrace and HiTraceId classes.
import ohos.hiviewdfx.HiTrace;
import ohos.hiviewdfx.HiTraceId;
Add the code to start or stop call chain tracing.
HiTraceId traceId = HiTrace.begin("MyServiceFlow", HiTrace.HITRACE_FLAG_DEFAULT);
... (service process for call chain tracing)
HiTrace.end(traceId);
2
Run the application.
3
Use the hilog tool in the shell to filter logs of the service invoking process.
Filter logs based on the name parameter in the tracing task and find ChainId.
hilog | grep "MyServiceFlow"
Note: The log format for traceid is as follows:
Time PID TID Level Domain/Tag: [ChainId, SpanId, ParentSpanId] Content
Filter the logs of the service invoking process based on ChainId.
hilog | grep "ChainId"