• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_H
17 #define GPU_COUNTER_H
18 
19 #include "string"
20 #include "vector"
21 #include "sp_profiler.h"
22 #include "GpuCounterCallback.h"
23 #include "thread"
24 #include "mutex"
25 
26 namespace OHOS {
27     namespace SmartPerf {
28         class GpuCounter : public SpProfiler {
29         public:
30             enum GcStatus {
31                 GC_INIT = 0,
32                 GC_RUNNING,
33             };
34 
35             enum GcCollectType {
36                 GC_START = 0,
37                 GC_RESTART,
38             };
39 
40         public:
41             std::map<std::string, std::string> ItemData() override;
42 
GetInstance()43             static GpuCounter &GetInstance()
44             {
45                 static GpuCounter instance;
46                 return instance;
47             }
48             void StartCollect(GcCollectType type);
49             void StopCollect();
50             std::vector<std::string> &GetGpuCounterData();
51             std::vector<std::string> &GetGpuCounterSaveReportData();
52             std::mutex &GetRealtimeDataLock();
53             std::string &GetGpuCounterRealtimeData();
54             void AddGpuCounterRealtimeData(std::string dataString);
55             void GetGpuRealtimeData(std::map<std::string, std::string> &dataMap);
56             void SaveData(std::string path);
57         private:
GpuCounter()58             GpuCounter() {};
59             GpuCounter(const GpuCounter &);
60             GpuCounter &operator = (const GpuCounter &);
61             GcStatus gcStatus = GC_INIT;
62             std::vector<std::string> gpuCounterData;
63             std::vector<std::string> gpuCounterSaveReportData;
64             std::mutex realtimeDataLock;
65             std::string gpuCounterRealtimeData;
66             const std::string createPlugin = "onCreatePlugin";
67         };
68     };
69 }
70 
71 
72 #endif
73