• 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/AI_schedule.h"
17 #include "include/CPU.h"
18 #include "include/DDR.h"
19 #include "include/GetLog.h"
20 #include "include/GPU.h"
21 #include "include/FPS.h"
22 #include "include/profiler_fps.h"
23 #include "include/RAM.h"
24 #include "include/Network.h"
25 #include "include/Power.h"
26 #include "include/Temperature.h"
27 #include "include/ByTrace.h"
28 #include "include/sp_utils.h"
29 #include "include/sp_profiler_factory.h"
30 #include "include/Capture.h"
31 #include "include/navigation.h"
32 #include "include/sp_log.h"
33 
34 namespace OHOS {
35 namespace SmartPerf {
GetProfilerItem(MessageType messageType)36 SpProfiler *SpProfilerFactory::GetProfilerItem(MessageType messageType)
37 {
38     SpProfiler* profiler = nullptr;
39     switch (messageType) {
40         case MessageType::GET_CPU_FREQ_LOAD:
41             profiler = &CPU::GetInstance();
42             break;
43         case MessageType::GET_FPS_AND_JITTERS:
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         case MessageType::GET_LOG:
58             profiler = &GetLog::GetInstance();
59             break;
60         default:
61             break;
62     }
63     if (profiler == nullptr) {
64         profiler = GetProfilerItemContinue(messageType);
65     }
66     return profiler;
67 }
68 
GetProfilerItemContinue(MessageType messageType)69 SpProfiler *SpProfilerFactory::GetProfilerItemContinue(MessageType messageType)
70 {
71     SpProfiler* profiler = nullptr;
72     switch (messageType) {
73         case MessageType::GET_TEMPERATURE:
74             profiler = &Temperature::GetInstance();
75             break;
76         case MessageType::GET_POWER:
77             profiler = &Power::GetInstance();
78             break;
79         case MessageType::CATCH_TRACE_CONFIG:
80             ProfilerFPS::GetInstance().SetTraceCatch();
81             break;
82         case MessageType::GET_CAPTURE:
83             Capture::GetInstance().SocketMessage();
84             profiler = &Capture::GetInstance();
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 
SetProfilerPkg(const std::string & pkg)96 void SpProfilerFactory::SetProfilerPkg(const std::string &pkg)
97 {
98     LOGD("SpProfilerFactory setPKG:%s", pkg.c_str());
99     FPS &fps = FPS::GetInstance();
100     fps.SetPackageName(pkg);
101     ProfilerFPS &profilerFps = ProfilerFPS::GetInstance();
102     profilerFps.SetPackageName(pkg);
103     RAM &ram = RAM::GetInstance();
104     ram.SetPackageName(pkg);
105     CPU &cpu = CPU::GetInstance();
106     cpu.SetPackageName(pkg);
107 }
108 
SetProfilerPidByPkg(std::string & pid)109 void SpProfilerFactory::SetProfilerPidByPkg(std::string &pid)
110 {
111     LOGD("SpProfilerFactory setPID:%s", pid.c_str());
112     FPS &fps = FPS::GetInstance();
113     fps.SetProcessId(pid);
114     ProfilerFPS &profilerFps = ProfilerFPS::GetInstance();
115     profilerFps.SetProcessId(pid);
116     RAM &ram = RAM::GetInstance();
117     ram.SetProcessId(pid);
118     CPU &cpu = CPU::GetInstance();
119     cpu.SetProcessId(pid);
120     Navigation &nav = Navigation::GetInstance();
121     nav.SetProcessId(pid);
122     AISchedule &as = AISchedule::GetInstance();
123     as.SetProcessId(pid);
124 }
125 
SetProfilerLayer(const std::string & layer)126 void SpProfilerFactory::SetProfilerLayer(const std::string &layer)
127 {
128     FPS &fps = FPS::GetInstance();
129     fps.SetLayerName(layer);
130 }
131 
SetProfilerGameLayer(const std::string & isGameView)132 void SpProfilerFactory::SetProfilerGameLayer(const std::string &isGameView)
133 {
134     ProfilerFPS &profilerFps = ProfilerFPS::GetInstance();
135     profilerFps.SetGameLayer(isGameView);
136 }
137 
SetByTrace(std::string message)138 void SpProfilerFactory::SetByTrace(std::string message)
139 {
140     std::vector<std::string> values;
141     std::string delimiter = "||";
142     std::string delim = "=";
143     SPUtils::StrSplit(message, delimiter, values);
144     int mSum = 0;
145     int mInterval = 0;
146     long long mThreshold = 0;
147     int lowFps = 0;
148     for (std::string vItem : values) {
149         std::vector<std::string> vItems;
150         SPUtils::StrSplit(vItem, delim, vItems);
151         if (vItems[0] == "traceSum") {
152             mSum = SPUtilesTye::StringToSometype<int>(vItems[1]);
153         }
154         if (vItems[0] == "fpsJitterTime") {
155             mThreshold = SPUtilesTye::StringToSometype<int>(vItems[1]);
156         }
157         if (vItems[0] == "catchInterval") {
158             mInterval = SPUtilesTye::StringToSometype<int>(vItems[1]);
159         }
160         if (vItems[0] == "lowFps") {
161             lowFps = SPUtilesTye::StringToSometype<int>(vItems[1]);
162         }
163     }
164     const ByTrace &bTrace = ByTrace::GetInstance();
165     if (message.find("traceSum") != std::string::npos) {
166         int mCurNum = 1;
167         bTrace.SetTraceConfig(mSum, mInterval, mThreshold, lowFps, mCurNum);
168     }
169 }
GetCmdProfilerItem(CommandType commandType,bool cmdFlag)170 SpProfiler *SpProfilerFactory::GetCmdProfilerItem(CommandType commandType, bool cmdFlag)
171 {
172     SpProfiler *profiler = nullptr;
173     switch (commandType) {
174         case CommandType::CT_C:
175             if (cmdFlag) {
176                 profiler = &CPU::GetInstance();
177             }
178             break;
179         case CommandType::CT_G:
180             profiler = &GPU::GetInstance();
181             break;
182         case CommandType::CT_F:
183             if (cmdFlag) {
184                 profiler = &FPS::GetInstance();
185             }
186             break;
187         case CommandType::CT_D:
188             profiler = &DDR::GetInstance();
189             break;
190         case CommandType::CT_P:
191             profiler = &Power::GetInstance();
192             break;
193         case CommandType::CT_T:
194             profiler = &Temperature::GetInstance();
195             break;
196         case CommandType::CT_R:
197             if (cmdFlag) {
198                 profiler = &RAM::GetInstance();
199             }
200             break;
201         case CommandType::CT_NET:
202             profiler = &Network::GetInstance();
203             break;
204         case CommandType::CT_NAV:
205             profiler = &Navigation::GetInstance();
206             break;
207         case CommandType::CT_TTRACE:
208             ProfilerFPS::GetInstance().SetTraceCatch();
209             break;
210         case CommandType::CT_AS:
211             profiler = &AISchedule::GetInstance();
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