1e41f4b71Sopenharmony_ci# HiCollie
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ci## Overview
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ciHiCollie provides APIs for detecting service thread stuck and jank events and reporting service thread stuck events.
7e41f4b71Sopenharmony_ci
8e41f4b71Sopenharmony_ci**Since**: 12
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci## Summary
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci### Files
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci| Name| Description|
17e41f4b71Sopenharmony_ci| -------- | -------- |
18e41f4b71Sopenharmony_ci| [hicollie.h](hicollie_8h.md) | Defines APIs for debugging.|
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci### Structs
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci| Name| Description|
24e41f4b71Sopenharmony_ci| -------- | -------- |
25e41f4b71Sopenharmony_ci| struct  [HiCollie_DetectionParam](_hi_hicollie___detection_param.md) | Defines the parameters of the jank event detection.|
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ci### Types
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci| Name| Description|
31e41f4b71Sopenharmony_ci| -------- | -------- |
32e41f4b71Sopenharmony_ci| typedef enum [HiCollie_ErrorCode](errorcode-hiviewdfx-hicollie.md) [HiCollie_ErrorCode](#hicollie_errorcode) | Defines an enum for error codes.| 
33e41f4b71Sopenharmony_ci| typedef void(\* [OH_HiCollie_Task](#oh_hicollie_task)) (void) | Defines the pointer to the user-defined callback. This callback is used to periodically check the processing event on the application service thread.| 
34e41f4b71Sopenharmony_ci| typedef void(\* [OH_HiCollie_BeginFunc](#oh_hicollie_beginfunc)) (const char \*name) | Defines the pointer to the user-defined callback. This callback is used before the service thread processes the event.| 
35e41f4b71Sopenharmony_ci| typedef void(\* [OH_HiCollie_EndFunc](#oh_hicollie_endfunc)) (const char \*name) | Defines the pointer to the user-defined callback. This callback is used after the service thread processed the event.| 
36e41f4b71Sopenharmony_ci| typedef struct [HiCollie_DetectionParam](_hi_hicollie___detection_param.md) [HiCollie_DetectionParam](#hicollie_detectionparam) | Defines a struct for the parameters of the user-defined jank event detection.| 
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci## Type Description
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci### HiCollie_ErrorCode
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci```
45e41f4b71Sopenharmony_citypedef enum HiCollie_ErrorCode HiCollie_ErrorCode
46e41f4b71Sopenharmony_ci```
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_ci**Description**
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_ciDefines an enum for error codes.
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_ci**Since**: 12
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ci### OH_HiCollie_Task
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ci```
58e41f4b71Sopenharmony_citypedef void (*OH_HiCollie_Task)(void)
59e41f4b71Sopenharmony_ci```
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ci**Description**
62e41f4b71Sopenharmony_ci
63e41f4b71Sopenharmony_ciDefines the pointer to the user-defined callback for the stuck event detection. This callback is used to periodically check whether the processing event on the service thread is stuck.
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_ci**Since**: 12
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ci### OH_HiCollie_BeginFunc
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci```
71e41f4b71Sopenharmony_citypedef void (*OH_HiCollie_BeginFunc)(const char* eventName)
72e41f4b71Sopenharmony_ci```
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci**Description**
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ciDefines the pointer to the user-defined callback for the jank event detection. This callback is used before the service thread processes the event to record the start time of the processing event.
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci**Since**: 12
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ci### OH_HiCollie_EndFunc
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci```
84e41f4b71Sopenharmony_citypedef void (*OH_HiCollie_EndFunc)(const char* eventName)
85e41f4b71Sopenharmony_ci```
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ci**Description**
88e41f4b71Sopenharmony_ci
89e41f4b71Sopenharmony_ciDefines the pointer to the user-defined callback for the jank event detection. This callback is used after the service thread processed the event to check whether the thread is jank.
90e41f4b71Sopenharmony_ci
91e41f4b71Sopenharmony_ci**Since**: 12
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci### HiCollie_DetectionParam
95e41f4b71Sopenharmony_ci
96e41f4b71Sopenharmony_ci```
97e41f4b71Sopenharmony_citypedef struct HiCollie_DetectionParam HiCollie_DetectionParam
98e41f4b71Sopenharmony_ci```
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ci**Description**
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ciDefines the pointer to the parameters of the user-defined jank event detection, such as the threshold of the jank event.
103e41f4b71Sopenharmony_ci
104e41f4b71Sopenharmony_ci**Since**: 12
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ci
107e41f4b71Sopenharmony_ci### Functions
108e41f4b71Sopenharmony_ci
109e41f4b71Sopenharmony_ci| Name| Description| 
110e41f4b71Sopenharmony_ci| -------- | -------- |
111e41f4b71Sopenharmony_ci| HiCollie_ErrorCode [OH_HiCollie_Init_StuckDetection](_hi_hicollie.md#oh_hicollie_init_stuckdetection) (OH_HiCollie_Task task) | Registers a callback to periodically detect service thread stuck events. | 
112e41f4b71Sopenharmony_ci| HiCollie_ErrorCode [OH_HiCollie_Init_JankDetection](_hi_hicollie.md#oh_hicollie_init_jankdetection) (OH_HiCollie_BeginFunc\* beginFunc, OH_HiCollie_EndFunc\* endFunc, HiCollie_DetectionParam param) | Registers a callback to detect service thread jank events. | 
113e41f4b71Sopenharmony_ci| HiCollie_ErrorCode [OH_HiCollie_Report](_hi_hicollie.md#oh_hicollie_report) (bool\* isSixSecond) | Reports service thread stuck events and generates timeout logs to help locate application timeout events. This API is used together with **OH_HiCollie_Init_StuckDetection()**, which initializes the stuck event detection at first, and then **OH_HiCollie_Report()** reports the stuck event when it occurs. | 
114e41f4b71Sopenharmony_ci
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_ci## Function Description
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci
119e41f4b71Sopenharmony_ci### OH_HiCollie_Init_StuckDetection
120e41f4b71Sopenharmony_ci
121e41f4b71Sopenharmony_ci```
122e41f4b71Sopenharmony_ciHiCollie_ErrorCode OH_HiCollie_Init_StuckDetection(OH_HiCollie_Task task)
123e41f4b71Sopenharmony_ci```
124e41f4b71Sopenharmony_ci
125e41f4b71Sopenharmony_ci**Description**
126e41f4b71Sopenharmony_ci
127e41f4b71Sopenharmony_ciRegisters a callback to periodically detect service thread stuck events.
128e41f4b71Sopenharmony_ci
129e41f4b71Sopenharmony_ci**Since**: 12
130e41f4b71Sopenharmony_ci
131e41f4b71Sopenharmony_ci**Parameters**
132e41f4b71Sopenharmony_ci
133e41f4b71Sopenharmony_ci| Name| Description|
134e41f4b71Sopenharmony_ci| -------- | -------- |
135e41f4b71Sopenharmony_ci| task | Callback used to periodically check whether the service thread is stuck. If you want to cancel the detection, pass a null pointer.|
136e41f4b71Sopenharmony_ci
137e41f4b71Sopenharmony_ci
138e41f4b71Sopenharmony_ci**Returns**
139e41f4b71Sopenharmony_ci
140e41f4b71Sopenharmony_ci Returns **0** if the stuck event detection is successfully initialized.
141e41f4b71Sopenharmony_ci
142e41f4b71Sopenharmony_ci
143e41f4b71Sopenharmony_ci### OH_HiCollie_Init_JankDetection
144e41f4b71Sopenharmony_ci
145e41f4b71Sopenharmony_ci```
146e41f4b71Sopenharmony_ciHiCollie_ErrorCode OH_HiCollie_Init_JankDetection(OH_HiCollie_BeginFunc* beginFunc, OH_HiCollie_EndFunc* endFunc, HiCollie_DetectionParam param);
147e41f4b71Sopenharmony_ci
148e41f4b71Sopenharmony_ci```
149e41f4b71Sopenharmony_ci
150e41f4b71Sopenharmony_ci**Description**
151e41f4b71Sopenharmony_ci
152e41f4b71Sopenharmony_ciRegisters a callback to detect service thread jank events. To monitor thread jank events, you can implement two callbacks as instrumentation functions, placing them before and after the service thread processes the event.  
153e41f4b71Sopenharmony_ci
154e41f4b71Sopenharmony_ci**Since**: 12
155e41f4b71Sopenharmony_ci
156e41f4b71Sopenharmony_ci**Parameters**
157e41f4b71Sopenharmony_ci
158e41f4b71Sopenharmony_ci| Name| Description|
159e41f4b71Sopenharmony_ci| -------- | -------- |
160e41f4b71Sopenharmony_ci| beginFunc | Callback used before the service thread processes the event. If you want to cancel the detection, pass a null pointer to **beginFunc** and **endFunc**.|
161e41f4b71Sopenharmony_ci| endFunc | Callback used after the service thread processed the event. If you want to cancel the detection, pass a null pointer to **beginFunc** and **endFunc**.|
162e41f4b71Sopenharmony_ci| param | Parameters of the user-defined jank event detection. Extended parameters for future development use. For details, see [HiCollie_DetectionParam](_hi_hicollie___detection_param.md).|
163e41f4b71Sopenharmony_ci
164e41f4b71Sopenharmony_ci**Returns**
165e41f4b71Sopenharmony_ci
166e41f4b71Sopenharmony_ci Returns **0** if the jank event detection is successfully initialized.
167e41f4b71Sopenharmony_ci
168e41f4b71Sopenharmony_ci
169e41f4b71Sopenharmony_ci### OH_HiCollie_Report
170e41f4b71Sopenharmony_ci
171e41f4b71Sopenharmony_ci```
172e41f4b71Sopenharmony_ciHiCollie_ErrorCode OH_HiCollie_Report(bool* isSixSecond);
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_ci```
175e41f4b71Sopenharmony_ci
176e41f4b71Sopenharmony_ci**Description**
177e41f4b71Sopenharmony_ci
178e41f4b71Sopenharmony_ciReports service thread stuck events and generates timeout logs to help locate application timeout events. This API is used together with **OH_HiCollie_Init_StuckDetection()**, which initializes the stuck event detection at first, and then **OH_HiCollie_Report()** reports the stuck event when it occurs.
179e41f4b71Sopenharmony_ci
180e41f4b71Sopenharmony_ci**Since**: 12
181e41f4b71Sopenharmony_ci
182e41f4b71Sopenharmony_ci**Parameters**
183e41f4b71Sopenharmony_ci
184e41f4b71Sopenharmony_ci| Name| Description|
185e41f4b71Sopenharmony_ci| -------- | -------- |
186e41f4b71Sopenharmony_ci| isSixSecond | Pointer to the boolean variable, whose value is **true** when the service thread is stuck for 6s. If the service thread is stuck for 3s, the value is **false**.|
187e41f4b71Sopenharmony_ci
188e41f4b71Sopenharmony_ci
189e41f4b71Sopenharmony_ci**Returns**
190e41f4b71Sopenharmony_ci
191e41f4b71Sopenharmony_ci Returns **0** if the stuck event reporting function is successfully initialized.
192