1 /* 2 * Copyright (c) 2023-2024 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 struct CalculationTimeInfo { 41 // calculation time, using system clock. 42 uint64_t startTime = 0; 43 uint64_t endTime = 0; 44 45 // calculation time, using boot time. 46 uint64_t startBootTime = 0; 47 uint64_t endBootTime = 0; 48 49 // calculation period, using boot time. 50 uint64_t period = 0; 51 }; 52 53 class CpuUtil { 54 public: 55 static uint32_t GetNumOfCpuCores(); 56 static UCollect::UcError GetSysCpuLoad(SysCpuLoad& sysCpuLoad); 57 static UCollect::UcError GetCpuTimeInfos(std::vector<CpuTimeInfo>& cpuInfos); 58 static UCollect::UcError GetCpuFrequency(std::vector<CpuFreq>& cpuFreqs); 59 }; 60 } // namespace UCollectUtil 61 } // namespace HiviewDFX 62 } // namespace OHOS 63 #endif // HIVIEW_FRAMEWORK_NATIVE_UNIFIED_COLLECTION_UTILS_CPU_UTIL_H 64