1 /*
2 * Copyright (c) 2023-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
16 #include "gpu_decorator.h"
17 #include "decorator_util.h"
18
19 namespace OHOS {
20 namespace HiviewDFX {
21 namespace UCollectUtil {
22 constexpr char GPU_COLLECTOR_NAME[] = "GpuCollector";
23 StatInfoWrapper GpuDecorator::statInfoWrapper_;
24
CollectGpuFrequency()25 CollectResult<GpuFreq> GpuDecorator::CollectGpuFrequency()
26 {
27 auto task = [this] { return gpuCollector_->CollectGpuFrequency(); };
28 return Invoke(task, statInfoWrapper_, std::string(GPU_COLLECTOR_NAME) + UC_SEPARATOR + __func__);
29 }
CollectSysGpuLoad()30 CollectResult<SysGpuLoad> GpuDecorator::CollectSysGpuLoad()
31 {
32 auto task = [this] { return gpuCollector_->CollectSysGpuLoad(); };
33 return Invoke(task, statInfoWrapper_, std::string(GPU_COLLECTOR_NAME) + UC_SEPARATOR + __func__);
34 }
35
SaveStatCommonInfo()36 void GpuDecorator::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 GpuDecorator::ResetStatInfo()
47 {
48 statInfoWrapper_.ResetStatInfo();
49 }
50 } // namespace UCollectUtil
51 } // namespace HiviewDFX
52 } // namespace OHOS
53