• 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 "../interface/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             void StartExecutionOnce(bool isPause) override;
43             void FinishtExecutionOnce(bool isPause) override;
44 
GetInstance()45             static GpuCounter &GetInstance()
46             {
47                 static GpuCounter instance;
48                 return instance;
49             }
50             void StartCollect(GcCollectType type);
51             void StopCollect();
52             std::vector<std::string> &GetGpuCounterData();
53             std::vector<std::string> &GetGpuCounterSaveReportData();
54             void AddGpuCounterRealtimeData(const std::string& dataString);
55             void SetSavePathDirectory(const std::string& dir);
56             void SaveData(const std::string& path);
57             void SetFrequency(const int& freq);
58             std::mutex &GetGpuCounterLock();
59             void SetIsPause(bool isPause);
60             std::map<std::string, std::string> GetGpuRealtimeData();
61         private:
GpuCounter()62             GpuCounter() {};
63             GpuCounter(const GpuCounter &);
64             GpuCounter &operator = (const GpuCounter &);
65             GcStatus gcStatus = GC_INIT;
66             std::vector<std::string> gpuCounterData;
67             std::vector<std::string> gpuCounterSaveReportData;
68             std::mutex realtimeDataLock;
69             std::mutex gpuCounterLock;
70             std::string gpuCounterRealtimeData;
71             const std::string createPlugin = "onCreatePlugin";
72             std::string savePathDirectory_ {"/data/local/tmp/"};
73             int frequency = 50;
74             bool isPause_ {false};
75         };
76     };
77 }
78 
79 
80 #endif
81