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 
18 namespace OHOS {
19 namespace HiviewDFX {
20 namespace UCollectUtil {
21 const std::string GPU_COLLECTOR_NAME = "GpuCollector";
22 StatInfoWrapper GpuDecorator::statInfoWrapper_;
23 
CollectGpuFrequency()24 CollectResult<GpuFreq> GpuDecorator::CollectGpuFrequency()
25 {
26     auto task = [this] { return gpuCollector_->CollectGpuFrequency(); };
27     return Invoke(task, statInfoWrapper_, GPU_COLLECTOR_NAME + UC_SEPARATOR + __func__);
28 }
CollectSysGpuLoad()29 CollectResult<SysGpuLoad> GpuDecorator::CollectSysGpuLoad()
30 {
31     auto task = [this] { return gpuCollector_->CollectSysGpuLoad(); };
32     return Invoke(task, statInfoWrapper_, GPU_COLLECTOR_NAME + UC_SEPARATOR + __func__);
33 }
34 
SaveStatCommonInfo()35 void GpuDecorator::SaveStatCommonInfo()
36 {
37     std::map<std::string, StatInfo> statInfo = statInfoWrapper_.GetStatInfo();
38     std::vector<std::string> formattedStatInfo;
39     for (const auto& record : statInfo) {
40         formattedStatInfo.push_back(record.second.ToString());
41     }
42     WriteLinesToFile(formattedStatInfo, false);
43 }
44 
ResetStatInfo()45 void GpuDecorator::ResetStatInfo()
46 {
47     statInfoWrapper_.ResetStatInfo();
48 }
49 } // namespace UCollectUtil
50 } // namespace HiviewDFX
51 } // namespace OHOS
52