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<a name="section139261151145116"></a>
<tdclass="cellrowborder"valign="top"width="44.47555244475552%"headers="mcps1.2.4.1.3 "><pid="p18700175062115"><aname="p18700175062115"></a><aname="p18700175062115"></a>Provides the callback of the suspension detection result.</p>
<tdclass="cellrowborder"valign="top"width="44.47555244475552%"headers="mcps1.2.4.1.3 "><pid="p127630177475"><aname="p127630177475"></a><aname="p127630177475"></a>Provides the callback of the thread suspension detection result.</p>
<tdclass="cellrowborder"valign="top"width="35.82641735826417%"headers="mcps1.2.4.1.2 "><pid="p16289114074812"><aname="p16289114074812"></a><aname="p16289114074812"></a>void RegisterXCollieChecker(const sptr<XCollieChecker>&checker, unsigned int type)</p>
</td>
<tdclass="cellrowborder"valign="top"width="44.47555244475552%"headers="mcps1.2.4.1.3 "><pid="p186437319482"><aname="p186437319482"></a><aname="p186437319482"></a>Registers the callback of the thread suspension detection result.</p>
<aname="ul7783192181413"></a><aname="ul7783192181413"></a><ulid="ul7783192181413"><li><strongid="b64637561712"><aname="b64637561712"></a><aname="b64637561712"></a>checker</strong>: Indicates the pointer to the XCollieChecker instance.</li><li><strongid="b1947711661711"><aname="b1947711661711"></a><aname="b1947711661711"></a>type</strong>: Indicates the suspension detection type. Set it to <strongid="b259214119717"><aname="b259214119717"></a><aname="b259214119717"></a>XCOLLIE_THREAD</strong>.</li></ul>
<aname="ul845512153147"></a><aname="ul845512153147"></a><ulid="ul845512153147"><li><strongid="b44651010141715"><aname="b44651010141715"></a><aname="b44651010141715"></a>name</strong>: Indicates the timer name.</li><li><strongid="b266981221717"><aname="b266981221717"></a><aname="b266981221717"></a>timeout</strong>: Indicates the timeout duration, in seconds.</li><li><strongid="b17158171421710"><aname="b17158171421710"></a><aname="b17158171421710"></a>func</strong>: Indicates the timeout callback.</li><li><strongid="b1950162581810"><aname="b1950162581810"></a><aname="b1950162581810"></a>arg</strong>: Indicates the pointer to the timeout callback.</li><li><strongid="b4949151521714"><aname="b4949151521714"></a><aname="b4949151521714"></a>flag</strong>: Indicates the timer operation type.<pid="p1242762435310"><aname="p1242762435310"></a><aname="p1242762435310"></a>XCOLLIE_FLAG_DEFAULT // Indicates the default flag, which is the combination of the other three options.</p>
<pid="p1542712435312"><aname="p1542712435312"></a><aname="p1542712435312"></a>XCOLLIE_FLAG_NOOP // Calls only the timeout callback.</p>
<pid="p15427112416531"><aname="p15427112416531"></a><aname="p15427112416531"></a>XCOLLIE_FLAG_LOG // Generates a timeout fault log.</p>
<pid="p242762455314"><aname="p242762455314"></a><aname="p242762455314"></a>XCOLLIE_FLAG_RECOVERY // Exits the process.</p>
<pid="p144271424155316"><aname="p144271424155316"></a><aname="p144271424155316"></a>Return value: Returns the timer ID if the operation is successful; returns <strongid="b2229713291"><aname="b2229713291"></a><aname="b2229713291"></a>-1</strong> otherwise.</p>
<aname="ul1628783221411"></a><aname="ul1628783221411"></a><ulid="ul1628783221411"><li><strongid="b61651021161710"><aname="b61651021161710"></a><aname="b61651021161710"></a>id</strong>: Indicates the timer ID.</li><li><strongid="b24661423141717"><aname="b24661423141717"></a><aname="b24661423141717"></a>timeout</strong>: Indicates the timeout duration, in seconds.</li></ul>
<pid="p38311853105716"><aname="p38311853105716"></a><aname="p38311853105716"></a>Return value: Returns <strongid="b95701352192819"><aname="b95701352192819"></a><aname="b95701352192819"></a>true</strong> if the operation is successful; returns <strongid="b175761652152814"><aname="b175761652152814"></a><aname="b175761652152814"></a>false</strong> otherwise.</p>
<pid="p9311488283"><aname="p9311488283"></a><aname="p9311488283"></a><strongid="b9666749171816"><aname="b9666749171816"></a><aname="b9666749171816"></a>id</strong>: Indicates the timer ID.</p>
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.
1. 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");
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.
1. Develop the source code.
Include the **xcollie** header file in the source file.
# Development Guidelines on HiLog\_Lite<a name="EN-US_TOPIC_0000001089263241"></a>
# Development Guidelines on HiLog\_Lite<a name="EN-US_TOPIC_0000001185815838"></a>
-[Overview](#section775017517390)
-[Available APIs](#section114412157402)
...
...
@@ -6,7 +6,7 @@
## Overview<a name="section775017517390"></a>
HiLog\_Lite is the HiLog framework for Mini-System Devices \(reference memory ≥ 128 KB\) and Small-System Devices \(reference memory ≥ 1 MB\). It implements functions such as log printing, log output, and flow control.
HiLog\_Lite is the HiLog framework for Mini-System Devices \(reference memory ≥ 128 KiB\) and Small-System Devices \(reference memory ≥ 1 MiB\). It implements functions such as log printing, log output, and flow control.
## Available APIs<a name="section114412157402"></a>
HiSysEvent supports listening for events across processes. You can register a listener to listen for concerned events on a real-time basis. For example, you can enable the battery module to listen for power consumption event for power usage analysis.
## Available APIs<a name="section0342191810519"></a>
<tdclass="cellrowborder"valign="top"width="51.88%"headers="mcps1.2.3.1.2 "><pid="p14727325133216"><aname="p14727325133216"></a><aname="p14727325133216"></a>Registers a listener for system events. You can listen for certain events by specifying rules.</p>
<aname="ul6717142214919"></a><aname="ul6717142214919"></a><ulid="ul6717142214919"><li><strongid="b5330432115819"><aname="b5330432115819"></a><aname="b5330432115819"></a>listener</strong>: callback object for system events.</li><li><strongid="b1518805912597"><aname="b1518805912597"></a><aname="b1518805912597"></a>rules</strong>: rules for event listening.</li></ul>
<aname="ul12105842111913"></a><aname="ul12105842111913"></a><ulid="ul12105842111913"><li><strongid="b117641849702"><aname="b117641849702"></a><aname="b117641849702"></a>0</strong>: Repeated registration is successful.</li><li><strongid="b2682415314"><aname="b2682415314"></a><aname="b2682415314"></a>1</strong>: Initial registration is successful.</li><li>Other values: Registration has failed.</li></ul>
<tdclass="cellrowborder"valign="top"width="51.88%"headers="mcps1.2.3.1.2 "><pid="p1104194420248"><aname="p1104194420248"></a><aname="p1104194420248"></a>Removes the listener for system events.</p>
<aname="ul894321075411"></a><aname="ul894321075411"></a><ulid="ul894321075411"><li><strongid="b178371510181317"><aname="b178371510181317"></a><aname="b178371510181317"></a>listener</strong>: callback object for system events.</li></ul>
<tdclass="cellrowborder"valign="top"width="51.89%"headers="mcps1.2.3.1.2 "><pid="p94416160565"><aname="p94416160565"></a><aname="p94416160565"></a>Rule type. The matching scope includes <strongid="b638713414175"><aname="b638713414175"></a><aname="b638713414175"></a>domain</strong> and <strongid="b128648618171"><aname="b128648618171"></a><aname="b128648618171"></a>eventName</strong>. The value can be any of the following:</p>
<tdclass="cellrowborder"valign="top"width="51.89%"headers="mcps1.2.3.1.2 "><aname="ul14905926102311"></a><aname="ul14905926102311"></a><ulid="ul14905926102311"><li><strongid="b152431514132110"><aname="b152431514132110"></a><aname="b152431514132110"></a>domain</strong>: domain to which the event belongs. By default, an empty string indicates that the domain is successfully matched.</li></ul>
<tdclass="cellrowborder"valign="top"width="51.89%"headers="mcps1.2.3.1.2 "><aname="ul248063132319"></a><aname="ul248063132319"></a><ulid="ul248063132319"><li><strongid="b197622401229"><aname="b197622401229"></a><aname="b197622401229"></a>eventName</strong>: event name. By default, an empty string indicates that the event name is successfully matched.</li></ul>
<tdclass="cellrowborder"valign="top"width="51.74999999999999%"headers="mcps1.2.3.1.2 "><pid="p1772213111011"><aname="p1772213111011"></a><aname="p1772213111011"></a>Callback object for system events.</p>
HiSysEvent provides an API for you to query system events. You can query concerned events by specifying search criteria. For example, for a power consumption module, you can query required system events for analysis.
## Available APIs<a name="section03869128521"></a>
<tdclass="cellrowborder"valign="top"width="51.88%"headers="mcps1.2.3.1.2 "><pid="p14727325133216"><aname="p14727325133216"></a><aname="p14727325133216"></a>Queries system events by specifying search criteria such as the time segment, event domain, and event name.</p>
<tbody><trid="row3784451122012"><tdclass="cellrowborder"valign="top"width="47.85%"headers="mcps1.2.3.1.1 "><pid="p2078414512209"><aname="p2078414512209"></a><aname="p2078414512209"></a>long long beginTime</p>
<trid="row1564913158230"><tdclass="cellrowborder"valign="top"width="47.85%"headers="mcps1.2.3.1.1 "><pid="p11649191511239"><aname="p11649191511239"></a><aname="p11649191511239"></a>long long endTime</p>
<tdclass="cellrowborder"valign="top"width="52.15%"headers="mcps1.2.3.1.2 "><pid="p1161901214232"><aname="p1161901214232"></a><aname="p1161901214232"></a>Maximum number of query records.</p>
<tdclass="cellrowborder"valign="top"width="51.970000000000006%"headers="mcps1.2.3.1.2 "><pid="p94416160565"><aname="p94416160565"></a><aname="p94416160565"></a>Rule type. The default value is <strongid="b196007205817"><aname="b196007205817"></a><aname="b196007205817"></a>0</strong>.</p>
<tdclass="cellrowborder"valign="top"width="51.970000000000006%"headers="mcps1.2.3.1.2 "><aname="ul14905926102311"></a><aname="ul14905926102311"></a><ulid="ul14905926102311"><li><strongid="b9813231789"><aname="b9813231789"></a><aname="b9813231789"></a>domain</strong>: domain to which the event belongs. By default, an empty string indicates that the domain is successfully matched.</li></ul>
<tdclass="cellrowborder"valign="top"width="51.970000000000006%"headers="mcps1.2.3.1.2 "><aname="ul248063132319"></a><aname="ul248063132319"></a><ulid="ul248063132319"><li><strongid="b172129351784"><aname="b172129351784"></a><aname="b172129351784"></a>eventList</strong>: event name list. By default, an empty string indicates that the event names on the list are successfully matched.</li></ul>
<tdclass="cellrowborder"valign="top"width="51.970000000000006%"headers="mcps1.2.3.1.2 "><pid="p126315352130"><aname="p126315352130"></a><aname="p126315352130"></a>Callback object for completion of event query.</p>
<aname="ul106383518130"></a><aname="ul106383518130"></a><ulid="ul106383518130"><li><strongid="b855743017177"><aname="b855743017177"></a><aname="b855743017177"></a>reason</strong>: reason for completion of event query. The default value is <strongid="b5175337111718"><aname="b5175337111718"></a><aname="b5175337111718"></a>0</strong>.</li><li><strongid="b1196583151911"><aname="b1196583151911"></a><aname="b1196583151911"></a>total</strong>: total number of events returned in this query.</li></ul>
The HiSysEvent tool is a command line tool preconfigured in the system. You can specify search criteria to query system events that meet your requirement. Using this tool, you can debug event logging during development or query system events for fault locating.
## Usage<a name="section1210623418527"></a>
1. Run the HiSysEvent tool.
The tool is preconfigured in the **/system/bin** directory. You can run the following command in any directory:
In the preceding command, parameters **-s** and **-e** specify the start time and end time, respectively. If **-s** or **-e** is not specified, there is no limitation for the start time or end time.
Parameter **-m** specifies the maximum number of event records that can be returned in this query.
The DFX subsystem provides the following functions:
- HiLog: Implements the logging function. It is applicable to Mini-System Devices \(reference memory ≥ 128 KB\) and Small-System Devices \(reference memory ≥ 1 MB\) as well as Standard-System Devices \(reference memory ≥ 128 MB\).
- HiLog: implements the logging function. It is applicable to Mini-System Devices \(reference memory ≥ 128 KiB\), Small-System Devices \(reference memory ≥ 1 MiB\), and Standard-System Devices \(reference memory ≥ 128 MB\).
- HiSysEvent: Implements system event logging. It is applicable to Standard-System Devices \(reference memory ≥ 128 MB\).
- HiTrace: implements distributed call chain tracing. It is applicable to Standard-System Devices \(reference memory ≥ 128 MB\).
- HiCollie: implements thread suspension detection. It is applicable to Standard-System Devices \(reference memory ≥ 128 MB\).
- HiSysEvent: implements system event logging. It is applicable to Standard-System Devices \(reference memory ≥ 128 MB\).