# HiSysEvent Query - [Overview](#section279684125212) - [Development Guidelines](#section315316761113) - [Available APIs](#section03869128521) - [Development Example](#section14286111855212) ## Overview 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. ## Development Guidelines ### Available APIs **Table 1** Description of the HiSysEvent query API | Name| Description | | -------- | --------- | | bool HiSysEventManager::QueryHiSysEvent(struct QueryArg& queryArg, std::vector<QueryRule>& queryRules, std::shared_ptr<HiSysEventQueryCallBack> queryCallBack) | Queries system events by specifying search criteria such as the time segment, event domain, and event name.

Input arguments:Return value: | **Table 2** Description of QueryArg | Attribute| Description | | -------- | --------- | | beginTime | Start time, in the **long long int** format.| | endTime | End time, in the **long long int** format.| | maxEvents | Maximum number of returned events, in the **int** format.| **Table 3** Description of QueryRule | API| Description | | -------- | --------- | | QueryRule(const std::string& domain, const std::vector<std::string>& eventList) | Constructor used to create a **QueryRule** object.

Input arguments: | **Table 4** Description of HiSysEventQueryCallBack | API| Description | | -------- | --------- | | void HiSysEventQueryCallBack::OnQuery(const ::std::vector<std::string>& sysEvent, const ::std::vector<int64_t>& seq) | Callback object for event query.

Input arguments:Return value:
None.| | void HiSysEventQueryCallBack::OnComplete(int32_t reason, int32_t total) | Callback object for completion of event query.

Input arguments:Return value:
None.| ### Development Example C++ 1. Develop the source code. - Import the corresponding header file: hisysevent\_manager.h - Implement the callback API. void HiSysEventQueryCallBack::OnQuery\(const ::std::vector<std::string>& sysEvent, const ::std::vector& seq\) void HiSysEventQueryCallBack::OnComplete\(int32\_t reason, int32\_t total\) - Invoke the query API in the corresponding service logic. HiSysEventManager::QueryHiSysEvent\(struct QueryArg& queryArg, std::vector& queryRules, std::shared\_ptr queryCallBack\) ``` // In this example, you'll query all system events. #include "hisysevent_manager.h" #include namespace OHOS { namespace HiviewDFX { // Implement the query callback API. void HiSysEventToolQuery::OnQuery(const ::std::vector& sysEvent, const ::std::vector& 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(); struct QueryArg args(clientCmdArg.beginTime, clientCmdArg.endTime, clientCmdArg.maxEvents); std::vector 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", ] ```