HiCollie Development
Overview
HiCollie provides the software watchdog function. It provides a unified framework for fault detection and fault log generation to help you locate software timeout faults resulting from system service deadlock, application main thread blocking, and service process timeout.
Available APIs
Table 1 Description of C++ APIs
Example
Print logs.
timeout: TimeoutTimer start at 1611040305 to check 1s ago
----------StacktraceCatcher CurrentTime:2021-01-19 15:11:45 Unexecuted(-1)(LogType:Stacktrace Pid:27689 Process:XCollieTimeoutModuleTest)----------
----- pid 27689 at 2021-01-19 15:11:45 -----
Cmd line: ./XCollieTimeoutModuleTest
ABI: 'arm64'
"XCollieTimeoutM" sysTid=27689
#01 pc 00000000000174cc /data/test/XCollieTimeoutModuleTest
How to Develop
C++
Thread Suspension Monitoring
This function requires you to implement two callback functions: CheckBlock and CheckThreadBlock of the XCollieChecker class. After the callbacks are implemented, you need to use the RegisterXCollieChecker function of the XCollie class to register their instances. The suspension monitoring thread periodically executes all successfully registered callbacks, checks the thread logic completion flag, and determines whether the service logic of any registered thread is suspended.
-
Develop the source code.
Include the xcollie header file in the source file.
#include "xcollie.h"
Add the following code to the service code:
void MyXCollieChecker::CheckLock() { /* time consuming job */ } void MyXCollieChecker::CheckThreadBlock() { /* time consuming job */ } sptr<XCollieChecker> checker = new MyXCollieChecker("MyXCollieChecker"); XCollie::GetInstance().RegisterXCollieChecker(checker, (XCOLLIE_LOCK | XCOLLIE_THREAD)); ...
-
Configure compilation information. Specifically, add the subsystem SDK dependency to BUILD.gn.
external_deps = [ "hiviewdfx:libxcollie" ]
Timeout Monitoring
You can add a maximum of 128 timers for a single process by using the SetTimer function. Adding timers will fail if the number of timers has reached the upper limit.
-
Develop the source code.
Include the xcollie header file in the source file.
#include "xcollie.h"
Add the code to add, update, and cancel timers.
std::function<void(void *)> callback = [](void *args) { /* dump helpful information */ }; int id = XCollie::GetInstance().SetTimer("MyXCollieTimer", 10, callback ,nullptr, XCOLLIE_FLAG_LOG); /* time consuming job */ XCollie::GetInstance().UpdateTimer(id, 5); /* time consuming job */ XCollie::GetInstance().CancelTimer(id); ...
-
Configure compilation information. Specifically, add the subsystem SDK dependency to BUILD.gn.
external_deps = [ "hiviewdfx:libxcollie" ]