1 /*
2 * Copyright (c) 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 "thermal_decorator.h"
16 #include "decorator_util.h"
17
18 namespace OHOS {
19 namespace HiviewDFX {
20 namespace UCollectUtil {
21 constexpr char THERMAL_COLLECTOR_NAME[] = "ThermalCollector";
22 StatInfoWrapper ThermalDecorator::statInfoWrapper_;
23
CollectDevThermal(ThermalZone thermalZone)24 CollectResult<int32_t> ThermalDecorator::CollectDevThermal(ThermalZone thermalZone)
25 {
26 auto task = [this, thermalZone] { return thermalCollector_->CollectDevThermal(thermalZone); };
27 return Invoke(task, statInfoWrapper_, std::string(THERMAL_COLLECTOR_NAME) + UC_SEPARATOR + __func__);
28 }
29
CollectThermaLevel()30 CollectResult<uint32_t> ThermalDecorator::CollectThermaLevel()
31 {
32 auto task = [this] { return thermalCollector_->CollectThermaLevel(); };
33 return Invoke(task, statInfoWrapper_, std::string(THERMAL_COLLECTOR_NAME) + UC_SEPARATOR + __func__);
34 }
35
SaveStatCommonInfo()36 void ThermalDecorator::SaveStatCommonInfo()
37 {
38 std::map<std::string, StatInfo> statInfo = statInfoWrapper_.GetStatInfo();
39 std::list<std::string> formattedStatInfo;
40 for (const auto& record : statInfo) {
41 formattedStatInfo.push_back(record.second.ToString());
42 }
43 WriteLinesToFile(formattedStatInfo, false, UC_STAT_LOG_PATH);
44 }
45
ResetStatInfo()46 void ThermalDecorator::ResetStatInfo()
47 {
48 statInfoWrapper_.ResetStatInfo();
49 }
50 } // namespace UCollectUtil
51 } // namespace HiviewDFX
52 } // namespace OHOS
53