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/RAM.h" 21 #include "include/Power.h" 22 #include "include/Temperature.h" 23 #include "include/ByTrace.h" 24 #include "include/sp_utils.h" 25 #include "include/sp_profiler_factory.h" 26 #include "include/Dubai.h" 27 namespace OHOS { 28 namespace SmartPerf { GetProfilerItem(MessageType messageType)29SpProfiler *SpProfilerFactory::GetProfilerItem(MessageType messageType) 30 { 31 SpProfiler *profiler = nullptr; 32 switch (messageType) { 33 case MessageType::GET_CPU_NUM: 34 case MessageType::GET_CPU_FREQ: 35 case MessageType::GET_CPU_LOAD: 36 profiler = &CPU::GetInstance(); 37 break; 38 case MessageType::GET_FPS_AND_JITTERS: 39 profiler = &FPS::GetInstance(); 40 break; 41 case MessageType::GET_GPU_FREQ: 42 case MessageType::GET_GPU_LOAD: 43 profiler = &GPU::GetInstance(); 44 break; 45 case MessageType::GET_DDR_FREQ: 46 profiler = &DDR::GetInstance(); 47 break; 48 case MessageType::GET_RAM_INFO: 49 profiler = &RAM::GetInstance(); 50 break; 51 case MessageType::GET_TEMPERATURE: 52 profiler = &Temperature::GetInstance(); 53 break; 54 case MessageType::GET_POWER: 55 profiler = &Power::GetInstance(); 56 break; 57 case MessageType::CATCH_TRACE_START: 58 ByTrace::GetInstance().ThreadGetTrace(); 59 break; 60 case MessageType::CATCH_TRACE_FINISH: { 61 ByTrace::GetInstance().ThreadEndTrace(); 62 std::string curTime = std::to_string(SPUtils::GetCurTime()); 63 ByTrace::GetInstance().ThreadFinishTrace(curTime); 64 break; 65 } 66 case MessageType::GET_CAPTURE: 67 FPS::GetInstance().SetCaptureOn(); 68 break; 69 case MessageType::SET_DUBAI_DB: { 70 Dubai::DumpDubaiBegin(); 71 Dubai::DumpDubaiFinish(); 72 Dubai::MoveDubaiDb(); 73 break; 74 } 75 default: 76 break; 77 } 78 return profiler; 79 } SetProfilerPkg(std::string pkg)80void SpProfilerFactory::SetProfilerPkg(std::string pkg) 81 { 82 FPS &fps = FPS::GetInstance(); 83 fps.SetPackageName(pkg); 84 } SetProfilerPid(std::string pid)85void SpProfilerFactory::SetProfilerPid(std::string pid) 86 { 87 RAM &ram = RAM::GetInstance(); 88 ram.SetProcessId(pid); 89 } GetCmdProfilerItem(CommandType commandType)90SpProfiler *SpProfilerFactory::GetCmdProfilerItem(CommandType commandType) 91 { 92 SpProfiler *profiler = nullptr; 93 switch (commandType) { 94 case CommandType::CT_C: 95 profiler = &CPU::GetInstance(); 96 break; 97 case CommandType::CT_G: 98 profiler = &GPU::GetInstance(); 99 break; 100 case CommandType::CT_F: 101 case CommandType::CT_F1: 102 case CommandType::CT_F2: 103 profiler = &FPS::GetInstance(); 104 break; 105 case CommandType::CT_D: 106 profiler = &DDR::GetInstance(); 107 break; 108 case CommandType::CT_P: 109 profiler = &Power::GetInstance(); 110 break; 111 case CommandType::CT_T: 112 profiler = &Temperature::GetInstance(); 113 break; 114 case CommandType::CT_R: 115 profiler = &RAM::GetInstance(); 116 break; 117 case CommandType::CT_TTRACE: 118 FPS::GetInstance().SetTraceCatch(); 119 break; 120 case CommandType::CT_SNAPSHOT: 121 FPS::GetInstance().SetCaptureOn(); 122 break; 123 case CommandType::CT_HW: 124 break; 125 default: 126 break; 127 } 128 return profiler; 129 } 130 } 131 } 132