1 /*
2 * Copyright (c) 2022-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "sys_usage_event.h"
16
17 #include "hiview_logger.h"
18 #include "usage_event_common.h"
19
20 namespace OHOS {
21 namespace HiviewDFX {
22 DEFINE_LOG_TAG("SysUsageEvent");
23 using namespace SysUsageEventSpace;
24
SysUsageEvent(const std::string & name,HiSysEvent::EventType type)25 SysUsageEvent::SysUsageEvent(const std::string &name, HiSysEvent::EventType type)
26 : LoggerEvent(name, type)
27 {
28 this->paramMap_ = {
29 {KEY_OF_START, DEFAULT_UINT64}, {KEY_OF_END, DEFAULT_UINT64},
30 {KEY_OF_POWER, DEFAULT_UINT64}, {KEY_OF_RUNNING, DEFAULT_UINT64}
31 };
32 }
33
Report()34 void SysUsageEvent::Report()
35 {
36 ReportDFX();
37 ReportDFXUE();
38 }
39
ReportDFX()40 void SysUsageEvent::ReportDFX()
41 {
42 auto ret = HiSysEventWrite(HiSysEvent::Domain::HIVIEWDFX, this->eventName_, this->eventType_,
43 KEY_OF_START, this->paramMap_[KEY_OF_START].GetUint64(),
44 KEY_OF_END, this->paramMap_[KEY_OF_END].GetUint64(),
45 KEY_OF_POWER, this->paramMap_[KEY_OF_POWER].GetUint64(),
46 KEY_OF_RUNNING, this->paramMap_[KEY_OF_RUNNING].GetUint64());
47 if (ret != 0) {
48 HIVIEW_LOGW("failed to report sys usage event, ret=%{public}d", ret);
49 }
50 }
51
ReportDFXUE()52 void SysUsageEvent::ReportDFXUE()
53 {
54 auto ret = HiSysEventWrite(DomainSpace::HIVIEWDFX_UE_DOMAIN, this->eventName_, this->eventType_,
55 KEY_OF_START, this->paramMap_[KEY_OF_START].GetUint64(),
56 KEY_OF_END, this->paramMap_[KEY_OF_END].GetUint64(),
57 KEY_OF_POWER, this->paramMap_[KEY_OF_POWER].GetUint64(),
58 KEY_OF_RUNNING, this->paramMap_[KEY_OF_RUNNING].GetUint64());
59 if (ret != 0) {
60 HIVIEW_LOGW("failed to report sys usage event, ret=%{public}d", ret);
61 }
62 }
63 } // namespace HiviewDFX
64 } // namespace OHOS
65