HiSysEvent Query
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:
|
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:
None. |
void HiSysEventQueryCallBack::OnComplete(int32_t reason, int32_t total) | Callback object for completion of event query. Input arguments:
None. |
Development Example
C++
-
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<int64_t>& 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<QueryRule>& queryRules, std::shared_ptr<HiSysEventQueryCallBack> 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. std::shared_ptr<HiSysEventToolQuery> queryCallBack = nullptr; try { queryCallBack = std::make_shared<HiSysEventToolQuery>(); } catch(...) { // Catch exception thrown by make_shared } if (queryCallBack != nullptr) { struct QueryArg args(clientCmdArg.beginTime, clientCmdArg.endTime, clientCmdArg.maxEvents); std::vector<QueryRule> rules; HiSysEventManager::QueryHiSysEvent(args, rules, queryCallBack); }
-
-
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", ]