1/* 2 * Copyright (C) 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#ifndef GPU_COUNTER_CALLBACK_H 17#define GPU_COUNTER_CALLBACK_H 18#include "vector" 19 20namespace OHOS { 21 namespace SmartPerf { 22 struct GpuPerfInfo { 23 int64_t remainTime = 0; 24 int64_t startTime = 0; 25 int32_t duration = 0; 26 uint32_t gpuActive = 0; 27 uint32_t drawCalls = 0; 28 uint64_t primitives = 0; 29 uint64_t vertexCounts = 0; 30 uint64_t totalInstruments = 0; 31 uint32_t gpuLoadPercentage = 0; 32 uint32_t vertexLoadPercentage = 0; 33 uint32_t fragmentLoadPercentage = 0; 34 uint32_t computeLoadPercentage = 0; 35 uint32_t textureLoadPercentage = 0; 36 uint32_t memoryReadBandwidth = 0; 37 uint32_t memoryWriteBandwidth = 0; 38 uint32_t memoryBandwidthPercentage = 0; 39 }; 40 41 class GpuCounterCallback { 42 public: 43 GpuCounterCallback() = default; 44 virtual ~GpuCounterCallback() = default; 45 virtual int OnGpuData(std::vector <GpuPerfInfo> &gpuPerfInfos) = 0; 46 }; 47 48 class GpuCounterCallbackImpl : public GpuCounterCallback { 49 public: 50 GpuCounterCallbackImpl(); 51 int OnGpuData(std::vector <GpuPerfInfo> &gpuPerfInfos) override; 52 53 private: 54 void GetRealTime(GpuPerfInfo *newData); 55 void JoinSocketDataValue(GpuPerfInfo *newData); 56 unsigned long long JoinSocketDataPercentFunction(uint32_t itemFirst, int32_t durationFirst, 57 uint32_t itemSecond, int32_t durationSecond) const; 58 void JoinSocketDataPercent(GpuPerfInfo *newData); 59 void JoinSocketData(GpuPerfInfo *newData); 60 unsigned long long SplitSocketDataValueFunction(uint32_t value, int32_t interval, int32_t duration) const; 61 void SplitSocketDataValue(int32_t interval); 62 void SplitSocketDataPercent(); 63 void SplitSocketData(); 64 std::vector<GpuPerfInfo> gpuCounter; 65 const long long collectInterval = 50; 66 const int64_t maxTime = 10800000; 67 const int64_t restartTime = 300000; 68 const int32_t maxDuration = 1000; 69 GpuPerfInfo realtimeGpuPerfInfoData; 70 }; 71 } 72} 73 74#endif 75