1 /*
2 * Copyright (c) 2022 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
16 #include "thermal_hisysevent.h"
17
18 #define HISYSEVENT_PERIOD 5
19 #define HISYSEVENT_THRESHOLD 200
20 #include "hisysevent.h"
21 #include "thermal_log.h"
22
23 namespace OHOS {
24 namespace PowerMgr {
25 template<typename... Types>
WriteEvent(const std::string & eventType,Types...args)26 static void WriteEvent(const std::string& eventType, Types... args)
27 {
28 int ret = HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::THERMAL, eventType,
29 HiviewDFX::HiSysEvent::EventType::STATISTIC, args...);
30 if (ret != 0) {
31 THERMAL_HILOGE(COMP_SVC, "Write event fail: %{public}s", eventType.c_str());
32 }
33 }
34
WriteLevelChangedHiSysEvent(bool enableEvent,int32_t level)35 void WriteLevelChangedHiSysEvent(bool enableEvent, int32_t level)
36 {
37 if (enableEvent) {
38 WriteEvent("LEVEL_CHANGED", "LEVEL", level);
39 }
40 }
41
WriteActionTriggeredHiSysEvent(bool enableEvent,const std::string & actionName,int32_t value)42 void WriteActionTriggeredHiSysEvent(bool enableEvent, const std::string& actionName, int32_t value)
43 {
44 if (enableEvent) {
45 WriteEvent("ACTION_TRIGGERED", "ACTION", actionName, "VALUE", value);
46 }
47 }
48
WriteActionTriggeredHiSysEventWithRatio(bool enableEvent,const std::string & actionName,float value)49 void WriteActionTriggeredHiSysEventWithRatio(bool enableEvent, const std::string& actionName, float value)
50 {
51 if (enableEvent) {
52 WriteEvent("ACTION_TRIGGERED", "ACTION", actionName, "RATIO", value);
53 }
54 }
55
56 template<typename... Types>
WriteFaultEvent(const std::string & eventType,Types...args)57 static void WriteFaultEvent(const std::string& eventType, Types... args)
58 {
59 int ret = HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::THERMAL, eventType,
60 HiviewDFX::HiSysEvent::EventType::FAULT, args...);
61 if (ret != 0) {
62 THERMAL_HILOGE(COMP_SVC, "Write fault event fail: %{public}s", eventType.c_str());
63 }
64 }
65
WriteFanFaultEvent(int32_t faultId,std::string msg)66 void WriteFanFaultEvent(int32_t faultId, std::string msg)
67 {
68 WriteFaultEvent("FAN_FAULT", "ID", faultId, "MSG", msg);
69 }
70
71 } // namespace PowerMgr
72 } // namespace OHOS
73