137a09cd7Sopenharmony_ci/*
237a09cd7Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
337a09cd7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
437a09cd7Sopenharmony_ci * you may not use this file except in compliance with the License.
537a09cd7Sopenharmony_ci * You may obtain a copy of the License at
637a09cd7Sopenharmony_ci *
737a09cd7Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
837a09cd7Sopenharmony_ci *
937a09cd7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1037a09cd7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1137a09cd7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1237a09cd7Sopenharmony_ci * See the License for the specific language governing permissions and
1337a09cd7Sopenharmony_ci * limitations under the License.
1437a09cd7Sopenharmony_ci */
1537a09cd7Sopenharmony_ci
1637a09cd7Sopenharmony_ci#include "thermal_hisysevent.h"
1737a09cd7Sopenharmony_ci
1837a09cd7Sopenharmony_ci#define HISYSEVENT_PERIOD 5
1937a09cd7Sopenharmony_ci#define HISYSEVENT_THRESHOLD 200
2037a09cd7Sopenharmony_ci#ifdef HAS_HIVIEWDFX_HISYSEVENT_PART
2137a09cd7Sopenharmony_ci#include "hisysevent.h"
2237a09cd7Sopenharmony_ci#endif
2337a09cd7Sopenharmony_ci#include "thermal_log.h"
2437a09cd7Sopenharmony_ci
2537a09cd7Sopenharmony_cinamespace OHOS {
2637a09cd7Sopenharmony_cinamespace PowerMgr {
2737a09cd7Sopenharmony_citemplate<typename... Types>
2837a09cd7Sopenharmony_cistatic void WriteEvent(const std::string& eventType, Types... args)
2937a09cd7Sopenharmony_ci{
3037a09cd7Sopenharmony_ci#ifdef HAS_HIVIEWDFX_HISYSEVENT_PART
3137a09cd7Sopenharmony_ci    int ret = HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::THERMAL, eventType,
3237a09cd7Sopenharmony_ci        HiviewDFX::HiSysEvent::EventType::STATISTIC, args...);
3337a09cd7Sopenharmony_ci    if (ret != 0) {
3437a09cd7Sopenharmony_ci        THERMAL_HILOGE(COMP_SVC, "Write event fail: %{public}s", eventType.c_str());
3537a09cd7Sopenharmony_ci    }
3637a09cd7Sopenharmony_ci#endif
3737a09cd7Sopenharmony_ci}
3837a09cd7Sopenharmony_ci
3937a09cd7Sopenharmony_civoid WriteLevelChangedHiSysEvent(bool enableEvent, int32_t level)
4037a09cd7Sopenharmony_ci{
4137a09cd7Sopenharmony_ci    if (enableEvent) {
4237a09cd7Sopenharmony_ci        WriteEvent("LEVEL_CHANGED", "LEVEL", level);
4337a09cd7Sopenharmony_ci    }
4437a09cd7Sopenharmony_ci}
4537a09cd7Sopenharmony_ci
4637a09cd7Sopenharmony_civoid WriteActionTriggeredHiSysEvent(bool enableEvent, const std::string& actionName, int32_t value)
4737a09cd7Sopenharmony_ci{
4837a09cd7Sopenharmony_ci    if (enableEvent) {
4937a09cd7Sopenharmony_ci        WriteEvent("ACTION_TRIGGERED", "ACTION", actionName, "VALUE", value);
5037a09cd7Sopenharmony_ci    }
5137a09cd7Sopenharmony_ci}
5237a09cd7Sopenharmony_ci
5337a09cd7Sopenharmony_civoid WriteActionTriggeredHiSysEventWithRatio(bool enableEvent, const std::string& actionName, float value)
5437a09cd7Sopenharmony_ci{
5537a09cd7Sopenharmony_ci    if (enableEvent) {
5637a09cd7Sopenharmony_ci        WriteEvent("ACTION_TRIGGERED", "ACTION", actionName, "RATIO", value);
5737a09cd7Sopenharmony_ci    }
5837a09cd7Sopenharmony_ci}
5937a09cd7Sopenharmony_ci
6037a09cd7Sopenharmony_citemplate<typename... Types>
6137a09cd7Sopenharmony_cistatic void WriteFaultEvent(const std::string& eventType, Types... args)
6237a09cd7Sopenharmony_ci{
6337a09cd7Sopenharmony_ci#ifdef HAS_HIVIEWDFX_HISYSEVENT_PART
6437a09cd7Sopenharmony_ci    int ret = HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::THERMAL, eventType,
6537a09cd7Sopenharmony_ci        HiviewDFX::HiSysEvent::EventType::FAULT, args...);
6637a09cd7Sopenharmony_ci    if (ret != 0) {
6737a09cd7Sopenharmony_ci        THERMAL_HILOGE(COMP_SVC, "Write fault event fail: %{public}s", eventType.c_str());
6837a09cd7Sopenharmony_ci    }
6937a09cd7Sopenharmony_ci#endif
7037a09cd7Sopenharmony_ci}
7137a09cd7Sopenharmony_ci
7237a09cd7Sopenharmony_civoid WriteFanFaultEvent(int32_t faultId, std::string msg)
7337a09cd7Sopenharmony_ci{
7437a09cd7Sopenharmony_ci    WriteFaultEvent("FAN_FAULT", "ID", faultId, "MSG", msg);
7537a09cd7Sopenharmony_ci}
7637a09cd7Sopenharmony_ci
7737a09cd7Sopenharmony_ci} // namespace PowerMgr
7837a09cd7Sopenharmony_ci} // namespace OHOS
79