README.md
1# HiSysEvent<a name="EN-US_TOPIC_0000001115694150"></a>
2
3- [Introduction](#section11660541593)
4- [Directory Structure](#section161941989596)
5- [Description](#section1312121216216)
6 - [Available APIs](#section1551164914237)
7 - [Sample Code](#section129654513264)
8
9- [Repositories Involved](#section1371113476307)
10
11## Introduction<a name="section11660541593"></a>
12
13HiSysEvent provides event logging APIs for OpenHarmony to record important information of key processes during system running, helping you locate faults. In addition, you can upload the log data to the cloud for big data analytics.
14
15**Figure 1** HiSysEvent architecture<a name="fig1514425244110"></a>
16
17
18![](figures/en-us_image_0000001115534248.png)
19
20## Directory Structure<a name="section161941989596"></a>
21
22```
23/base/hiviewdfx/hisysevent # HiSysEvent source code
24├── adapter # Platform adaptation code
25│ └── native # native adaptation code
26├── frameworks # Framework code
27│ └── native # C/C++ APIs
28├── interfaces # External APIs
29 └── native # C++ APIs
30 └── innerkits # C++ APIs opened to internal subsystems
31```
32
33## Description<a name="section1312121216216"></a>
34
35### Available APIs<a name="section1551164914237"></a>
36
37The following table lists the C++ APIs provided by the **HiSysEvent** class.
38
39**Table 1** C++ APIs provided by HiSysEvent
40
41<a name="table1972602519328"></a>
42<table><thead align="left"><tr id="row5726112593219"><th class="cellrowborder" valign="top" width="57.38999999999999%" id="mcps1.2.3.1.1"><p id="p1472602523216"><a name="p1472602523216"></a><a name="p1472602523216"></a>API</p>
43</th>
44<th class="cellrowborder" valign="top" width="42.61%" id="mcps1.2.3.1.2"><p id="p12726112512322"><a name="p12726112512322"></a><a name="p12726112512322"></a>Description</p>
45</th>
46</tr>
47</thead>
48<tbody><tr id="row47261259328"><td class="cellrowborder" valign="top" width="57.38999999999999%" headers="mcps1.2.3.1.1 "><p id="p15726112583213"><a name="p15726112583213"></a><a name="p15726112583213"></a>template<typename... Types> static int Write(const std::string &domain, const std::string &eventName, EventType type, Types... keyValues)</p>
49</td>
50<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>
51<p id="p167271525203213"><a name="p167271525203213"></a><a name="p167271525203213"></a>Input parameters:</p>
52<a name="ul0727102516327"></a><a name="ul0727102516327"></a><ul id="ul0727102516327"><li><strong id="b2019634817576"><a name="b2019634817576"></a><a name="b2019634817576"></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), lowercase letters (a-z), uppercase letters (A-Z), and underscores (_). It must start with a letter.</li><li><strong id="b20954154912571"><a name="b20954154912571"></a><a name="b20954154912571"></a>eventName</strong>: 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.</li><li><strong id="b488285185718"><a name="b488285185718"></a><a name="b488285185718"></a>type</strong>: Indicates the event type. For details, see <strong id="b1667133015432"><a name="b1667133015432"></a><a name="b1667133015432"></a>EventType</strong>.</li><li><strong id="b19936135214571"><a name="b19936135214571"></a><a name="b19936135214571"></a>keyValues</strong>: Indicates the key-value pairs of event parameters. It can be in the format of the basic data type, <strong id="b79851431194316"><a name="b79851431194316"></a><a name="b79851431194316"></a>std::string</strong>, <strong id="b119861931204316"><a name="b119861931204316"></a><a name="b119861931204316"></a>std::vector<em id="i798503114317"><a name="i798503114317"></a><a name="i798503114317"></a><basic data type></em></strong>, or <strong id="b16986143164314"><a name="b16986143164314"></a><a name="b16986143164314"></a>std:vector<std::string></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. The number of parameters cannot exceed 128.</li></ul>
53<p id="p1727152513217"><a name="p1727152513217"></a><a name="p1727152513217"></a>Return value: If the operation is successful, <strong id="b277873515435"><a name="b277873515435"></a><a name="b277873515435"></a>0</strong> is returned. If the operation fails, a negative value is returned.</p>
54</td>
55</tr>
56</tbody>
57</table>
58
59### Sample Code<a name="section129654513264"></a>
60
61**C++**
62
631. Develop the source code.
64
65 Include the **HiSysEvent** header file in the class definition header file or class implementation source file. For example:
66
67 ```
68 #include "hisysevent.h"
69 ```
70
71 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:
72
73 ```
74 HiSysEvent::Write(HiSysEvent::Domain::AAFWK, "start_app", HiSysEvent::EventType::BEHAVIOR, "app_name", "com.demo");
75 ```
76
772. Configure compilation information. Specifically, add the subsystem SDK dependency to **BUILD.gn**.
78
79 ```
80 external_deps = [ "hisysevent:libhisysevent" ]
81 ```
82
83
84## Repositories Involved<a name="section1371113476307"></a>
85
86[DFX subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/dfx.md)
87
88[hiviewdfx\_hiview](https://gitee.com/openharmony/hiviewdfx_hiview/blob/master/README.md)
89
90[hiviewdfx\_hilog](https://gitee.com/openharmony/hiviewdfx_hilog/blob/master/README.md)
91
92[hiviewdfx\_hiappevent](https://gitee.com/openharmony/hiviewdfx_hiappevent/blob/master/README.md)
93
94**hiviewdfx\_hisysevent**
95
96[hiviewdfx\_faultloggerd](https://gitee.com/openharmony/hiviewdfx_faultloggerd/blob/master/README.md)
97
98[hiviewdfx\_hilog\_lite](https://gitee.com/openharmony/hiviewdfx_hilog_lite/blob/master/README.md)
99
100[hiviewdfx\_hievent\_lite](https://gitee.com/openharmony/hiviewdfx_hievent_lite/blob/master/README.md)
101
102[hiviewdfx\_hiview\_lite](https://gitee.com/openharmony/hiviewdfx_hiview_lite/blob/master/README.md)
103
104
README_zh.md
1# HiSysEvent组件<a name="ZH-CN_TOPIC_0000001115694150"></a>
2
3- [简介](#section11660541593)
4- [目录](#section161941989596)
5- [说明](#section1312121216216)
6 - [接口说明](#section1551164914237)
7 - [使用说明](#section129654513264)
8
9- [相关仓](#section1371113476307)
10
11## 简介<a name="section11660541593"></a>
12
13HiSysEvent提供OpenHarmony埋点接口,通过在关键路径埋点记录系统在运行过程中的重要信息,辅助开发者定位问题,此外还支持开发者将数据上传到云进行大数据质量度量。
14
15**图 1** HiSysEvent架构图<a name="fig1514425244110"></a>
16
17
18![](figures/zh-cn_image_0000001115534248.png)
19
20## 目录<a name="section161941989596"></a>
21
22```
23/base/hiviewdfx/hisysevent # hisysevent部件代码
24├── adapter # 平台适配
25│ └── native # C++适配
26├── frameworks # 框架代码
27│ └── native # 对内部子系统暴露的C++接口
28├── interfaces # 对外接口存放目录
29 └── native # C++接口
30 └── innerkits # 对内部子系统暴露的C++接口
31```
32
33## 说明<a name="section1312121216216"></a>
34
35### 接口说明<a name="section1551164914237"></a>
36
37C++埋点接口如下:
38
39**表 1** HiSysEvent接口介绍
40
41<a name="table1972602519328"></a>
42<table><thead align="left"><tr id="row5726112593219"><th class="cellrowborder" valign="top" width="57.38999999999999%" id="mcps1.2.3.1.1"><p id="p1472602523216"><a name="p1472602523216"></a><a name="p1472602523216"></a>接口名</p>
43</th>
44<th class="cellrowborder" valign="top" width="42.61%" id="mcps1.2.3.1.2"><p id="p12726112512322"><a name="p12726112512322"></a><a name="p12726112512322"></a>描述</p>
45</th>
46</tr>
47</thead>
48<tbody><tr id="row47261259328"><td class="cellrowborder" valign="top" width="57.38999999999999%" headers="mcps1.2.3.1.1 "><p id="p15726112583213"><a name="p15726112583213"></a><a name="p15726112583213"></a>template<typename... Types> static int Write(const std::string &domain, const std::string &eventName, EventType type, Types... keyValues)</p>
49</td>
50<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>接口功能:记录系统事件。</p>
51<p id="p167271525203213"><a name="p167271525203213"></a><a name="p167271525203213"></a>输入参数:</p>
52<a name="ul0727102516327"></a><a name="ul0727102516327"></a><ul id="ul0727102516327"><li><strong id="b2019634817576">domain</strong>:事件的相关领域,需要使用预置领域请参考Domain,可自定义领域。自定义领域长度在16个字符以内,有效的字符是0-9、a-z, A-Z、_,以字母开头。</li><li><strong id="b2019634817578">eventName</strong>:事件名,长度在32个字符以内,有效的字符是0-9、a-z, A-Z、_,以字母开头。</li><li><strong id="b2019634817579">type</strong>:事件类型,参考EventType。</li><li><strong id="b2019634817580">keyValues</strong>:事件参数键值对,支持<strong id="b2019634917677">基本类型、std::string,以及std::vector<基本类型>、std:vector<std::string></strong>。参数名长度在48个字符以内,有效的字符是0-9、a-z, A-Z、_,以字母开头。事件参数键值对的个数不超过128个。</li></ul>
53<p id="p1727152513217"><a name="p1727152513217"></a><a name="p1727152513217"></a>返回值:成功返回<strong id="b2019634817677">0</strong>,错误返回小于0的值。</p>
54</td>
55</tr>
56</tbody>
57</table>
58
59### 使用说明<a name="section129654513264"></a>
60
61C++接口实例
62
631. 源代码开发
64
65 在类定义头文件或者类实现源文件中,包含HiSysEvent头文件:
66
67 ```
68 #include "hisysevent.h"
69 ```
70
71 假设在业务关注应用启动时间start\_app,在业务类实现相关源文件中使用(调用接口埋点):
72
73 ```
74 HiSysEvent::Write(HiSysEvent::Domain::AAFWK, "start_app", HiSysEvent::EventType::BEHAVIOR, "app_name", "com.demo");
75 ```
76
772. 编译设置,在BUILD.gn里增加子系统SDK依赖:
78
79 ```
80 external_deps = [ "hisysevent:libhisysevent" ]
81 ```
82
83
84## 相关仓<a name="section1371113476307"></a>
85
86[DFX子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/DFX%E5%AD%90%E7%B3%BB%E7%BB%9F.md)
87
88[hiviewdfx\_hiview](https://gitee.com/openharmony/hiviewdfx_hiview/blob/master/README_zh.md)
89
90[hiviewdfx\_hilog](https://gitee.com/openharmony/hiviewdfx_hilog/blob/master/README_zh.md)
91
92[hiviewdfx\_hiappevent](https://gitee.com/openharmony/hiviewdfx_hiappevent/blob/master/README_zh.md)
93
94**hiviewdfx\_hisysevent**
95
96[hiviewdfx\_faultloggerd](https://gitee.com/openharmony/hiviewdfx_faultloggerd/blob/master/README_zh.md)
97
98[hiviewdfx\_hilog\_lite](https://gitee.com/openharmony/hiviewdfx_hilog_lite/blob/master/README_zh.md)
99
100[hiviewdfx\_hievent\_lite](https://gitee.com/openharmony/hiviewdfx_hievent_lite/blob/master/README_zh.md)
101
102[hiviewdfx\_hiview\_lite](https://gitee.com/openharmony/hiviewdfx_hiview_lite/blob/master/README_zh.md)
103
104