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 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