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 #ifndef CPU_H 16 #define CPU_H 17 #include <iostream> 18 #include <vector> 19 #include "sp_profiler.h" 20 namespace OHOS { 21 namespace SmartPerf { 22 struct CpuFreqs { 23 uint32_t cpuId = 0; 24 uint32_t curFreq = 0; 25 }; 26 struct CpuUsageInfos { 27 std::string cpuId; 28 double userUsage = 0; 29 double niceUsage = 0; 30 double systemUsage = 0; 31 double idleUsage = 0; 32 double ioWaitUsage = 0; 33 double irqUsage = 0; 34 double softIrqUsage = 0; 35 }; 36 37 class CPU : public SpProfiler { 38 public: GetInstance()39 static CPU &GetInstance() 40 { 41 static CPU instance; 42 return instance; 43 } 44 std::map<std::string, std::string> ItemData() override; 45 std::vector<CpuFreqs> GetCpuFreq(); 46 std::vector<CpuUsageInfos> GetCpuUsage(); 47 std::map<std::string, std::string> GetSysProcessCpuLoad() const; 48 void SetPackageName(std::string pName); 49 private: CPU()50 CPU() {}; 51 CPU(const CPU &); 52 CPU &operator = (const CPU &); 53 std::string packageName = ""; 54 }; 55 } 56 } 57 #endif