harmony 鸿蒙HiTrace

2025-06-12 浏览 (1)

HiTrace

Overview

HiTraceMeter provides APIs for system performance tracing.

You can call the APIs provided by HiTraceMeter in your own service logic to effectively track service processes and check the system performance.

HiTraceChain provides APIs for cross-thread and cross-process distributed tracing.

HiTraceChain generates a unique chain ID for a service process and passes it to various information (including application events, system events, and logs) specific to the service process. During debugging and fault locating, you can use the unique chain ID to quickly correlate various information related to the service process.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 10

Summary

Files

NameDescription
trace.hDefines APIs of the HiTraceMeter module for performance trace.

Structs

NameDescription
struct  HiTraceIdDefines a HiTraceId instance.

Types

NameDescription
typedef enum HiTraceId_Valid HiTraceId_ValidDefines an enum for whether a HiTraceId instance is valid.
typedef enum HiTrace_Version HiTrace_VersionDefines an enum for the HiTrace versions.
typedef enum HiTrace_Flag HiTrace_FlagDefines an enum for the HiTrace flags.
typedef enum HiTrace_Tracepoint_Type HiTrace_Tracepoint_TypeDefines an enum for the HiTrace tracepoint types.
typedef enum HiTrace_Communication_Mode HiTrace_Communication_ModeDefines an enum for the HiTrace communication modes.
typedef enum HiTrace_Output_Level HiTrace_Output_LevelDefines an enum for the HiTrace output levels.
typedef struct HiTraceIdHiTraceId

Enums

NameDescription
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 HiTrace versions.
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
}
Enumerates the HiTrace flags.
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 HiTrace tracepoint types.
HiTrace_Communication_Mode { HITRACE_CM_DEFAULT = 0, HITRACE_CM_THREAD = 1, HITRACE_CM_PROCESS = 2, HITRACE_CM_DEVICE = 3 }Enumerates the HiTrace communication modes.
HiTrace_Output_Level {
HITRACE_LEVEL_DEBUG = 0, HITRACE_LEVEL_INFO = 1, HITRACE_LEVEL_CRITICAL = 2, HITRACE_LEVEL_COMMERCIAL = 3,
HITRACE_LEVEL_MAX = HITRACE_LEVEL_COMMERCIAL
}
Enumerates the HiTrace output levels.

Functions

NameDescription
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.
void OH_HiTrace_StartTraceEx (HiTrace_Output_Level level, const char *name, const char *customArgs)Marks the start of a synchronous trace task with the trace output level specified.
void OH_HiTrace_FinishTraceEx (HiTrace_Output_Level level)Marks the end of a synchronous trace task with the trace output level specified.
void OH_HiTrace_StartAsyncTraceEx (HiTrace_Output_Level level, const char *name, int32_t taskId, const char *customCategory, const char *customArgs)Marks the start of an asynchronous trace task with the trace output level specified.
void OH_HiTrace_FinishAsyncTraceEx (HiTrace_Output_Level level, const char *name, int32_t taskId)Marks the end of an asynchronous trace task with the trace output level specified.
void OH_HiTrace_CountTraceEx (HiTrace_Output_Level level, const char *name, int64_t count)Marks an integer variable trace task with the trace output level specified.
bool OH_HiTrace_IsTraceEnabled (void)Checks whether trace capture is enabled for an application. If not, HiTraceMeter performance tracing is invalid.

Type Description

HiTrace_Communication_Mode

typedef enum HiTrace_Communication_ModeHiTrace_Communication_Mode

Description Defines an enum for the HiTrace communication modes.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 12

HiTrace_Flag

typedef enum HiTrace_FlagHiTrace_Flag

Description Defines an enum for the HiTrace flags.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 12

HiTrace_Output_Level

typedef enum HiTrace_Output_LevelHiTrace_Output_Level

Description Defines an enum for the HiTrace output levels.

The trace output level lower than the threshold does not take effect. The log version threshold is HITRACE_LEVEL_INFO, and the nolog version threshold is HITRACE_LEVEL_COMMERCIAL.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 19

HiTrace_Tracepoint_Type

typedef enum HiTrace_Tracepoint_Type HiTrace_Tracepoint_Type

Description Defines an enum for the HiTrace tracepoint types.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 12

HiTrace_Version

typedef enum HiTrace_Version HiTrace_Version

Description Defines an enum for the HiTrace versions.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 12

HiTraceId_Valid

typedef enum HiTraceId_Valid HiTraceId_Valid

Description Defines an enum for whether a HiTraceId instance is valid.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 12

Enum Description

HiTrace_Communication_Mode

enum HiTrace_Communication_Mode

Description Enumerates the HiTrace communication modes.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 12

ValueDescription
HITRACE_CM_DEFAULTUnspecified.
HITRACE_CM_THREADInter-thread communication.
HITRACE_CM_PROCESSInter-process communication (IPC).
HITRACE_CM_DEVICEInter-device communication.

HiTrace_Flag

enum HiTrace_Flag

Description Enumerates the HiTrace flags.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 12

ValueDescription
HITRACE_FLAG_DEFAULTDefault value.
HITRACE_FLAG_INCLUDE_ASYNCBoth synchronous and asynchronous calls are traced. By default, only synchronous calls are traced.
HITRACE_FLAG_DONOT_CREATE_SPANNo spans are created. By default, spans are created.
HITRACE_FLAG_TP_INFOTrace points are automatically added to spans. By default, no trace point is added.
HITRACE_FLAG_NO_BE_INFOInformation about the start and end of the trace task is not printed. By default, information about the start and end of the trace task is printed.
HITRACE_FLAG_DONOT_ENABLE_LOGThe ID is not added to the log. By default, the ID is added to the log.
HITRACE_FLAG_FAULT_TRIGGERTracing is triggered by faults.
HITRACE_FLAG_D2D_TP_INFOOnly the device-to-device tracing point information in the span is output. By default, the device-to-device tracing point information is not output.

HiTrace_Output_Level

enum HiTrace_Output_Level

Description Enumerates the HiTrace output levels.

The trace output level lower than the threshold does not take effect. The log version threshold is HITRACE_LEVEL_INFO, and the nolog version threshold is HITRACE_LEVEL_COMMERCIAL.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 19

ValueDescription
HITRACE_LEVEL_DEBUGLevel used only for debugging, which has the lowest priority.
HITRACE_LEVEL_INFOLevel for the log version.
HITRACE_LEVEL_CRITICALLevel for the log version, which has a higher priority than INFO.
HITRACE_LEVEL_COMMERCIALLevel for the nolog version, which has the highest priority.
HITRACE_LEVEL_MAXThe maximum output level.

HiTrace_Tracepoint_Type

enum HiTrace_Tracepoint_Type

Description Enumerates the HiTrace tracepoint types.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 12

ValueDescription
HITRACE_TP_CSCS trace point.
HITRACE_TP_CRCR trace point.
HITRACE_TP_SSSS trace point.
HITRACE_TP_SRSR trace point.
HITRACE_TP_GENERALGeneral trace point.

HiTrace_Version

enum HiTrace_Version

Description Enumerates the HiTrace versions.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 12

ValueDescription
HITRACE_VER_1Version 1.

HiTraceId_Valid

enum HiTraceId_Valid

Description Enumerates whether a HiTraceId instance is valid.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 12

ValueDescription
HITRACE_ID_INVALIDInvalid HiTraceId.
HITRACE_ID_VALIDValid HiTraceId.

Function Description

OH_HiTrace_BeginChain()

HiTraceId OH_HiTrace_BeginChain (const char * name, int flags )

Description Starts tracing a process.

This API starts tracing, creates a HiTraceId instance, and sets it to the TLS of the calling thread. This API works only when it is called for the first time.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 12

Parameters

NameDescription
nameName of the traced service.
flagsFlags of the tracing. For details, see HiTrace_Flag.

Returns

Returns the generated HitraceId. For details, see HiTraceId.

OH_HiTrace_ClearId()

void OH_HiTrace_ClearId (void )

Description Clears the trace ID of the calling thread and invalidates it.

This API clears the HiTraceId instance in the TLS of the calling thread.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 12

OH_HiTrace_CountTrace()

void OH_HiTrace_CountTrace (const char * name, int64_t count )

Description Traces the value change of an integer variable based on its name.

This API can be executed for multiple times to trace the value change of a given integer variable at different time points.

Since API version 19, you are advised to use the OH_HiTrace_CountTraceEx API to specify the trace output level.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 10

Parameters

NameDescription
nameName of the integer variable. It does not need to be the same as the real variable name.
countInteger value.

OH_HiTrace_CountTraceEx()

void OH_HiTrace_CountTraceEx (HiTrace_Output_Level level, const char * name, int64_t count )

Description Marks an integer variable trace task with the trace output level specified.

Since: 19

Parameters

NameDescription
levelTrace output level.
nameName of the integer variable. It does not need to be the same as the actual variable name.
countInteger value.

OH_HiTrace_CreateSpan()

HiTraceId OH_HiTrace_CreateSpan (void )

Description Creates a span ID based on the trace ID of the calling thread.

This API generates a new span and corresponding HiTraceId instance based on the HiTraceId instance in the TLS of the calling thread.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 12

Returns

Returns a valid span trace ID. For details, see HiTraceId. If the span ID cannot be created, the ID of the calling thread is traced.

OH_HiTrace_EnableFlag()

void OH_HiTrace_EnableFlag (const HiTraceId * id, HiTrace_Flag flag )

Description Enables the specified trace flag in a HiTraceId instance.

Sets trace flags in a HiTraceId instance.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 12

Parameters

NameDescription
idThe trace ID for which the flag needs to be enabled. For details, see HiTraceId.
flagThe specified trace flag needs to be enabled in the trace ID. For details, see HiTrace_Flag.

OH_HiTrace_EndChain()

void OH_HiTrace_EndChain ()

Description 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.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 12

OH_HiTrace_FinishAsyncTrace()

void OH_HiTrace_FinishAsyncTrace (const char * name, int32_t taskId )

Description Marks the end of an asynchronous trace.

This API is called in the callback function after an asynchronous trace is complete.

It is used with OH_HiTrace_StartAsyncTrace in pairs. Its name and task ID must be the same as those of OH_HiTrace_StartAsyncTrace.

Since API version 19, you are advised to use the OH_HiTrace_FinishAsyncTraceEx API to specify the trace output level.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 10

Parameters

NameDescription
nameName of the asynchronous trace.
taskIdID of the asynchronous trace. The start and end of an asynchronous trace task do not occur in sequence. Therefore, the start and end of an asynchronous trace need to be matched based on the task name and the unique task ID together.

OH_HiTrace_FinishAsyncTraceEx()

void OH_HiTrace_FinishAsyncTraceEx (HiTrace_Output_Level level, const char * name, int32_t taskId )

Description Marks the end of an asynchronous trace task with the trace output level specified.

This API is used to stop tracing after an asynchronous operation is complete, for example, in a callback function.

It is used with OH_HiTrace_StartAsyncTraceEx in pairs. Its level, name and task ID must be the same as those of OH_HiTrace_StartAsyncTraceEx.

Since: 19

Parameters

NameDescription
levelTrace output level.
nameName of the asynchronous trace.
taskIdID of the asynchronous trace.

OH_HiTrace_FinishTrace()

void OH_HiTrace_FinishTrace (void )

Description Marks the end of a synchronous trace.

This API must be used with OH_HiTrace_StartTrace in pairs. During trace parsing, the system matches it with the OH_HiTrace_StartTrace API recently invoked in the service process.

Since API version 19, you are advised to use the OH_HiTrace_FinishTraceEx API to specify the trace output level.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 10

OH_HiTrace_FinishTraceEx()

void OH_HiTrace_FinishTraceEx (HiTrace_Output_Level level)

Description Marks the end of a synchronous trace task with the trace output level specified.

It must be used with OH_HiTrace_StartTraceEx in pairs. Its level must be the same as those of OH_HiTrace_StartTraceEx.

During trace data parsing, the system matches it with the OH_HiTrace_StartTraceEx API recently invoked in the service process.

Since: 19

Parameters

NameDescription
levelTrace output level.

OH_HiTrace_GetChainId()

uint64_t OH_HiTrace_GetChainId (const HiTraceId * id)

Description Obtains a trace chain ID.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 12

Parameters

NameDescription
idHiTraceId instance for which you want to obtain the trace chain ID. For details, see HiTraceId.

Returns

Returns the trace chain ID of the specified HiTraceId instance.

OH_HiTrace_GetFlags()

int OH_HiTrace_GetFlags (const HiTraceId * id)

Description Obtains the trace flags in a HiTraceId instance.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 12

Parameters

NameDescription
idHiTraceId instance for which you want to obtain the flag. For details, see HiTraceId.

Returns

Returns the trace flags set in the specified HiTraceId instance.

OH_HiTrace_GetId()

HiTraceId OH_HiTrace_GetId ()

Description Obtains the trace ID of the calling thread. If the calling thread does not have a trace ID, an invalid trace ID is returned.

Obtains the trace ID in TLS of the calling thread.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 12

Returns

Returns the HiTraceId of the calling thread. Returns an invalid HiTraceId if the calling thread does not have a HiTraceId.

OH_HiTrace_GetParentSpanId()

uint64_t OH_HiTrace_GetParentSpanId (const HiTraceId * id)

Description Obtains the parent span ID in a HiTraceId instance.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 12

Parameters

NameDescription
idHiTraceId instance for which you want to obtain the parent span ID. For details, see HiTraceId.

Returns

Returns the parent span ID in the specified HiTraceId instance.

OH_HiTrace_GetSpanId()

uint64_t OH_HiTrace_GetSpanId (const HiTraceId * id)

Description Obtains the span ID in a HiTraceId instance.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 12

Parameters

NameDescription
idHiTraceId instance for which you want to obtain the span ID. For details, see HiTraceId.

Returns

Returns the span ID in the specified HiTraceId instance.

OH_HiTrace_IdFromBytes()

void OH_HiTrace_IdFromBytes (HiTraceId * id, const uint8_t * pIdArray, int len )

Description Creates a HiTraceId instance based on a byte array.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 12

Parameters

NameDescription
idHiTraceId instance to create.
pIdArrayByte array.
lenLength of the byte array.

OH_HiTrace_IdToBytes()

int OH_HiTrace_IdToBytes (const HiTraceId * id, uint8_t * pIdArray, int len )

Description Converts a HiTraceId instance into a byte array for caching or transfer.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 12

Parameters

NameDescription
idHiTraceId instance to convert. For details, see HiTraceId.
pIdArrayByte array.
lenLength of the byte array.

Returns

Returns the length of the byte array after conversion.

OH_HiTrace_InitId()

void OH_HiTrace_InitId (HiTraceId * id)

Description Initializes a HiTraceId instance.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 12

Parameters

NameDescription
idHiTraceId instance to initialize.

OH_HiTrace_IsFlagEnabled()

bool OH_HiTrace_IsFlagEnabled (const HiTraceId * id, HiTrace_Flag flag )

Description Checks whether the specified trace flag is enabled in a HiTraceId instance.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 12

Parameters

NameDescription
idHiTraceId instance to check. For details, see HiTraceId.
flagSpecified trace flag. For details, see HiTrace_Flag.

Returns

Returns true if the specified trace flag is enabled; returns false otherwise.

OH_HiTrace_IsIdValid()

bool OH_HiTrace_IsIdValid (const HiTraceId * id)

Description Checks whether a HiTraceId instance is valid.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 12

Parameters

NameDescription
idHiTraceId instance to check. For details, see HiTraceId.

Returns

Returns true if the HiTraceId instance is valid; returns false otherwise.

OH_HiTrace_IsTraceEnabled()

bool OH_HiTrace_IsTraceEnabled (void )

Description Checks whether trace capture is enabled for an application. If not, HiTraceMeter performance tracing is invalid.

Since: 19

Returns

Returns true if the application trace capture is enabled and the HiTraceMeter performance tracing takes effect;

returns false otherwise.

OH_HiTrace_SetChainId()

void OH_HiTrace_SetChainId (HiTraceId * id, uint64_t chainId )

Description Sets the trace chain ID in a HiTraceId instance.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 12

Parameters

NameDescription
idHiTraceId instance. For details, see HiTraceId.
chainIdTrace chain ID to set.

OH_HiTrace_SetFlags()

void OH_HiTrace_SetFlags (HiTraceId * id, int flags )

Description Sets trace flags in a HiTraceId instance.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 12

Parameters

NameDescription
idHiTraceId instance. For details, see HiTraceId.
flagsTrace flag to set. For details, see HiTrace_Flag.

OH_HiTrace_SetId()

void OH_HiTrace_SetId (const HiTraceId * id)

Description Sets the trace ID of the calling thread. If the ID is invalid, no operation is performed.

This API sets a HiTraceId instance to the TLS of the calling thread.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 12

Parameters

NameDescription
idTrace ID of the calling thread. For details, see HiTraceId.

OH_HiTrace_SetParentSpanId()

void OH_HiTrace_SetParentSpanId (HiTraceId * id, uint64_t parentSpanId )

Description Sets the ParentSpanId in a HiTraceId instance.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 12

Parameters

NameDescription
idHiTraceId instance. For details, see HiTraceId.
parentSpanIdParent span ID to set.

OH_HiTrace_SetSpanId()

void OH_HiTrace_SetSpanId (HiTraceId * id, uint64_t spanId )

Description Sets the span ID in a HiTraceId instance.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 12

Parameters

NameDescription
idHiTraceId instance for which you want to set the span ID.
spanIdSpan ID to set.

OH_HiTrace_StartAsyncTrace()

void OH_HiTrace_StartAsyncTrace (const char * name, int32_t taskId )

Description Marks the start of an asynchronous trace.

This API is used to start tracing before an asynchronous operation. The start and end of an asynchronous trace do not occur in sequence. Therefore, a unique task ID is required to identify them.

It must be used with OH_HiTrace_FinishAsyncTrace in pairs. The start and end identified by the same name and task ID constitute an asynchronous trace task.

If multiple trace tasks with the same name need to be performed at the same time or a trace task needs to be performed multiple times concurrently, different task IDs must be specified.

If the trace tasks with the same name are not performed at the same time, the same taskId can be used.

Since API version 19, you are advised to use the OH_HiTrace_StartAsyncTraceEx API to specify the trace output level and category.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 10

Parameters

NameDescription
nameName of the asynchronous trace.
taskIdID of the asynchronous trace. The start and end of an asynchronous trace task do not occur in sequence. Therefore, the start and end of an asynchronous trace need to be matched based on the task name and the unique task ID together.

OH_HiTrace_StartAsyncTraceEx()

void OH_HiTrace_StartAsyncTraceEx (HiTrace_Output_Level level, const char * name, int32_t taskId, const char * customCategory, const char * customArgs )

Description Marks the start of an asynchronous trace task with the trace output level specified.

This API is used to start tracing before an asynchronous operation. The start and end of an asynchronous trace do not occur in sequence. Therefore, a unique task ID is required to identify them.

It is used with OH_HiTrace_FinishAsyncTraceEx in pairs. The start and end identified by the same name and task ID constitute an asynchronous trace task.

If multiple trace tasks with the same name need to be performed at the same time or a trace task needs to be performed multiple times concurrently, different task IDs must be specified.

If the trace tasks with the same name are not performed at the same time, the same taskId can be used.

Task IDs of different processes does not interfere with each other.

Since: 19

Parameters

NameDescription
levelTrace output level.
nameName of the asynchronous trace.
taskIdID of the asynchronous trace.
customCategoryCustom category name, which is used to collect asynchronous trace data of the same type.
customArgsKey-value pair. Use commas (,) to separate multiple key-value pairs, for example, "key1=value1,key2=value2".

OH_HiTrace_StartTrace()

void OH_HiTrace_StartTrace (const char * name)

Description Marks the start of a synchronous trace.

This API is used with OH_HiTrace_FinishTrace in pairs.

The two APIs can be nested. The stack data structure is used for matching during trace parsing.

Since API version 19, you are advised to use the OH_HiTrace_StartTraceEx API to specify the trace output level.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 10

Parameters

NameDescription
nameName of a synchronous trace.

OH_HiTrace_StartTraceEx()

void OH_HiTrace_StartTraceEx (HiTrace_Output_Level level, const char * name, const char * customArgs )

Description Marks the start of a synchronous trace task with the trace output level specified.

This API is used with OH_HiTrace_FinishTraceEx in pairs.

The two APIs can be nested. The stack data structure is used for matching during trace parsing.

Since: 19

Parameters

NameDescription
levelTrace output level.
nameName of a synchronous trace.
customArgsKey-value pair. Use commas (,) to separate multiple key-value pairs, for example, "key1=value1,key2=value2".

OH_HiTrace_Tracepoint()

void OH_HiTrace_Tracepoint (HiTrace_Communication_Mode mode, HiTrace_Tracepoint_Type type, const HiTraceId * id, const char * fmt,  ... )

Description Prints HiTrace information, including the trace ID.

This API prints trace point information, including the communication mode, trace point type, timestamp, and span.

System capability: SystemCapability.HiviewDFX.HiTrace

Since: 12

Parameters

NameDescription
modeCommunication mode for the trace point. For details, see HiTrace_Communication_Mode.
typeTrace point type. For details, see HiTrace_Tracepoint_Type.
idTrace ID. For details, see HiTraceId.
fmtCustom information to print.

Variable Description

chainId

uint64_t HiTraceId::chainId

Description Chain ID of HiTraceId.

flags

uint64_t HiTraceId::flags

Description Flag of HiTraceId.

parentSpanId

uint64_t HiTraceId::parentSpanId

Description Parent span ID of HiTraceId.

spanId

uint64_t HiTraceId::spanId

Description Span ID of HiTraceId.

valid

uint64_t HiTraceId::valid

Description Whether a HiTraceId instance is valid.

ver

uint64_t HiTraceId::ver

Description Version number of HiTraceId.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Performance Analysis Kit

harmony 鸿蒙Performance Analysis Kit

harmony 鸿蒙HiAppEvent

harmony 鸿蒙HiAppEvent_AppEventGroup

harmony 鸿蒙HiAppEvent_AppEventInfo

harmony 鸿蒙HiCollie

harmony 鸿蒙HiCollie_DetectionParam

harmony 鸿蒙HiCollie_SetTimerParam

harmony 鸿蒙HiDebug

harmony 鸿蒙HiDebug_MemoryLimit

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/LW1nkF