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_H 1706f6ba60Sopenharmony_ci#define GPU_COUNTER_H 1806f6ba60Sopenharmony_ci 1906f6ba60Sopenharmony_ci#include "string" 2006f6ba60Sopenharmony_ci#include "vector" 2106f6ba60Sopenharmony_ci#include "sp_profiler.h" 2206f6ba60Sopenharmony_ci#include "GpuCounterCallback.h" 2306f6ba60Sopenharmony_ci#include "thread" 2406f6ba60Sopenharmony_ci#include "mutex" 2506f6ba60Sopenharmony_ci 2606f6ba60Sopenharmony_cinamespace OHOS { 2706f6ba60Sopenharmony_ci namespace SmartPerf { 2806f6ba60Sopenharmony_ci class GpuCounterPlugin { 2906f6ba60Sopenharmony_ci public: 3006f6ba60Sopenharmony_ci uint32_t version; 3106f6ba60Sopenharmony_ci const char *pluginName; 3206f6ba60Sopenharmony_ci 3306f6ba60Sopenharmony_ci virtual int32_t StartGetGpuPerfInfo(int64_t duration, std::unique_ptr <GpuCounterCallback> callback) = 0; 3406f6ba60Sopenharmony_ci virtual int32_t StopGetGpuPerfInfo() = 0; 3506f6ba60Sopenharmony_ci }; 3606f6ba60Sopenharmony_ci 3706f6ba60Sopenharmony_ci class GpuCounter : public SpProfiler { 3806f6ba60Sopenharmony_ci public: 3906f6ba60Sopenharmony_ci enum GcStatus { 4006f6ba60Sopenharmony_ci GC_INIT = 0, 4106f6ba60Sopenharmony_ci GC_RUNNING, 4206f6ba60Sopenharmony_ci }; 4306f6ba60Sopenharmony_ci 4406f6ba60Sopenharmony_ci enum GcCollectType { 4506f6ba60Sopenharmony_ci GC_START = 0, 4606f6ba60Sopenharmony_ci GC_RESTART, 4706f6ba60Sopenharmony_ci }; 4806f6ba60Sopenharmony_ci 4906f6ba60Sopenharmony_ci public: 5006f6ba60Sopenharmony_ci std::map<std::string, std::string> ItemData() override; 5106f6ba60Sopenharmony_ci 5206f6ba60Sopenharmony_ci static GpuCounter &GetInstance() 5306f6ba60Sopenharmony_ci { 5406f6ba60Sopenharmony_ci static GpuCounter instance; 5506f6ba60Sopenharmony_ci return instance; 5606f6ba60Sopenharmony_ci } 5706f6ba60Sopenharmony_ci void StartCollect(GcCollectType type); 5806f6ba60Sopenharmony_ci void StopCollect(); 5906f6ba60Sopenharmony_ci std::vector<std::string> &GetGpuCounterData(); 6006f6ba60Sopenharmony_ci std::vector<std::string> &GetGpuCounterSaveReportData(); 6106f6ba60Sopenharmony_ci std::mutex &GetRealtimeDataLock(); 6206f6ba60Sopenharmony_ci std::string &GetGpuCounterRealtimeData(); 6306f6ba60Sopenharmony_ci void AddGpuCounterRealtimeData(std::string dataString); 6406f6ba60Sopenharmony_ci void GetGpuRealtimeData(std::map<std::string, std::string> &dataMap); 6506f6ba60Sopenharmony_ci void SaveData(std::string path); 6606f6ba60Sopenharmony_ci private: 6706f6ba60Sopenharmony_ci GpuCounter() {}; 6806f6ba60Sopenharmony_ci GpuCounter(const GpuCounter &); 6906f6ba60Sopenharmony_ci GpuCounter &operator = (const GpuCounter &); 7006f6ba60Sopenharmony_ci void* GetSoHandle(); 7106f6ba60Sopenharmony_ci GcStatus gcStatus = GC_INIT; 7206f6ba60Sopenharmony_ci std::vector<std::string> gpuCounterData; 7306f6ba60Sopenharmony_ci std::vector<std::string> gpuCounterSaveReportData; 7406f6ba60Sopenharmony_ci std::mutex realtimeDataLock; 7506f6ba60Sopenharmony_ci std::string gpuCounterRealtimeData; 7606f6ba60Sopenharmony_ci const std::string PLUGIN_SO_PATH = "system/lib64/libgameservice_gpucounter_plugin.z.so"; 7706f6ba60Sopenharmony_ci const std::string CREATE_PLUGIN = "onCreatePlugin"; 7806f6ba60Sopenharmony_ci }; 7906f6ba60Sopenharmony_ci }; 8006f6ba60Sopenharmony_ci} 8106f6ba60Sopenharmony_ci 8206f6ba60Sopenharmony_ci 8306f6ba60Sopenharmony_ci#endif 84