1 /* 2 * Copyright (c) 2023 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 HIVIEW_FRAMEWORK_NATIVE_UNIFIED_COLLECTION_UTILS_CPU_UTIL_H 16 #define HIVIEW_FRAMEWORK_NATIVE_UNIFIED_COLLECTION_UTILS_CPU_UTIL_H 17 18 #include <string> 19 #include <vector> 20 21 #include "collect_result.h" 22 #include "cpu.h" 23 24 namespace OHOS { 25 namespace HiviewDFX { 26 namespace UCollectUtil { 27 const std::string SYS_CPU_DIR_PREFIX = "/sys/devices/system/cpu/cpu"; 28 29 struct CpuTimeInfo { 30 std::string cpuId; 31 uint32_t userTime = 0; 32 uint32_t niceTime = 0; 33 uint32_t systemTime = 0; 34 uint32_t idleTime = 0; 35 uint32_t ioWaitTime = 0; 36 uint32_t irqTime = 0; 37 uint32_t softIrqTime = 0; 38 }; 39 40 class CpuUtil { 41 public: 42 static uint32_t GetNumOfCpuCores(); 43 static UCollect::UcError GetSysCpuLoad(SysCpuLoad& sysCpuLoad); 44 static UCollect::UcError GetCpuTimeInfos(std::vector<CpuTimeInfo>& cpuInfos); 45 static UCollect::UcError GetCpuFrequency(std::vector<CpuFreq>& cpuFreqs); 46 }; 47 } // namespace UCollectUtil 48 } // namespace HiviewDFX 49 } // namespace OHOS 50 #endif // HIVIEW_FRAMEWORK_NATIVE_UNIFIED_COLLECTION_UTILS_CPU_UTIL_H 51