1 /* 2 * Copyright (C) 2021 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 "include/GPU.h" 16 #include <iostream> 17 #include "include/sp_utils.h" 18 #include "gpu_collector.h" 19 #include "collect_result.h" 20 #include "include/sp_log.h" 21 22 using namespace OHOS::HiviewDFX; 23 using namespace OHOS::HiviewDFX::UCollectUtil; 24 using namespace OHOS::HiviewDFX::UCollect; 25 26 namespace OHOS { 27 namespace SmartPerf { ItemData()28std::map<std::string, std::string> GPU::ItemData() 29 { 30 std::map<std::string, std::string> result; 31 int32_t freq = GetGpuFreq(); 32 float load = GetGpuLoad(); 33 result["gpuFrequency"] = std::to_string(freq); 34 result["gpuLoad"] = std::to_string(load); 35 return result; 36 } 37 GetGpuFreq()38int GPU::GetGpuFreq() 39 { 40 std::shared_ptr<GpuCollector> collector = GpuCollector::Create(); 41 CollectResult<GpuFreq> result = collector->CollectGpuFrequency(); 42 LOGI("GpuFrequency: %s", std::to_string(result.data.curFeq).c_str()); 43 return result.data.curFeq; 44 } 45 GetGpuLoad()46float GPU::GetGpuLoad() 47 { 48 std::shared_ptr<GpuCollector> collector = GpuCollector::Create(); 49 CollectResult<SysGpuLoad> result = collector->CollectSysGpuLoad(); 50 LOGI("SysGpuLoad: %s", std::to_string(result.data.gpuLoad).c_str()); 51 return float(result.data.gpuLoad); 52 } 53 } 54 } 55