• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 #include <iostream>
16 #include "include/CPU.h"
17 #include "include/DDR.h"
18 #include "include/GPU.h"
19 #include "include/FPS.h"
20 #include "include/profiler_fps.h"
21 #include "include/RAM.h"
22 #include "include/Network.h"
23 #include "include/Power.h"
24 #include "include/Temperature.h"
25 #include "include/ByTrace.h"
26 #include "include/sp_utils.h"
27 #include "include/sp_profiler_factory.h"
28 #include "include/Dubai.h"
29 #include "include/Capture.h"
30 #include "include/navigation.h"
31 #include "include/sp_log.h"
32 
33 namespace OHOS {
34 namespace SmartPerf {
GetProfilerItem(MessageType messageType)35 SpProfiler *SpProfilerFactory::GetProfilerItem(MessageType messageType)
36 {
37     SpProfiler* profiler = nullptr;
38     switch (messageType) {
39         case MessageType::GET_CPU_FREQ_LOAD:
40             profiler = &CPU::GetInstance();
41             break;
42         case MessageType::GET_FPS_AND_JITTERS:
43         case MessageType::GET_LOW_POWER_FPS:
44         case MessageType::GET_CUR_FPS:
45             profiler = &ProfilerFPS::GetInstance();
46             break;
47         case MessageType::GET_GPU_FREQ:
48         case MessageType::GET_GPU_LOAD:
49             profiler = &GPU::GetInstance();
50             break;
51         case MessageType::GET_DDR_FREQ:
52             profiler = &DDR::GetInstance();
53             break;
54         case MessageType::GET_RAM_INFO:
55             profiler = &RAM::GetInstance();
56             break;
57         default:
58             break;
59     }
60     if (profiler == nullptr) {
61         profiler = GetProfilerItemContinue(messageType);
62     }
63     return profiler;
64 }
65 
GetProfilerItemContinue(MessageType messageType)66 SpProfiler *SpProfilerFactory::GetProfilerItemContinue(MessageType messageType)
67 {
68     SpProfiler* profiler = nullptr;
69     switch (messageType) {
70         case MessageType::GET_TEMPERATURE:
71             profiler = &Temperature::GetInstance();
72             break;
73         case MessageType::GET_POWER:
74             profiler = &Power::GetInstance();
75             break;
76         case MessageType::CATCH_TRACE_CONFIG:
77             ProfilerFPS::GetInstance().SetTraceCatch();
78             break;
79         case MessageType::GET_CAPTURE:
80             Capture::GetInstance().SocketMessage();
81             profiler = &Capture::GetInstance();
82             break;
83         case MessageType::SET_DUBAI_DB:
84             DumpDubaiAndMoveDb();
85             break;
86         case MessageType::CATCH_NETWORK_TRAFFIC:
87         case MessageType::GET_NETWORK_TRAFFIC:
88             profiler = &Network::GetInstance();
89             break;
90         default:
91             break;
92     }
93     return profiler;
94 }
95 
DumpDubaiAndMoveDb()96 void SpProfilerFactory::DumpDubaiAndMoveDb()
97 {
98     Dubai::DumpDubaiBegin();
99     Dubai::DumpDubaiFinish();
100     Dubai::MoveDubaiDb();
101 }
102 
SetProfilerPkg(const std::string & pkg)103 void SpProfilerFactory::SetProfilerPkg(const std::string &pkg)
104 {
105     FPS &fps = FPS::GetInstance();
106     fps.SetPackageName(pkg);
107     ProfilerFPS &profilerFps = ProfilerFPS::GetInstance();
108     profilerFps.SetPackageName(pkg);
109     RAM &ram = RAM::GetInstance();
110     ram.SetPackageName(pkg);
111     CPU &cpu = CPU::GetInstance();
112     cpu.SetPackageName(pkg);
113 }
114 
SetProfilerPidByPkg(std::string & pid)115 void SpProfilerFactory::SetProfilerPidByPkg(std::string &pid)
116 {
117     FPS &fps = FPS::GetInstance();
118     fps.SetProcessId(pid);
119     ProfilerFPS &profilerFps = ProfilerFPS::GetInstance();
120     profilerFps.SetProcessId(pid);
121     RAM &ram = RAM::GetInstance();
122     ram.SetProcessId(pid);
123     CPU &cpu = CPU::GetInstance();
124     cpu.SetProcessId(pid);
125     Navigation &nav = Navigation::GetInstance();
126     nav.SetProcessId(pid);
127 }
128 
SetProfilerLayer(const std::string & layer)129 void SpProfilerFactory::SetProfilerLayer(const std::string &layer)
130 {
131     FPS &fps = FPS::GetInstance();
132     fps.SetLayerName(layer);
133 }
134 
SetProfilerGameLayer(const std::string & isGameView)135 void SpProfilerFactory::SetProfilerGameLayer(const std::string &isGameView)
136 {
137     ProfilerFPS &profilerFps = ProfilerFPS::GetInstance();
138     profilerFps.SetGameLayer(isGameView);
139 }
140 
SetByTrace(std::string message)141 void SpProfilerFactory::SetByTrace(std::string message)
142 {
143     std::vector<std::string> values;
144     std::string delimiter = "||";
145     std::string delim = "=";
146     SPUtils::StrSplit(message, delimiter, values);
147     int mSum = 0;
148     int mInterval = 0;
149     long long mThreshold = 0;
150     int lowFps = 0;
151     for (std::string vItem : values) {
152         std::vector<std::string> vItems;
153         SPUtils::StrSplit(vItem, delim, vItems);
154         if (vItems[0] == "traceSum") {
155             mSum = std::stoi(vItems[1]);
156         }
157         if (vItems[0] == "fpsJitterTime") {
158             mThreshold = std::stoi(vItems[1]);
159         }
160         if (vItems[0] == "catchInterval") {
161             mInterval = std::stoi(vItems[1]);
162         }
163         if (vItems[0] == "lowFps") {
164             lowFps = std::stoi(vItems[1]);
165         }
166     }
167     const ByTrace &bTrace = ByTrace::GetInstance();
168     if (message.find("traceSum") != std::string::npos) {
169         int mCurNum = 1;
170         bTrace.SetTraceConfig(mSum, mInterval, mThreshold, lowFps, mCurNum);
171     }
172 }
GetCmdProfilerItem(CommandType commandType,bool cmdFlag)173 SpProfiler *SpProfilerFactory::GetCmdProfilerItem(CommandType commandType, bool cmdFlag)
174 {
175     SpProfiler *profiler = nullptr;
176     switch (commandType) {
177         case CommandType::CT_C:
178             if (cmdFlag) {
179                 profiler = &CPU::GetInstance();
180             }
181             break;
182         case CommandType::CT_G:
183             profiler = &GPU::GetInstance();
184             break;
185         case CommandType::CT_F:
186             if (cmdFlag) {
187                 profiler = &FPS::GetInstance();
188             }
189             break;
190         case CommandType::CT_D:
191             profiler = &DDR::GetInstance();
192             break;
193         case CommandType::CT_P:
194             profiler = &Power::GetInstance();
195             break;
196         case CommandType::CT_T:
197             profiler = &Temperature::GetInstance();
198             break;
199         case CommandType::CT_R:
200             if (cmdFlag) {
201                 profiler = &RAM::GetInstance();
202             }
203             break;
204         case CommandType::CT_NET:
205             profiler = &Network::GetInstance();
206             break;
207         case CommandType::CT_NAV:
208             profiler = &Navigation::GetInstance();
209             break;
210         case CommandType::CT_TTRACE:
211             ProfilerFPS::GetInstance().SetTraceCatch();
212             break;
213         default:
214             break;
215     }
216     if (profiler == nullptr) {
217         profiler = GetCmdProfilerItemContinue(commandType, cmdFlag);
218     }
219     return profiler;
220 }
221 
GetCmdProfilerItemContinue(CommandType commandType,bool cmdFlag)222 SpProfiler *SpProfilerFactory::GetCmdProfilerItemContinue(CommandType commandType, bool cmdFlag)
223 {
224     SpProfiler *profiler = nullptr;
225     switch (commandType) {
226         case CommandType::CT_SNAPSHOT:
227             if (cmdFlag) {
228                 profiler = &Capture::GetInstance();
229             }
230             break;
231         default:
232             break;
233     }
234     return profiler;
235 }
236 }
237 }
238