提交 2e101fb9 编写于 作者: D duangavin123

更新获取源码和dfx英文

Signed-off-by: Nduangavin123 <duanxichao@huawei.com>
上级 cc0366e3
# 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>
......
# HiCollie Development<a name="EN-US_TOPIC_0000001231255509"></a>
- [Overview](#section3432134085116)
- [Available APIs](#section139261151145116)
- [Example](#section1589120102458)
- [How to Develop](#section13905646534)
- [C++](#section9797199145316)
- [Thread Suspension Monitoring](#section1734221332)
- [Timeout Monitoring](#section2186947140)
## Overview<a name="section3432134085116"></a>
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>
**Table 1** Description of C++ APIs
<a name="table19452225011"></a>
<table><thead align="left"><tr id="row1517803543518"><th class="cellrowborder" valign="top" width="19.698030196980305%" id="mcps1.2.4.1.1"><p id="p484763319529"><a name="p484763319529"></a><a name="p484763319529"></a>Class</p>
</th>
<th class="cellrowborder" valign="top" width="35.82641735826417%" id="mcps1.2.4.1.2"><p id="p1684719339523"><a name="p1684719339523"></a><a name="p1684719339523"></a>API</p>
</th>
<th class="cellrowborder" valign="top" width="44.47555244475552%" id="mcps1.2.4.1.3"><p id="p284773315220"><a name="p284773315220"></a><a name="p284773315220"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row1361184632117"><td class="cellrowborder" valign="top" width="19.698030196980305%" headers="mcps1.2.4.1.1 "><p id="p6700155032113"><a name="p6700155032113"></a><a name="p6700155032113"></a>XCollieChecker</p>
</td>
<td class="cellrowborder" valign="top" width="35.82641735826417%" headers="mcps1.2.4.1.2 "><p id="p18699115019217"><a name="p18699115019217"></a><a name="p18699115019217"></a>virtual void CheckBlock()</p>
</td>
<td class="cellrowborder" valign="top" width="44.47555244475552%" headers="mcps1.2.4.1.3 "><p id="p18700175062115"><a name="p18700175062115"></a><a name="p18700175062115"></a>Provides the callback of the suspension detection result.</p>
<p id="p13700125012216"><a name="p13700125012216"></a><a name="p13700125012216"></a>Input arguments: none</p>
<p id="p13700650162114"><a name="p13700650162114"></a><a name="p13700650162114"></a>Output arguments: none</p>
<p id="p3700850192115"><a name="p3700850192115"></a><a name="p3700850192115"></a>Return value: none</p>
</td>
</tr>
<tr id="row8945182185017"><td class="cellrowborder" valign="top" width="19.698030196980305%" headers="mcps1.2.4.1.1 "><p id="p79451227506"><a name="p79451227506"></a><a name="p79451227506"></a>XCollieChecker</p>
</td>
<td class="cellrowborder" valign="top" width="35.82641735826417%" headers="mcps1.2.4.1.2 "><p id="p647534064612"><a name="p647534064612"></a><a name="p647534064612"></a>virtual void CheckThreadBlock()</p>
</td>
<td class="cellrowborder" valign="top" width="44.47555244475552%" headers="mcps1.2.4.1.3 "><p id="p127630177475"><a name="p127630177475"></a><a name="p127630177475"></a>Provides the callback of the thread suspension detection result.</p>
<p id="p18763111794719"><a name="p18763111794719"></a><a name="p18763111794719"></a>Input arguments: none</p>
<p id="p87631176478"><a name="p87631176478"></a><a name="p87631176478"></a>Output arguments: none</p>
<p id="p3764111718473"><a name="p3764111718473"></a><a name="p3764111718473"></a>Return value: none</p>
</td>
</tr>
<tr id="row149924222486"><td class="cellrowborder" valign="top" width="19.698030196980305%" headers="mcps1.2.4.1.1 "><p id="p11643173114810"><a name="p11643173114810"></a><a name="p11643173114810"></a>XCollie</p>
</td>
<td class="cellrowborder" valign="top" width="35.82641735826417%" headers="mcps1.2.4.1.2 "><p id="p16289114074812"><a name="p16289114074812"></a><a name="p16289114074812"></a>void RegisterXCollieChecker(const sptr&lt;XCollieChecker&gt; &amp;checker, unsigned int type)</p>
</td>
<td class="cellrowborder" valign="top" width="44.47555244475552%" headers="mcps1.2.4.1.3 "><p id="p186437319482"><a name="p186437319482"></a><a name="p186437319482"></a>Registers the callback of the thread suspension detection result.</p>
<p id="p112011591133"><a name="p112011591133"></a><a name="p112011591133"></a>Input arguments:</p>
<a name="ul7783192181413"></a><a name="ul7783192181413"></a><ul id="ul7783192181413"><li><strong id="b64637561712"><a name="b64637561712"></a><a name="b64637561712"></a>checker</strong>: Indicates the pointer to the XCollieChecker instance.</li><li><strong id="b1947711661711"><a name="b1947711661711"></a><a name="b1947711661711"></a>type</strong>: Indicates the suspension detection type. Set it to <strong id="b259214119717"><a name="b259214119717"></a><a name="b259214119717"></a>XCOLLIE_THREAD</strong>.</li></ul>
<p id="p166439314482"><a name="p166439314482"></a><a name="p166439314482"></a>Output arguments: none</p>
<p id="p564393112485"><a name="p564393112485"></a><a name="p564393112485"></a>Return value: none</p>
</td>
</tr>
<tr id="row594519275012"><td class="cellrowborder" valign="top" width="19.698030196980305%" headers="mcps1.2.4.1.1 "><p id="p294512211505"><a name="p294512211505"></a><a name="p294512211505"></a>XCollie</p>
</td>
<td class="cellrowborder" valign="top" width="35.82641735826417%" headers="mcps1.2.4.1.2 "><p id="p81561310145215"><a name="p81561310145215"></a><a name="p81561310145215"></a>int SetTimer(const std::string &amp;name, unsigned int timeout, std::function&lt;void (void *)&gt; func, void *arg, unsigned int flag)</p>
</td>
<td class="cellrowborder" valign="top" width="44.47555244475552%" headers="mcps1.2.4.1.3 "><p id="p174279246538"><a name="p174279246538"></a><a name="p174279246538"></a>Adds timers.</p>
<p id="p1998141221410"><a name="p1998141221410"></a><a name="p1998141221410"></a>Input arguments:</p>
<a name="ul845512153147"></a><a name="ul845512153147"></a><ul id="ul845512153147"><li><strong id="b44651010141715"><a name="b44651010141715"></a><a name="b44651010141715"></a>name</strong>: Indicates the timer name.</li><li><strong id="b266981221717"><a name="b266981221717"></a><a name="b266981221717"></a>timeout</strong>: Indicates the timeout duration, in seconds.</li><li><strong id="b17158171421710"><a name="b17158171421710"></a><a name="b17158171421710"></a>func</strong>: Indicates the timeout callback.</li><li><strong id="b1950162581810"><a name="b1950162581810"></a><a name="b1950162581810"></a>arg</strong>: Indicates the pointer to the timeout callback.</li><li><strong id="b4949151521714"><a name="b4949151521714"></a><a name="b4949151521714"></a>flag</strong>: Indicates the timer operation type.<p id="p1242762435310"><a name="p1242762435310"></a><a name="p1242762435310"></a>XCOLLIE_FLAG_DEFAULT // Indicates the default flag, which is the combination of the other three options.</p>
<p id="p1542712435312"><a name="p1542712435312"></a><a name="p1542712435312"></a>XCOLLIE_FLAG_NOOP // Calls only the timeout callback.</p>
<p id="p15427112416531"><a name="p15427112416531"></a><a name="p15427112416531"></a>XCOLLIE_FLAG_LOG // Generates a timeout fault log.</p>
<p id="p242762455314"><a name="p242762455314"></a><a name="p242762455314"></a>XCOLLIE_FLAG_RECOVERY // Exits the process.</p>
</li></ul>
<p id="p15427102445311"><a name="p15427102445311"></a><a name="p15427102445311"></a>Output arguments: none</p>
<p id="p144271424155316"><a name="p144271424155316"></a><a name="p144271424155316"></a>Return value: Returns the timer ID if the operation is successful; returns <strong id="b2229713291"><a name="b2229713291"></a><a name="b2229713291"></a>-1</strong> otherwise.</p>
</td>
</tr>
<tr id="row1294692165010"><td class="cellrowborder" valign="top" width="19.698030196980305%" headers="mcps1.2.4.1.1 "><p id="p19461929506"><a name="p19461929506"></a><a name="p19461929506"></a>XCollie</p>
</td>
<td class="cellrowborder" valign="top" width="35.82641735826417%" headers="mcps1.2.4.1.2 "><p id="p119467215012"><a name="p119467215012"></a><a name="p119467215012"></a>bool UpdateTimer(int id, unsigned int timeout)</p>
</td>
<td class="cellrowborder" valign="top" width="44.47555244475552%" headers="mcps1.2.4.1.3 "><p id="p3831253185713"><a name="p3831253185713"></a><a name="p3831253185713"></a>Updates timers.</p>
<p id="p10649172815148"><a name="p10649172815148"></a><a name="p10649172815148"></a>Input arguments:</p>
<a name="ul1628783221411"></a><a name="ul1628783221411"></a><ul id="ul1628783221411"><li><strong id="b61651021161710"><a name="b61651021161710"></a><a name="b61651021161710"></a>id</strong>: Indicates the timer ID.</li><li><strong id="b24661423141717"><a name="b24661423141717"></a><a name="b24661423141717"></a>timeout</strong>: Indicates the timeout duration, in seconds.</li></ul>
<p id="p11831115375719"><a name="p11831115375719"></a><a name="p11831115375719"></a>Output arguments: none</p>
<p id="p38311853105716"><a name="p38311853105716"></a><a name="p38311853105716"></a>Return value: Returns <strong id="b95701352192819"><a name="b95701352192819"></a><a name="b95701352192819"></a>true</strong> if the operation is successful; returns <strong id="b175761652152814"><a name="b175761652152814"></a><a name="b175761652152814"></a>false</strong> otherwise.</p>
</td>
</tr>
<tr id="row594682175013"><td class="cellrowborder" valign="top" width="19.698030196980305%" headers="mcps1.2.4.1.1 "><p id="p194614212504"><a name="p194614212504"></a><a name="p194614212504"></a>XCollie</p>
</td>
<td class="cellrowborder" valign="top" width="35.82641735826417%" headers="mcps1.2.4.1.2 "><p id="p1435552713588"><a name="p1435552713588"></a><a name="p1435552713588"></a>void CancelTimer(int id)</p>
</td>
<td class="cellrowborder" valign="top" width="44.47555244475552%" headers="mcps1.2.4.1.3 "><p id="p06791131580"><a name="p06791131580"></a><a name="p06791131580"></a>Cancels timers.</p>
<p id="p868013165815"><a name="p868013165815"></a><a name="p868013165815"></a>Input arguments:</p>
<p id="p9311488283"><a name="p9311488283"></a><a name="p9311488283"></a><strong id="b9666749171816"><a name="b9666749171816"></a><a name="b9666749171816"></a>id</strong>: Indicates the timer ID.</p>
<p id="p12680537587"><a name="p12680537587"></a><a name="p12680537587"></a>Output arguments: none</p>
<p id="p768015317586"><a name="p768015317586"></a><a name="p768015317586"></a>Return value: none</p>
</td>
</tr>
</tbody>
</table>
## Example<a name="section1589120102458"></a>
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<a name="section13905646534"></a>
### C++<a name="section9797199145316"></a>
### Thread Suspension Monitoring<a name="section1734221332"></a>
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");
XCollie::GetInstance().RegisterXCollieChecker(checker,
(XCOLLIE_LOCK | XCOLLIE_THREAD));
...
```
2. Configure compilation information. Specifically, add the subsystem SDK dependency to **BUILD.gn**.
```
external_deps = [ "hiviewdfx:libxcollie" ]
```
### Timeout Monitoring<a name="section2186947140"></a>
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.
```
#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);
...
```
2. Configure compilation information. Specifically, add the subsystem SDK dependency to **BUILD.gn**.
```
external_deps = [ "hiviewdfx:libxcollie" ]
```
# Development Guidelines on HiLog <a name="EN-US_TOPIC_0000001081129329"></a>
# HiLog Development<a name="EN-US_TOPIC_0000001185655870"></a>
- [Overview](#section8154107175019)
- [Available APIs](#section6748124155012)
......@@ -18,61 +18,68 @@ This development guide is applicable to Standard-System Devices \(reference memo
**Table 1** Description of C++ and C APIs
<a name="table94501354193619"></a>
<table><thead align="left"><tr id="row954285483614"><th class="cellrowborder" colspan="2" valign="top" id="mcps1.2.4.1.1"><p id="p16542254203611"><a name="p16542254203611"></a><a name="p16542254203611"></a><strong id="b17542185414366"><a name="b17542185414366"></a><a name="b17542185414366"></a>C++</strong></p>
<table><thead align="left"><tr id="row954285483614"><th class="cellrowborder" valign="top" width="18.258174182581744%" id="mcps1.2.4.1.1"><p id="p16542254203611"><a name="p16542254203611"></a><a name="p16542254203611"></a><strong id="b17542185414366"><a name="b17542185414366"></a><a name="b17542185414366"></a>C++</strong></p>
</th>
<th class="cellrowborder" valign="top" id="mcps1.2.4.1.2"><p id="p185431554163619"><a name="p185431554163619"></a><a name="p185431554163619"></a><strong id="b175431054123617"><a name="b175431054123617"></a><a name="b175431054123617"></a>C</strong></p>
<th class="cellrowborder" valign="top" width="43.39566043395661%" id="mcps1.2.4.1.2">&nbsp;&nbsp;</th>
<th class="cellrowborder" valign="top" width="38.34616538346165%" id="mcps1.2.4.1.3"><p id="p185431554163619"><a name="p185431554163619"></a><a name="p185431554163619"></a><strong id="b175431054123617"><a name="b175431054123617"></a><a name="b175431054123617"></a>C</strong></p>
</th>
</tr>
</thead>
<tbody><tr id="row954305418361"><td class="cellrowborder" valign="top" width="18.388161183881614%" headers="mcps1.2.4.1.1 "><p id="p3543754183618"><a name="p3543754183618"></a><a name="p3543754183618"></a><strong id="b2050619101839"><a name="b2050619101839"></a><a name="b2050619101839"></a>Class</strong></p>
<tbody><tr id="row954305418361"><td class="cellrowborder" valign="top" width="18.258174182581744%" headers="mcps1.2.4.1.1 "><p id="p3543754183618"><a name="p3543754183618"></a><a name="p3543754183618"></a><strong id="b2050619101839"><a name="b2050619101839"></a><a name="b2050619101839"></a>Class</strong></p>
</td>
<td class="cellrowborder" valign="top" width="43.53564643535647%" headers="mcps1.2.4.1.1 "><p id="p10544105453610"><a name="p10544105453610"></a><a name="p10544105453610"></a><strong id="b185619133317"><a name="b185619133317"></a><a name="b185619133317"></a>API</strong></p>
<td class="cellrowborder" valign="top" width="43.39566043395661%" headers="mcps1.2.4.1.2 "><p id="p10544105453610"><a name="p10544105453610"></a><a name="p10544105453610"></a><strong id="b185619133317"><a name="b185619133317"></a><a name="b185619133317"></a>API</strong></p>
</td>
<td class="cellrowborder" valign="top" width="38.076192380761924%" headers="mcps1.2.4.1.2 "><p id="p17969916192614"><a name="p17969916192614"></a><a name="p17969916192614"></a><strong id="b1316016214312"><a name="b1316016214312"></a><a name="b1316016214312"></a>API/Macro</strong></p>
<td class="cellrowborder" valign="top" width="38.34616538346165%" headers="mcps1.2.4.1.3 "><p id="p17969916192614"><a name="p17969916192614"></a><a name="p17969916192614"></a><strong id="b1316016214312"><a name="b1316016214312"></a><a name="b1316016214312"></a>API/Macro</strong></p>
</td>
</tr>
<tr id="row8544115410361"><td class="cellrowborder" rowspan="7" valign="top" width="18.388161183881614%" headers="mcps1.2.4.1.1 "><p id="p16544154183615"><a name="p16544154183615"></a><a name="p16544154183615"></a>HiLog</p>
<tr id="row8544115410361"><td class="cellrowborder" rowspan="7" valign="top" width="18.258174182581744%" headers="mcps1.2.4.1.1 "><p id="p16544154183615"><a name="p16544154183615"></a><a name="p16544154183615"></a>HiLog</p>
<p id="p956013011212"><a name="p956013011212"></a><a name="p956013011212"></a></p>
<p id="p1356013309127"><a name="p1356013309127"></a><a name="p1356013309127"></a></p>
<p id="p756011303129"><a name="p756011303129"></a><a name="p756011303129"></a></p>
<p id="p135601330191211"><a name="p135601330191211"></a><a name="p135601330191211"></a></p>
<p id="p756183091215"><a name="p756183091215"></a><a name="p756183091215"></a></p>
<p id="p1956115302128"><a name="p1956115302128"></a><a name="p1956115302128"></a></p>
</td>
<td class="cellrowborder" valign="top" width="43.53564643535647%" headers="mcps1.2.4.1.1 "><p id="p1326662513016"><a name="p1326662513016"></a><a name="p1326662513016"></a>int Debug(const HiLogLabel &amp;label, const char *fmt, ...)</p>
<td class="cellrowborder" valign="top" width="43.39566043395661%" headers="mcps1.2.4.1.2 "><p id="p1326662513016"><a name="p1326662513016"></a><a name="p1326662513016"></a>int Debug(const HiLogLabel &amp;label, const char *fmt, ...)</p>
</td>
<td class="cellrowborder" valign="top" width="38.076192380761924%" headers="mcps1.2.4.1.2 "><p id="p18697644105619"><a name="p18697644105619"></a><a name="p18697644105619"></a>HILOG_DEBUG(type, ...)</p>
<td class="cellrowborder" valign="top" width="38.34616538346165%" headers="mcps1.2.4.1.3 "><p id="p18697644105619"><a name="p18697644105619"></a><a name="p18697644105619"></a>HILOG_DEBUG(type, ...)</p>
</td>
</tr>
<tr id="row754495418366"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p86951544155610"><a name="p86951544155610"></a><a name="p86951544155610"></a>int Info(const HiLogLabel &amp;label, const char *fmt, ...)</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p96931344145615"><a name="p96931344145615"></a><a name="p96931344145615"></a>HILOG_INFO(type, ...)</p>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p96931344145615"><a name="p96931344145615"></a><a name="p96931344145615"></a>HILOG_INFO(type, ...)</p>
</td>
</tr>
<tr id="row95441954113614"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1769224485619"><a name="p1769224485619"></a><a name="p1769224485619"></a>int Warn(const HiLogLabel &amp;label, const char *fmt, ...)</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1969194465613"><a name="p1969194465613"></a><a name="p1969194465613"></a>HILOG_WARN(type, ...)</p>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1969194465613"><a name="p1969194465613"></a><a name="p1969194465613"></a>HILOG_WARN(type, ...)</p>
</td>
</tr>
<tr id="row45448547369"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p4748102365615"><a name="p4748102365615"></a><a name="p4748102365615"></a>int Error(const HiLogLabel &amp;label, const char *fmt, ...)</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p15747142375613"><a name="p15747142375613"></a><a name="p15747142375613"></a>HILOG_ERROR(type, ...)</p>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p15747142375613"><a name="p15747142375613"></a><a name="p15747142375613"></a>HILOG_ERROR(type, ...)</p>
</td>
</tr>
<tr id="row12545125453610"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p5745132318560"><a name="p5745132318560"></a><a name="p5745132318560"></a>int Fatal(const HiLogLabel &amp;label, const char *fmt, ...)</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p107441123175615"><a name="p107441123175615"></a><a name="p107441123175615"></a>HILOG_FATAL(type, ...)</p>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p107441123175615"><a name="p107441123175615"></a><a name="p107441123175615"></a>HILOG_FATAL(type, ...)</p>
</td>
</tr>
<tr id="row1454565433611"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1574242345618"><a name="p1574242345618"></a><a name="p1574242345618"></a>NA</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p197416239562"><a name="p197416239562"></a><a name="p197416239562"></a>int HiLogPrint(LogType type, LogLevel level, unsigned int domain, const char *tag, const char *fmt, ...)</p>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p197416239562"><a name="p197416239562"></a><a name="p197416239562"></a>int HiLogPrint(LogType type, LogLevel level, unsigned int domain, const char *tag, const char *fmt, ...)</p>
</td>
</tr>
<tr id="row165451854193617"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p64411913343"><a name="p64411913343"></a><a name="p64411913343"></a>boolean IsLoggable(unsigned int domain, const char *tag, LogLevel level)</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p107388238561"><a name="p107388238561"></a><a name="p107388238561"></a>bool HiLogIsLoggable(unsigned int domain, const char *tag, LogLevel level)</p>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p107388238561"><a name="p107388238561"></a><a name="p107388238561"></a>bool HiLogIsLoggable(unsigned int domain, const char *tag, LogLevel level)</p>
</td>
</tr>
<tr id="row154535415367"><td class="cellrowborder" valign="top" width="18.388161183881614%" headers="mcps1.2.4.1.1 "><p id="p795821952317"><a name="p795821952317"></a><a name="p795821952317"></a>HiLogLabel</p>
<tr id="row154535415367"><td class="cellrowborder" valign="top" width="18.258174182581744%" headers="mcps1.2.4.1.1 "><p id="p795821952317"><a name="p795821952317"></a><a name="p795821952317"></a>HiLogLabel</p>
</td>
<td class="cellrowborder" valign="top" width="43.53564643535647%" headers="mcps1.2.4.1.1 "><p id="p20464133712224"><a name="p20464133712224"></a><a name="p20464133712224"></a>struct HiLogLabel</p>
<td class="cellrowborder" valign="top" width="43.39566043395661%" headers="mcps1.2.4.1.2 "><p id="p20464133712224"><a name="p20464133712224"></a><a name="p20464133712224"></a>struct HiLogLabel</p>
</td>
<td class="cellrowborder" valign="top" width="38.076192380761924%" headers="mcps1.2.4.1.2 "><p id="p1360616314276"><a name="p1360616314276"></a><a name="p1360616314276"></a>LOG_DOMAIN</p>
<td class="cellrowborder" valign="top" width="38.34616538346165%" headers="mcps1.2.4.1.3 "><p id="p1360616314276"><a name="p1360616314276"></a><a name="p1360616314276"></a>LOG_DOMAIN</p>
<p id="p4698145992513"><a name="p4698145992513"></a><a name="p4698145992513"></a>LOG_TAG</p>
</td>
</tr>
......@@ -91,6 +98,11 @@ This development guide is applicable to Standard-System Devices \(reference memo
</tr>
</thead>
<tbody><tr id="row383911183378"><td class="cellrowborder" rowspan="6" valign="top" width="8.27%" headers="mcps1.2.4.1.1 "><p id="p10839318133713"><a name="p10839318133713"></a><a name="p10839318133713"></a>HiLog</p>
<p id="p58561944151216"><a name="p58561944151216"></a><a name="p58561944151216"></a></p>
<p id="p5856744201215"><a name="p5856744201215"></a><a name="p5856744201215"></a></p>
<p id="p1985664413120"><a name="p1985664413120"></a><a name="p1985664413120"></a></p>
<p id="p138562442123"><a name="p138562442123"></a><a name="p138562442123"></a></p>
<p id="p485612447125"><a name="p485612447125"></a><a name="p485612447125"></a></p>
</td>
<td class="cellrowborder" valign="top" width="31.41%" headers="mcps1.2.4.1.2 "><p id="p12483951497"><a name="p12483951497"></a><a name="p12483951497"></a>int Debug(const HiLogLabel &amp;label, const char *fmt, ...)</p>
</td>
......
# DHiSysEvent Development<a name="EN-US_TOPIC_0000001195021448"></a>
- **[HiSysEvent Logging](hisysevent-logging.md)**
- **[HiSysEvent Listening](hisysevent-listening.md)**
- **[HiSysEvent Query](hisysevent-query.md)**
- **[HiSysEvent Tool Usage](hisysevent-tool-usage.md)**
# HiSysEvent Listening<a name="EN-US_TOPIC_0000001185655868"></a>
- [Overview](#section315316685112)
- [Available APIs](#section0342191810519)
- [How to Develop](#section123181432175110)
- [C++](#section2016116181902)
## Overview<a name="section315316685112"></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>
**Table 1** HiSysEvent listener APIs
<a name="table1844019587496"></a>
<table><thead align="left"><tr id="row1440058184916"><th class="cellrowborder" valign="top" width="48.120000000000005%" id="mcps1.2.3.1.1"><p id="p19441135844915"><a name="p19441135844915"></a><a name="p19441135844915"></a>API</p>
</th>
<th class="cellrowborder" valign="top" width="51.88%" id="mcps1.2.3.1.2"><p id="p13441195815491"><a name="p13441195815491"></a><a name="p13441195815491"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row16441155818499"><td class="cellrowborder" valign="top" width="48.120000000000005%" headers="mcps1.2.3.1.1 "><p id="p877916438211"><a name="p877916438211"></a><a name="p877916438211"></a>int HiSysEventManager::AddEventListener(std::shared_ptr&lt;HiSysEventSubscribeCallBackBase&gt; listener, std::vector&lt;struct ListenerRule&gt;&amp; rules)</p>
</td>
<td class="cellrowborder" valign="top" width="51.88%" headers="mcps1.2.3.1.2 "><p id="p14727325133216"><a name="p14727325133216"></a><a name="p14727325133216"></a>Registers a listener for system events. You can listen for certain events by specifying rules.</p>
<p id="p167271525203213"><a name="p167271525203213"></a><a name="p167271525203213"></a>Input arguments:</p>
<a name="ul6717142214919"></a><a name="ul6717142214919"></a><ul id="ul6717142214919"><li><strong id="b5330432115819"><a name="b5330432115819"></a><a name="b5330432115819"></a>listener</strong>: callback object for system events.</li><li><strong id="b1518805912597"><a name="b1518805912597"></a><a name="b1518805912597"></a>rules</strong>: rules for event listening.</li></ul>
<p id="p83591223153818"><a name="p83591223153818"></a><a name="p83591223153818"></a>Return values</p>
<a name="ul12105842111913"></a><a name="ul12105842111913"></a><ul id="ul12105842111913"><li><strong id="b117641849702"><a name="b117641849702"></a><a name="b117641849702"></a>0</strong>: Repeated registration is successful.</li><li><strong id="b2682415314"><a name="b2682415314"></a><a name="b2682415314"></a>1</strong>: Initial registration is successful.</li><li>Other values: Registration has failed.</li></ul>
</td>
</tr>
<tr id="row910319443242"><td class="cellrowborder" valign="top" width="48.120000000000005%" headers="mcps1.2.3.1.1 "><p id="p15104154411248"><a name="p15104154411248"></a><a name="p15104154411248"></a>void HiSysEventManager::RemoveListener(std::shared_ptr&lt;HiSysEventSubscribeCallBackBase&gt; listener)</p>
</td>
<td class="cellrowborder" valign="top" width="51.88%" headers="mcps1.2.3.1.2 "><p id="p1104194420248"><a name="p1104194420248"></a><a name="p1104194420248"></a>Removes the listener for system events.</p>
<p id="p7943171095411"><a name="p7943171095411"></a><a name="p7943171095411"></a>Input arguments:</p>
<a name="ul894321075411"></a><a name="ul894321075411"></a><ul id="ul894321075411"><li><strong id="b178371510181317"><a name="b178371510181317"></a><a name="b178371510181317"></a>listener</strong>: callback object for system events.</li></ul>
<p id="p9744631162515"><a name="p9744631162515"></a><a name="p9744631162515"></a>Return value: none</p>
</td>
</tr>
</tbody>
</table>
**Table 2** HiSysEvent listener rules
<a name="table1144011610564"></a>
<table><thead align="left"><tr id="row124411716175611"><th class="cellrowborder" valign="top" width="48.11%" id="mcps1.2.3.1.1"><p id="p19441151675610"><a name="p19441151675610"></a><a name="p19441151675610"></a>Attribute</p>
</th>
<th class="cellrowborder" valign="top" width="51.89%" id="mcps1.2.3.1.2"><p id="p16441171616563"><a name="p16441171616563"></a><a name="p16441171616563"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row174411216105615"><td class="cellrowborder" valign="top" width="48.11%" headers="mcps1.2.3.1.1 "><p id="p496413536613"><a name="p496413536613"></a><a name="p496413536613"></a><span>uint32_t</span> ruleType</p>
</td>
<td class="cellrowborder" valign="top" width="51.89%" headers="mcps1.2.3.1.2 "><p id="p94416160565"><a name="p94416160565"></a><a name="p94416160565"></a>Rule type. The matching scope includes <strong id="b638713414175"><a name="b638713414175"></a><a name="b638713414175"></a>domain</strong> and <strong id="b128648618171"><a name="b128648618171"></a><a name="b128648618171"></a>eventName</strong>. The value can be any of the following:</p>
<a name="ul1652866141814"></a><a name="ul1652866141814"></a><ul id="ul1652866141814"><li>1: whole word matching.</li><li>2: prefix matching.</li><li>3: regular expression matching.</li><li>Other values: invalid matching mode.</li></ul>
</td>
</tr>
<tr id="row64411816125614"><td class="cellrowborder" valign="top" width="48.11%" headers="mcps1.2.3.1.1 "><p id="p1258135313712"><a name="p1258135313712"></a><a name="p1258135313712"></a>std::string domain</p>
</td>
<td class="cellrowborder" valign="top" width="51.89%" headers="mcps1.2.3.1.2 "><a name="ul14905926102311"></a><a name="ul14905926102311"></a><ul id="ul14905926102311"><li><strong id="b152431514132110"><a name="b152431514132110"></a><a name="b152431514132110"></a>domain</strong>: domain to which the event belongs. By default, an empty string indicates that the domain is successfully matched.</li></ul>
</td>
</tr>
<tr id="row244161615619"><td class="cellrowborder" valign="top" width="48.11%" headers="mcps1.2.3.1.1 "><p id="p227913101887"><a name="p227913101887"></a><a name="p227913101887"></a>std::string eventName</p>
</td>
<td class="cellrowborder" valign="top" width="51.89%" headers="mcps1.2.3.1.2 "><a name="ul248063132319"></a><a name="ul248063132319"></a><ul id="ul248063132319"><li><strong id="b197622401229"><a name="b197622401229"></a><a name="b197622401229"></a>eventName</strong>: event name. By default, an empty string indicates that the event name is successfully matched.</li></ul>
</td>
</tr>
</tbody>
</table>
**Table 3** HiSysEvent callback object
<a name="table1011703742711"></a>
<table><thead align="left"><tr id="row121187375270"><th class="cellrowborder" valign="top" width="48.25%" id="mcps1.2.3.1.1"><p id="p2118143782719"><a name="p2118143782719"></a><a name="p2118143782719"></a>API</p>
</th>
<th class="cellrowborder" valign="top" width="51.74999999999999%" id="mcps1.2.3.1.2"><p id="p4118037152710"><a name="p4118037152710"></a><a name="p4118037152710"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row111823719274"><td class="cellrowborder" valign="top" width="48.25%" headers="mcps1.2.3.1.1 "><p id="p161181537112712"><a name="p161181537112712"></a><a name="p161181537112712"></a>void HiSysEventSubscribeCallBackBase::OnHandle(const std::string&amp; domain, const std::string&amp; eventName, const int eventType, const std::string&amp; eventDetail)</p>
</td>
<td class="cellrowborder" valign="top" width="51.74999999999999%" headers="mcps1.2.3.1.2 "><p id="p1772213111011"><a name="p1772213111011"></a><a name="p1772213111011"></a>Callback object for system events.</p>
<p id="p182081719151016"><a name="p182081719151016"></a><a name="p182081719151016"></a>Input arguments:</p>
<a name="ul02091819131015"></a><a name="ul02091819131015"></a><ul id="ul02091819131015"><li><strong id="b19691125212280"><a name="b19691125212280"></a><a name="b19691125212280"></a>domain</strong>: domain to which the event belongs.</li><li><strong id="b144121713192910"><a name="b144121713192910"></a><a name="b144121713192910"></a>eventName</strong>: event name.</li><li><strong id="b410512122915"><a name="b410512122915"></a><a name="b410512122915"></a>eventType</strong>: event type.</li><li><strong id="b89521717103013"><a name="b89521717103013"></a><a name="b89521717103013"></a>eventDetail</strong>: JSON string containing event information.</li></ul>
<p id="p18209419201010"><a name="p18209419201010"></a><a name="p18209419201010"></a>Return value: none</p>
</td>
</tr>
</tbody>
</table>
## How to Develop<a name="section123181432175110"></a>
### **C++**<a name="section2016116181902"></a>
In this example, you'll be instructed to register a listener for all system events that belong to the **HIVIEWDFX** domain.
1. Develop the source code.
- Import the corresponding header file:
hisysevent\_manager.h
- Implement the callback API.
HiSysEventSubscribeCallBackBase::OnHandle\(const std::string& domain, const std::string& eventName, const int eventType, const std::string& eventDetail\)
- Register a callback object.
HiSysEventManager::AddEventListener\(std::shared\_ptr<HiSysEventSubscribeCallBackBase\> listener, std::vector<struct ListenerRule\>& rules\)
```
// Register a listener for all system events that belong to the HIVIEWDFX domain.
#include "hisysevent_manager.h"
#include <iostream>
namespace OHOS {
namespace HiviewDFX {
// Implement the API for registering a listener for callback objects.
void HiSysEventToolListener::OnHandle(const std::string& domain, const std::string& eventName,
const int eventType, const std::string& eventDetail)
{
std::cout << eventDetail << std::endl;
}
void HiSysEventToolListener::OnServiceDied()
{
std::cout << std::string("service disconnect, exit") << std::endl;
exit(0);
}
} // namespace HiviewDFX
} // namespace OHOS
// Register a listener for callback objects.
auto toolListener = std::make_shared<HiSysEventToolListener>();
struct ListenerRule rule;
rule.ruleType = 1; // 1: default type
rule.domain = "HIVIEWDFX";
std::vector<struct ListenerRule> sysRules;
sysRules.push_back(rule);
HiSysEventManager::AddEventListener(toolListener, sysRules);
```
2. Modify the **BUILD.gn** file.
In the **BUILD.gn** file, add the **libhisyseventmanager** library that depends on the** hisysevent\_native** component.
```
external_deps = [ "hisysevent_native:libhisyseventmanager", ]
```
# Development Guidelines on HiSysEvent<a name="EN-US_TOPIC_0000001091101688"></a>
# HiSysEvent Logging<a name="EN-US_TOPIC_0000001231373947"></a>
- [Overview](#section77571101789)
- [Available APIs](#section13480315886)
......@@ -27,7 +27,7 @@ For details about the **HiSysEvent** class, see the API reference.
</td>
<td class="cellrowborder" valign="top" width="42.61%" headers="mcps1.2.3.1.2 "><p id="p14727325133216"><a name="p14727325133216"></a><a name="p14727325133216"></a>Logs system events.</p>
<p id="p167271525203213"><a name="p167271525203213"></a><a name="p167271525203213"></a>Input arguments:</p>
<a name="ul0727102516327"></a><a name="ul0727102516327"></a><ul id="ul0727102516327"><li>domain: Indicates the domain related to the event. You can use a preconfigured domain or customize a domain as needed. The name of a custom domain can contain a maximum of 16 characters, including digits (0-9) and uppercase letters (A-Z). It must start with a letter.</li><li>eventName: Indicates the event name. The value contains a maximum of 32 characters, including digits (0 to 9), lowercase letters (a-z), uppercase letters (A-Z), and underscores (_). It must start with a letter and cannot end with an underscore (_).</li><li>type: Indicates the event type. For details, see <strong id="b137231746124214"><a name="b137231746124214"></a><a name="b137231746124214"></a>EventType</strong>.</li><li>keyValues: Indicates the key-value pairs of event parameters. It can be in the format of the basic data type, <strong id="b1270524734214"><a name="b1270524734214"></a><a name="b1270524734214"></a>std::string</strong>, <strong id="b1870517478422"><a name="b1870517478422"></a><a name="b1870517478422"></a>std::vector<em id="i5705114724211"><a name="i5705114724211"></a><a name="i5705114724211"></a>&lt;basic data type&gt;</em></strong>, or <strong id="b2070614724211"><a name="b2070614724211"></a><a name="b2070614724211"></a>std:vector&lt;std::string&gt;</strong>. The value contains a maximum of 48 characters, including digits (0 to 9), lowercase letters (a-z), uppercase letters (A-Z), and underscores (_). It must start with a letter and cannot end with an underscore (_). The number of parameter names cannot exceed 32.</li></ul>
<a name="ul0727102516327"></a><a name="ul0727102516327"></a><ul id="ul0727102516327"><li><strong id="b738811554915"><a name="b738811554915"></a><a name="b738811554915"></a>domain</strong>: Indicates the domain related to the event. You can use a preconfigured domain or customize a domain as needed. The name of a custom domain can contain a maximum of 16 characters, including digits (0-9) and uppercase letters (A-Z). It must start with a letter.</li><li><strong id="b6556916144913"><a name="b6556916144913"></a><a name="b6556916144913"></a>eventName</strong>: Indicates the event name. The value contains a maximum of 32 characters, including digits (0 to 9), letters (A-Z), and underscore (_). It must start with a letter and cannot end with an underscore (_).</li><li><strong id="b23385182493"><a name="b23385182493"></a><a name="b23385182493"></a>type</strong>: Indicates the event type. For details, see <strong id="b137231746124214"><a name="b137231746124214"></a><a name="b137231746124214"></a>EventType</strong>.</li><li><strong id="b8262191944912"><a name="b8262191944912"></a><a name="b8262191944912"></a>keyValues</strong>: Indicates the key-value pairs of event parameters. It can be in the format of the basic data type, <strong id="b1270524734214"><a name="b1270524734214"></a><a name="b1270524734214"></a>std::string</strong>, <strong id="b1870517478422"><a name="b1870517478422"></a><a name="b1870517478422"></a>std::vector<em id="i5705114724211"><a name="i5705114724211"></a><a name="i5705114724211"></a>&lt;basic data type&gt;</em></strong>, or <strong id="b2070614724211"><a name="b2070614724211"></a><a name="b2070614724211"></a>std:vector&lt;std::string&gt;</strong>. The value contains a maximum of 48 characters, including digits (0 to 9), letters (A-Z), and underscore (_). It must start with a letter and cannot end with an underscore (_). The number of parameter names cannot exceed 32.</li></ul>
<p id="p1727152513217"><a name="p1727152513217"></a><a name="p1727152513217"></a>Return value: Returns <strong id="b1893811237358"><a name="b1893811237358"></a><a name="b1893811237358"></a>0</strong> if the operation is successful; returns a value less than <strong id="b99381232350"><a name="b99381232350"></a><a name="b99381232350"></a>0</strong> otherwise.</p>
</td>
</tr>
......@@ -270,7 +270,7 @@ For details about the **HiSysEvent** class, see the API reference.
#include "hisysevent.h"
```
Add the event logging code. For example, if you want to log events specific to the app start time \(start\_app\), then add the following code to the service implementation source file:
Add the event logging code. For example, if you want to log events specific to the app start time \(**start\_app**\), then add the following code to the service implementation source file:
```
HiSysEvent::Write(HiSysEvent::Domain::AAFWK, "start_app", HiSysEvent::EventType::FAULT, "app_name", "com.demo");
......
# HiSysEvent Query<a name="EN-US_TOPIC_0000001231455461"></a>
- [Overview](#section279684125212)
- [Available APIs](#section03869128521)
- [How to Develop](#section14286111855212)
- [C++](#section162045551743)
## Overview<a name="section279684125212"></a>
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>
**Table 1** HiSysEvent query API
<a name="table1844019587496"></a>
<table><thead align="left"><tr id="row1440058184916"><th class="cellrowborder" valign="top" width="48.120000000000005%" id="mcps1.2.3.1.1"><p id="p19441135844915"><a name="p19441135844915"></a><a name="p19441135844915"></a>API</p>
</th>
<th class="cellrowborder" valign="top" width="51.88%" id="mcps1.2.3.1.2"><p id="p13441195815491"><a name="p13441195815491"></a><a name="p13441195815491"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row16441155818499"><td class="cellrowborder" valign="top" width="48.120000000000005%" headers="mcps1.2.3.1.1 "><p id="p114411558204915"><a name="p114411558204915"></a><a name="p114411558204915"></a>bool HiSysEventManager::QueryHiSysEvent(struct QueryArg&amp; queryArg, std::vector&lt;struct QueryRule&gt;&amp; queryRules, std::shared_ptr&lt;HiSysEventQueryCallBackBase&gt; queryCallBack)</p>
</td>
<td class="cellrowborder" valign="top" width="51.88%" headers="mcps1.2.3.1.2 "><p id="p14727325133216"><a name="p14727325133216"></a><a name="p14727325133216"></a>Queries system events by specifying search criteria such as the time segment, event domain, and event name.</p>
<p id="p167271525203213"><a name="p167271525203213"></a><a name="p167271525203213"></a>Input arguments:</p>
<a name="ul6717142214919"></a><a name="ul6717142214919"></a><ul id="ul6717142214919"><li><strong id="b13783124325410"><a name="b13783124325410"></a><a name="b13783124325410"></a>queryArg</strong>: event query parameter.</li><li><strong id="b179229305560"><a name="b179229305560"></a><a name="b179229305560"></a>queryRules</strong>: event filtering rules.</li><li><strong id="b1244153910574"><a name="b1244153910574"></a><a name="b1244153910574"></a>queryCallBack</strong>: callback object for query results.</li></ul>
<p id="p83591223153818"><a name="p83591223153818"></a><a name="p83591223153818"></a>Return values</p>
<a name="ul12105842111913"></a><a name="ul12105842111913"></a><ul id="ul12105842111913"><li><strong id="b16711328155919"><a name="b16711328155919"></a><a name="b16711328155919"></a>true</strong>: Operation successful.</li><li><strong id="b1421823714591"><a name="b1421823714591"></a><a name="b1421823714591"></a>false</strong>: Operation failed.</li></ul>
</td>
</tr>
</tbody>
</table>
**Table 2** HiSysEvent query parameters
<a name="table13783145132014"></a>
<table><thead align="left"><tr id="row11784451112013"><th class="cellrowborder" valign="top" width="47.85%" id="mcps1.2.3.1.1"><p id="p187841351152012"><a name="p187841351152012"></a><a name="p187841351152012"></a>Attribute</p>
</th>
<th class="cellrowborder" valign="top" width="52.15%" id="mcps1.2.3.1.2"><p id="p4784105182019"><a name="p4784105182019"></a><a name="p4784105182019"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row3784451122012"><td class="cellrowborder" valign="top" width="47.85%" headers="mcps1.2.3.1.1 "><p id="p2078414512209"><a name="p2078414512209"></a><a name="p2078414512209"></a>long long beginTime</p>
</td>
<td class="cellrowborder" valign="top" width="52.15%" headers="mcps1.2.3.1.2 "><p id="p37844517207"><a name="p37844517207"></a><a name="p37844517207"></a>Start time.</p>
</td>
</tr>
<tr id="row1564913158230"><td class="cellrowborder" valign="top" width="47.85%" headers="mcps1.2.3.1.1 "><p id="p11649191511239"><a name="p11649191511239"></a><a name="p11649191511239"></a>long long endTime</p>
</td>
<td class="cellrowborder" valign="top" width="52.15%" headers="mcps1.2.3.1.2 "><p id="p126491715182314"><a name="p126491715182314"></a><a name="p126491715182314"></a>End time.</p>
</td>
</tr>
<tr id="row461821212236"><td class="cellrowborder" valign="top" width="47.85%" headers="mcps1.2.3.1.1 "><p id="p461841262313"><a name="p461841262313"></a><a name="p461841262313"></a>int maxEvents</p>
</td>
<td class="cellrowborder" valign="top" width="52.15%" headers="mcps1.2.3.1.2 "><p id="p1161901214232"><a name="p1161901214232"></a><a name="p1161901214232"></a>Maximum number of query records.</p>
</td>
</tr>
</tbody>
</table>
**Table 3** HiSysEvent query rules
<a name="table1144011610564"></a>
<table><thead align="left"><tr id="row124411716175611"><th class="cellrowborder" valign="top" width="48.03%" id="mcps1.2.3.1.1"><p id="p19441151675610"><a name="p19441151675610"></a><a name="p19441151675610"></a>Attribute</p>
</th>
<th class="cellrowborder" valign="top" width="51.970000000000006%" id="mcps1.2.3.1.2"><p id="p16441171616563"><a name="p16441171616563"></a><a name="p16441171616563"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row174411216105615"><td class="cellrowborder" valign="top" width="48.03%" headers="mcps1.2.3.1.1 "><p id="p496413536613"><a name="p496413536613"></a><a name="p496413536613"></a><span>uint32_t</span> ruleType</p>
</td>
<td class="cellrowborder" valign="top" width="51.970000000000006%" headers="mcps1.2.3.1.2 "><p id="p94416160565"><a name="p94416160565"></a><a name="p94416160565"></a>Rule type. The default value is <strong id="b196007205817"><a name="b196007205817"></a><a name="b196007205817"></a>0</strong>.</p>
</td>
</tr>
<tr id="row64411816125614"><td class="cellrowborder" valign="top" width="48.03%" headers="mcps1.2.3.1.1 "><p id="p1258135313712"><a name="p1258135313712"></a><a name="p1258135313712"></a>std::string domain;</p>
</td>
<td class="cellrowborder" valign="top" width="51.970000000000006%" headers="mcps1.2.3.1.2 "><a name="ul14905926102311"></a><a name="ul14905926102311"></a><ul id="ul14905926102311"><li><strong id="b9813231789"><a name="b9813231789"></a><a name="b9813231789"></a>domain</strong>: domain to which the event belongs. By default, an empty string indicates that the domain is successfully matched.</li></ul>
</td>
</tr>
<tr id="row244161615619"><td class="cellrowborder" valign="top" width="48.03%" headers="mcps1.2.3.1.1 "><p id="p227913101887"><a name="p227913101887"></a><a name="p227913101887"></a>std::vector&lt;std::string&gt; eventList</p>
</td>
<td class="cellrowborder" valign="top" width="51.970000000000006%" headers="mcps1.2.3.1.2 "><a name="ul248063132319"></a><a name="ul248063132319"></a><ul id="ul248063132319"><li><strong id="b172129351784"><a name="b172129351784"></a><a name="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>
</td>
</tr>
</tbody>
</table>
**Table 4** HiSysEvent query callback objects
<a name="table1451320549112"></a>
<table><thead align="left"><tr id="row951420547116"><th class="cellrowborder" valign="top" width="48.03%" id="mcps1.2.3.1.1"><p id="p15141546117"><a name="p15141546117"></a><a name="p15141546117"></a>API</p>
</th>
<th class="cellrowborder" valign="top" width="51.970000000000006%" id="mcps1.2.3.1.2"><p id="p165141654151113"><a name="p165141654151113"></a><a name="p165141654151113"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row35141554151115"><td class="cellrowborder" valign="top" width="48.03%" headers="mcps1.2.3.1.1 "><p id="p4714143785410"><a name="p4714143785410"></a><a name="p4714143785410"></a>void HiSysEventQueryCallBackBase::OnQuery(const ::std::vector&lt;std::string&gt;&amp; sysEvent, const ::std::vector&lt;int64_t&gt;&amp; seq)</p>
</td>
<td class="cellrowborder" valign="top" width="51.970000000000006%" headers="mcps1.2.3.1.2 "><p id="p1772213111011"><a name="p1772213111011"></a><a name="p1772213111011"></a>Callback object for event query.</p>
<p id="p182081719151016"><a name="p182081719151016"></a><a name="p182081719151016"></a>Input arguments:</p>
<a name="ul02091819131015"></a><a name="ul02091819131015"></a><ul id="ul02091819131015"><li><strong id="b132316517135"><a name="b132316517135"></a><a name="b132316517135"></a>sysEvent</strong>: event set.</li><li><strong id="b185101961310"><a name="b185101961310"></a><a name="b185101961310"></a>seq</strong>: event sequence set.</li></ul>
<p id="p18209419201010"><a name="p18209419201010"></a><a name="p18209419201010"></a>Return value: none</p>
</td>
</tr>
<tr id="row15141154161111"><td class="cellrowborder" valign="top" width="48.03%" headers="mcps1.2.3.1.1 "><p id="p561110151119"><a name="p561110151119"></a><a name="p561110151119"></a>void HiSysEventQueryCallBackBase::OnComplete(int32_t reason, int32_t total)</p>
</td>
<td class="cellrowborder" valign="top" width="51.970000000000006%" headers="mcps1.2.3.1.2 "><p id="p126315352130"><a name="p126315352130"></a><a name="p126315352130"></a>Callback object for completion of event query.</p>
<p id="p6631235191316"><a name="p6631235191316"></a><a name="p6631235191316"></a>Input arguments:</p>
<a name="ul106383518130"></a><a name="ul106383518130"></a><ul id="ul106383518130"><li><strong id="b855743017177"><a name="b855743017177"></a><a name="b855743017177"></a>reason</strong>: reason for completion of event query. The default value is <strong id="b5175337111718"><a name="b5175337111718"></a><a name="b5175337111718"></a>0</strong>.</li><li><strong id="b1196583151911"><a name="b1196583151911"></a><a name="b1196583151911"></a>total</strong>: total number of events returned in this query.</li></ul>
<p id="p176313516133"><a name="p176313516133"></a><a name="p176313516133"></a>Return value: none</p>
</td>
</tr>
</tbody>
</table>
## How to Develop<a name="section14286111855212"></a>
### **C++**<a name="section162045551743"></a>
In this example, you'll be instructed to query all system events.
1. Develop the source code.
- Import the corresponding header file:
hisysevent\_manager.h
- Implement the callback API.
void HiSysEventQueryCallBackBase::OnQuery\(const ::std::vector<std::string\>& sysEvent, const ::std::vector<int64\_t\>& seq\)
void HiSysEventQueryCallBackBase::OnComplete\(int32\_t reason, int32\_t total\)
- Invoke the query API in the corresponding service logic.
HiSysEventManager::QueryHiSysEvent\(struct QueryArg& queryArg, std::vector<struct QueryRule\>& queryRules, std::shared\_ptr<HiSysEventQueryCallBackBase\> queryCallBack\)
```
// In this example, you'll query all system events.
#include "hisysevent_manager.h"
#include <iostream>
namespace OHOS {
namespace HiviewDFX {
// Implement the query callback API.
void HiSysEventToolQuery::OnQuery(const ::std::vector<std::string>& sysEvent,
const ::std::vector<int64_t>& seq)
{
for_each(sysEvent.cbegin(), sysEvent.cend(), [](const std::string &tmp) {
std::cout << tmp << std::endl;
});
}
void HiSysEventToolQuery::OnComplete(int32_t reason, int32_t total)
{
return;
}
} // namespace HiviewDFX
} // namespace OHOS
// Invoke the query callback API to obtain system events.
auto queryCallBack = std::make_shared<HiSysEventToolQuery>();
struct QueryArg args(clientCmdArg.beginTime, clientCmdArg.endTime, clientCmdArg.maxEvents);
std::vector<struct QueryRule> mRules;
HiSysEventManager::QueryHiSysEvent(args, mRules, queryCallBack);
```
2. Modify the **BUILD.gn** file.
In the **BUILD.gn** file, add the **libhisyseventmanager** library that depends on the** hisysevent\_native** component.
```
external_deps = [ "hisysevent_native:libhisyseventmanager", ]
```
# HiSysEvent Tool Usage<a name="EN-US_TOPIC_0000001231614021"></a>
- [Overview](#section1886702718521)
- [Usage](#section1210623418527)
## Overview<a name="section1886702718521"></a>
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:
```
hisysevent [-r | -l [-s <time> -e <time> -m <count>]]
-r get real hisysevent log.
-l -s <begin time> -e <end time> -m <max hisysevent count>
get history hisysevent log, begin time should not be earlier than end time.
```
2. To query real-time system events, run the following command:
```
hisysevent -r
```
When a system event is received, the event will be printed on the console.
3. To query historical system events, run the following command:
```
hisysevent -l -s <begin time> -e <end time> -m <max hisysevent count>
```
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.
# DFX<a name="EN-US_TOPIC_0000001075771948"></a>
# DFX<a name="EN-US_TOPIC_0000001185974398"></a>
- [Basic Concepts](#section5635178134811)
......@@ -6,9 +6,11 @@
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\).
## Basic Concepts<a name="section5635178134811"></a>
......
# DFX<a name="EN-US_TOPIC_0000001157479395"></a>
- **[DFX](subsys-dfx-overview.md)**
- **[Development Guidelines on HiLog](subsys-dfx-hilog-rich.md)**
- **[Development Guidelines on HiLog\_Lite](subsys-dfx-hilog-lite.md)**
- **[Development Guidelines on HiSysEvent](subsys-dfx-hisysevent.md)**
# DFX Development Guide
- [DFX Overview](subsys-dfx-overview.md)
- [HiLog Development](subsys-dfx-hilog-development.md)
- [Development Guidelines on HiLog\_Lite](subsys-dfx-development-guidelines-on-hilog_lite.md)
- [HiTrace Development](subsys-dfx-hitrace-development.md)
- [HiCollie Development](subsys-dfx-hicollie-development.md)
- [HiSysEvent Development](subsys-dfx-hisysevent-development.md)
- [HiSysEvent Logging](subsys-dfx-hisysevent-logging.md)
- [HiSysEvent Listening](subsys-dfx-hisysevent-listening.md)
- [HiSysEvent Query](subsys-dfx-hisysevent-query.md)
- [HiSysEvent Tool Usage](subsys-dfx-hisysevent-tool-usage.md)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册