trace.h
Overview
Defines APIs of the HiTraceMeter module for performance trace.
Example
Synchronous time slice trace event:
OH_HiTrace_StartTrace("hitraceTest");
OH_HiTrace_FinishTrace();
Output:
<...>-1668 (----—) [003] .... 135.059377: tracing_mark_write: B|1668|H:hitraceTest
<...>-1668 (----—) [003] .... 135.059415: tracing_mark_write: E|1668|
Asynchronous time slice trace event:
OH_HiTrace_StartAsyncTrace("hitraceTest", 123);
OH_HiTrace_FinishAsyncTrace("hitraceTest", 123);
Output:
<...>-2477 (----—) [001] .... 396.427165: tracing_mark_write: S|2477|H:hitraceTest 123
<...>-2477 (----—) [001] .... 396.427196: tracing_mark_write: F|2477|H:hitraceTest 123
Integer value trace event:
OH_HiTrace_CountTrace("hitraceTest", 500);
Output:
<...>-2638 (----—) [002] .... 458.904382: tracing_mark_write: C|2638|H:hitraceTest 500
File to include:
<hitrace/trace.h>
Since
10
Related Modules
Summary
Structs
| Name | Description |
|---|---|
| struct HiTraceId | Defines the HiTraceId instance. |
Types
| Name | Description |
|---|---|
| typedef enum HiTraceId_Valid HiTraceId_Valid | Defines an enum for whether a HiTraceId instance is valid. |
| typedef enum HiTrace_Version HiTrace_Version | Defines an enum for the version number of HiTrace. |
| typedef enum HiTrace_Flag HiTrace_Flag | Defines an enum for the flag of HiTrace. |
| typedef enum HiTrace_Tracepoint_Type HiTrace_Tracepoint_Type | Defines an enum for the tracepoint type of HiTrace. |
| typedef enum HiTrace_Communication_Mode HiTrace_Communication_Mode | |
| typedef struct HiTraceIdHiTraceId |
Enums
| Name | Description |
|---|---|
| HiTraceId_Valid { HITRACE_ID_INVALID = 0, HITRACE_ID_VALID = 1 } | Enumerates whether a HiTraceId instance is valid. |
| HiTrace_Version { HITRACE_VER_1 = 0 } | Enumerates the version numbers of HiTrace. |
| HiTrace_Flag { HITRACE_FLAG_DEFAULT = 0, HITRACE_FLAG_INCLUDE_ASYNC = 1 << 0, HITRACE_FLAG_DONOT_CREATE_SPAN = 1 << 1, HITRACE_FLAG_TP_INFO = 1 << 2, HITRACE_FLAG_NO_BE_INFO = 1 << 3, HITRACE_FLAG_DONOT_ENABLE_LOG = 1 << 4, HITRACE_FLAG_FAULT_TRIGGER = 1 << 5, HITRACE_FLAG_D2D_TP_INFO = 1 << 6 } |
Defines an enum for the flag of HiTrace. |
| HiTrace_Tracepoint_Type { HITRACE_TP_CS = 0, HITRACE_TP_CR = 1, HITRACE_TP_SS = 2, HITRACE_TP_SR = 3, HITRACE_TP_GENERAL = 4 } |
Enumerates the tracepoint types of HiTrace. |
| HiTrace_Communication_Mode { HITRACE_CM_DEFAULT = 0, HITRACE_CM_THREAD = 1, HITRACE_CM_PROCESS = 2, HITRACE_CM_DEVICE = 3 } |
Functions
| Name | Description |
|---|---|
| HiTraceId OH_HiTrace_BeginChain (const char *name, int flags) | Starts tracing a process. |
| void OH_HiTrace_EndChain () | Stops tracing the process and clears the trace ID of the calling thread if the given trace ID is valid. Otherwise, no operation is performed. |
| HiTraceId OH_HiTrace_GetId () | Obtains the trace ID of the calling thread. If the calling thread does not have a trace ID, an invalid trace ID is returned. |
| void OH_HiTrace_SetId (const HiTraceId *id) | Sets the trace ID of the calling thread. If the ID is invalid, no operation is performed. |
| void OH_HiTrace_ClearId (void) | Clears the trace ID of the calling thread and invalidates it. |
| HiTraceId OH_HiTrace_CreateSpan (void) | Creates a span ID based on the trace ID of the calling thread. |
| void OH_HiTrace_Tracepoint (HiTrace_Communication_Mode mode, HiTrace_Tracepoint_Type type, const HiTraceId *id, const char *fmt,...) | Prints HiTrace information, including the trace ID. |
| void OH_HiTrace_InitId (HiTraceId *id) | Initializes a HiTraceId instance. |
| void OH_HiTrace_IdFromBytes (HiTraceId *id, const uint8_t *pIdArray, int len) | Creates a HiTraceId instance based on a byte array. |
| bool OH_HiTrace_IsIdValid (const HiTraceId *id) | Checks whether a HiTraceId instance is valid. |
| bool OH_HiTrace_IsFlagEnabled (const HiTraceId *id, HiTrace_Flag flag) | Checks whether the specified trace flag is enabled in a HiTraceId instance. |
| void OH_HiTrace_EnableFlag (const HiTraceId *id, HiTrace_Flag flag) | Enables the specified trace flag in a HiTraceId instance. |
| int OH_HiTrace_GetFlags (const HiTraceId *id) | Obtains the trace flags in a HiTraceId instance. |
| void OH_HiTrace_SetFlags (HiTraceId *id, int flags) | Sets trace flags in a HiTraceId instance. |
| uint64_t OH_HiTrace_GetChainId (const HiTraceId *id) | Obtains a trace chain ID. |
| void OH_HiTrace_SetChainId (HiTraceId *id, uint64_t chainId) | Sets the trace chain ID in a HiTraceId instance. |
| uint64_t OH_HiTrace_GetSpanId (const HiTraceId *id) | Obtains the span ID in a HiTraceId instance. |
| void OH_HiTrace_SetSpanId (HiTraceId *id, uint64_t spanId) | Sets the span ID in a HiTraceId instance. |
| uint64_t OH_HiTrace_GetParentSpanId (const HiTraceId *id) | Obtains the parent span ID in a HiTraceId instance. |
| void OH_HiTrace_SetParentSpanId (HiTraceId *id, uint64_t parentSpanId) | Sets the ParentSpanId in a HiTraceId instance. |
| int OH_HiTrace_IdToBytes (const HiTraceId *id, uint8_t *pIdArray, int len) | Converts a HiTraceId instance into a byte array for caching or transfer. |
| void OH_HiTrace_StartTrace (const char *name) | Marks the start of a synchronous trace. |
| void OH_HiTrace_FinishTrace (void) | Marks the end of a synchronous trace. |
| void OH_HiTrace_StartAsyncTrace (const char *name, int32_t taskId) | Marks the start of an asynchronous trace. |
| void OH_HiTrace_FinishAsyncTrace (const char *name, int32_t taskId) | Marks the end of an asynchronous trace. |
| void OH_HiTrace_CountTrace (const char *name, int64_t count) | Traces the value change of an integer variable based on its name. |