harmony 鸿蒙hicollie.h

  • 2025-06-12
  • 浏览 (5)

hicollie.h

Overview

HiCollie provides APIs for detecting service thread stuck and jank events and reporting stuck events.

Library: libohhicollie.so

System capability: SystemCapability.HiviewDFX.HiCollie

Since: 12

Related module: HiCollie

Summary

Structs

Name Description
struct  HiCollie_DetectionParam Defines the parameters of the jank event detection. Note that this struct is supported since API 12.
struct  HiCollie_SetTimerParam Defines the input parameters of the OH_HiCollie_SetTimer function.

Types

Name Description
typedef enum HiCollie_ErrorCode HiCollie_ErrorCode Defines an enum for the error codes used in the HiCollie module.
typedef void(* OH_HiCollie_Task) (void) Defines a function used to check whether a service thread is stuck.
This function is called by HiCollie every 3 seconds in an independent thread.
For example, this function can be used to send a message to a service thread and set a flag after the service thread receives the message. Then the flag is checked to determine whether the service thread is stuck.
typedef void(* OH_HiCollie_BeginFunc) (const char *eventName) Defines a function used to record the begin time when a service thread processes an event. This function is used in the jank event detection.
HiCollie checks the duration of each event. If the duration exceeds the preset threshold, a jank event is reported.
This function is inserted before each event is processed.
typedef void(* OH_HiCollie_EndFunc) (const char *eventName) Defines a function used to check whether a service thread is janky when processing an event. This function is used in the jank event detection.
HiCollie checks the duration of each event. If the duration exceeds the preset threshold, a jank event is reported.
This function is inserted after each event is processed.
typedef struct HiCollie_DetectionParam HiCollie_DetectionParam Defines a struct for the parameters of the jank event detection. Note that this type is supported since API 12.
typedef void(* OH_HiCollie_Callback) (void *) Defines a callback function to be executed when OH_HiCollie_CancelTimer is not called within the custom task timeout period after OH_HiCollie_SetTimer is called.
typedef enum HiCollie_Flag HiCollie_Flag Defines an enum for the executions to be performed when a function times out.
typedef struct HiCollie_SetTimerParam HiCollie_SetTimerParam Defines a struct for the input parameters of the OH_HiCollie_SetTimer function.

Enums

Name Description
HiCollie_ErrorCode {
HICOLLIE_SUCCESS = 0,
HICOLLIE_INVALID_ARGUMENT = 401,
HICOLLIE_WRONG_THREAD_CONTEXT = 29800001,
HICOLLIE_REMOTE_FAILED = 29800002,
HICOLLIE_INVALID_TIMER_NAME = 29800003,
HICOLLIE_INVALID_TIMEOUT_VALUE = 29800004,
HICOLLIE_WRONG_PROCESS_CONTEXT = 29800005,
HICOLLIE_WRONG_TIMER_ID_OUTPUT_PARAM = 29800006
}
Defines an enum for the error codes used in the HiCollie module.
HiCollie_Flag {
HICOLLIE_FLAG_DEFAULT = (~0),
HICOLLIE_FLAG_NOOP = (0),
HICOLLIE_FLAG_LOG = (1 << 0),
HICOLLIE_FLAG_RECOVERY = (1 << 1)
}
Defines an enum for the executions to be performed when a function times out.

Functions

Name Description
HiCollie_ErrorCode OH_HiCollie_Init_StuckDetection (OH_HiCollie_Task task) Registers a callback used to periodically detect service thread stuck events.
By default, the BUSSINESS_THREAD_BLOCK_3S event is reported when the thread is blocked for 3s and the BUSSINESS_THREAD_BLOCK_6S event is reported when the thread is blocked for 6s.
HiCollie_ErrorCode OH_HiCollie_Init_StuckDetectionWithTimeout (OH_HiCollie_Task task, uint32_t stuckTimeout) Registers a callback used to periodically detect service thread stuck events.
You can set the interval for the stuck event detection. The value range is [3, 15], in seconds.
HiCollie_ErrorCode OH_HiCollie_Init_JankDetection (OH_HiCollie_BeginFunc *beginFunc, OH_HiCollie_EndFunc *endFunc, HiCollie_DetectionParam param) Registers a callback used to detect service thread jank events.
To monitor service thread jank events, you can implement two callbacks as instrumentation functions, placing them before and after the service thread event.
HiCollie_ErrorCode OH_HiCollie_Report (bool *isSixSecond) Reports a service thread stuck event and generates logs to help locate application stuck issues.
Call OH_HiCollie_Init_StuckDetection() or OH_HiCollie_Init_StuckDetectionWithTimeout() to initialize the detection task.
If the task times out, call OH_HiCollie_Report() to report the stuck event based on the service logic.
HiCollie_ErrorCode OH_HiCollie_SetTimer (HiCollie_SetTimerParam param, int *id) Registers a timer to check whether the execution time of a function or code block exceeds the custom time.
This API is used together with the OH_HiCollie_CancelTimer API. It must be used before the time-consuming function is called.
void OH_HiCollie_CancelTimer (int id) Cancels a timer based on the ID.
This API is used together with the OH_HiCollie_SetTimer API. It must be used after the function or code block is executed.
If a timer is not canceled within the custom time, a callback function is executed to generate fault logs for the specified timeout event.

你可能感兴趣的鸿蒙文章

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

0  赞