106f6ba60Sopenharmony_ci/* 206f6ba60Sopenharmony_ci * Copyright (C) 2024 Huawei Device Co., Ltd. 306f6ba60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 406f6ba60Sopenharmony_ci * you may not use this file except in compliance with the License. 506f6ba60Sopenharmony_ci * You may obtain a copy of the License at 606f6ba60Sopenharmony_ci * 706f6ba60Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 806f6ba60Sopenharmony_ci * 906f6ba60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1006f6ba60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1106f6ba60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1206f6ba60Sopenharmony_ci * See the License for the specific language governing permissions and 1306f6ba60Sopenharmony_ci * limitations under the License. 1406f6ba60Sopenharmony_ci */ 1506f6ba60Sopenharmony_ci 1606f6ba60Sopenharmony_ci#ifndef GPU_COUNTER_CALLBACK_H 1706f6ba60Sopenharmony_ci#define GPU_COUNTER_CALLBACK_H 1806f6ba60Sopenharmony_ci#include "vector" 1906f6ba60Sopenharmony_ci 2006f6ba60Sopenharmony_cinamespace OHOS { 2106f6ba60Sopenharmony_ci namespace SmartPerf { 2206f6ba60Sopenharmony_ci struct GpuPerfInfo { 2306f6ba60Sopenharmony_ci int64_t remainTime = 0; 2406f6ba60Sopenharmony_ci int64_t startTime = 0; 2506f6ba60Sopenharmony_ci int32_t duration = 0; 2606f6ba60Sopenharmony_ci uint32_t gpuActive = 0; 2706f6ba60Sopenharmony_ci uint32_t drawCalls = 0; 2806f6ba60Sopenharmony_ci uint64_t primitives = 0; 2906f6ba60Sopenharmony_ci uint64_t vertexCounts = 0; 3006f6ba60Sopenharmony_ci uint64_t totalInstruments = 0; 3106f6ba60Sopenharmony_ci uint32_t gpuLoadPercentage = 0; 3206f6ba60Sopenharmony_ci uint32_t vertexLoadPercentage = 0; 3306f6ba60Sopenharmony_ci uint32_t fragmentLoadPercentage = 0; 3406f6ba60Sopenharmony_ci uint32_t computeLoadPercentage = 0; 3506f6ba60Sopenharmony_ci uint32_t textureLoadPercentage = 0; 3606f6ba60Sopenharmony_ci uint32_t memoryReadBandwidth = 0; 3706f6ba60Sopenharmony_ci uint32_t memoryWriteBandwidth = 0; 3806f6ba60Sopenharmony_ci uint32_t memoryBandwidthPercentage = 0; 3906f6ba60Sopenharmony_ci }; 4006f6ba60Sopenharmony_ci 4106f6ba60Sopenharmony_ci class GpuCounterCallback { 4206f6ba60Sopenharmony_ci public: 4306f6ba60Sopenharmony_ci GpuCounterCallback() = default; 4406f6ba60Sopenharmony_ci virtual ~GpuCounterCallback() = default; 4506f6ba60Sopenharmony_ci virtual int OnGpuData(std::vector <GpuPerfInfo> &gpuPerfInfos) = 0; 4606f6ba60Sopenharmony_ci }; 4706f6ba60Sopenharmony_ci 4806f6ba60Sopenharmony_ci class GpuCounterCallbackImpl : public GpuCounterCallback { 4906f6ba60Sopenharmony_ci public: 5006f6ba60Sopenharmony_ci GpuCounterCallbackImpl(); 5106f6ba60Sopenharmony_ci int OnGpuData(std::vector <GpuPerfInfo> &gpuPerfInfos) override; 5206f6ba60Sopenharmony_ci 5306f6ba60Sopenharmony_ci private: 5406f6ba60Sopenharmony_ci void GetRealTime(GpuPerfInfo *newData); 5506f6ba60Sopenharmony_ci void JoinSocketDataValue(GpuPerfInfo *newData); 5606f6ba60Sopenharmony_ci unsigned long long JoinSocketDataPercentFunction(uint32_t itemFirst, int32_t durationFirst, 5706f6ba60Sopenharmony_ci uint32_t itemSecond, int32_t durationSecond) const; 5806f6ba60Sopenharmony_ci void JoinSocketDataPercent(GpuPerfInfo *newData); 5906f6ba60Sopenharmony_ci void JoinSocketData(GpuPerfInfo *newData); 6006f6ba60Sopenharmony_ci unsigned long long SplitSocketDataValueFunction(uint32_t value, int32_t interval, int32_t duration) const; 6106f6ba60Sopenharmony_ci void SplitSocketDataValue(int32_t interval); 6206f6ba60Sopenharmony_ci void SplitSocketDataPercent(); 6306f6ba60Sopenharmony_ci void SplitSocketData(); 6406f6ba60Sopenharmony_ci std::vector<GpuPerfInfo> gpuCounter; 6506f6ba60Sopenharmony_ci const long long collectInterval = 50; 6606f6ba60Sopenharmony_ci const int64_t maxTime = 10800000; 6706f6ba60Sopenharmony_ci const int64_t restartTime = 300000; 6806f6ba60Sopenharmony_ci const int32_t maxDuration = 1000; 6906f6ba60Sopenharmony_ci GpuPerfInfo realtimeGpuPerfInfoData; 7006f6ba60Sopenharmony_ci }; 7106f6ba60Sopenharmony_ci } 7206f6ba60Sopenharmony_ci} 7306f6ba60Sopenharmony_ci 7406f6ba60Sopenharmony_ci#endif 75