• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_collector_impl.h"
17 
18 #include <sstream>
19 
20 #include "common_util.h"
21 #include "file_util.h"
22 #include "gpu_decorator.h"
23 #include "hiview_logger.h"
24 
25 using namespace OHOS::HiviewDFX::UCollect;
26 
27 namespace OHOS {
28 namespace HiviewDFX {
29 namespace UCollectUtil {
30 DEFINE_LOG_TAG("UCollectUtil");
Create()31 std::shared_ptr<GpuCollector> GpuCollector::Create()
32 {
33     return std::make_shared<GpuDecorator>(std::make_shared<GpuCollectorImpl>());
34 }
35 
CollectGpuFrequency()36 CollectResult<GpuFreq> GpuCollectorImpl::CollectGpuFrequency()
37 {
38     CollectResult<GpuFreq> result;
39     GpuFreq& gpuFreq = result.data;
40     gpuFreq.curFeq = CommonUtil::ReadNodeWithOnlyNumber(GPU_CUR_FREQ);
41     gpuFreq.maxFeq = CommonUtil::ReadNodeWithOnlyNumber(GPU_MAX_FREQ);
42     gpuFreq.minFeq = CommonUtil::ReadNodeWithOnlyNumber(GPU_MIN_FREQ);
43     HIVIEW_LOGD("curFeq=%{public}d,maxFeq=%{public}d,minFeq=%{public}d",
44         gpuFreq.curFeq, gpuFreq.maxFeq, gpuFreq.minFeq);
45     result.retCode = UcError::SUCCESS;
46     return result;
47 }
48 
CollectSysGpuLoad()49 CollectResult<SysGpuLoad> GpuCollectorImpl::CollectSysGpuLoad()
50 {
51     CollectResult<SysGpuLoad> result;
52     SysGpuLoad& sysGpuLoad = result.data;
53     sysGpuLoad.gpuLoad = CommonUtil::ReadNodeWithOnlyNumber(GPU_LOAD);
54     HIVIEW_LOGD("gpuLoad=%{public}f", sysGpuLoad.gpuLoad);
55     result.retCode = UcError::SUCCESS;
56     return result;
57 }
58 } // UCollectUtil
59 } // HiViewDFX
60 } // OHOS
61