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 <iostream>
16 #include "include/sp_utils.h"
17 #include "include/GPU.h"
18 namespace OHOS {
19 namespace SmartPerf {
ItemData()20 std::map<std::string, std::string> GPU::ItemData()
21 {
22 std::map<std::string, std::string> result;
23 int freq = GetGpuFreq();
24 float load = GetGpuLoad();
25 result["gpuFrequency"] = std::to_string(freq);
26 result["gpuLoad"] = std::to_string(load);
27 return result;
28 }
29
GetGpuFreq()30 int GPU::GetGpuFreq()
31 {
32 std::string gpuFreq;
33 for (auto path : gpuCurFreqPaths) {
34 if (SPUtils::FileAccess(path)) {
35 SPUtils::LoadFile(path, gpuFreq);
36 }
37 }
38 return atoi(gpuFreq.c_str());
39 }
GetGpuLoad()40 float GPU::GetGpuLoad()
41 {
42 std::vector<std::string> sps;
43 std::string bufferLine;
44 for (auto path : gpuCurLoadPaths) {
45 if (SPUtils::FileAccess(path)) {
46 SPUtils::LoadFile(path, bufferLine);
47 }
48 }
49 SPUtils::StrSplit(bufferLine, "@", sps);
50 if (sps.size() > 0) {
51 // rk3568
52 float loadRk = std::stof(sps[0]);
53 return loadRk;
54 } else {
55 // wgr
56 float loadWgr = std::stof(bufferLine);
57 return loadWgr;
58 }
59 return -1.0;
60 }
61 }
62 }
63