1 /* 2 * Copyright (c) 2023-2025 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 OHOS_HIVIEWDFX_UCOLLECTUTIL_COMMON_UTIL_H 16 #define OHOS_HIVIEWDFX_UCOLLECTUTIL_COMMON_UTIL_H 17 18 #include <cinttypes> 19 #include <sstream> 20 #include <string> 21 22 namespace OHOS { 23 namespace HiviewDFX { 24 namespace UCollectUtil { 25 constexpr const char* const PROC = "/proc/"; 26 constexpr const char* const IO = "/io"; 27 constexpr const char* const SMAPS_ROLLUP = "/smaps_rollup"; 28 constexpr const char* const STATM = "/statm"; 29 constexpr const char* const MEM_INFO = "/proc/meminfo"; 30 constexpr const char* const GPU_CUR_FREQ = "/sys/class/devfreq/gpufreq/cur_freq"; 31 constexpr const char* const GPU_MAX_FREQ = "/sys/class/devfreq/gpufreq/max_freq"; 32 constexpr const char* const GPU_MIN_FREQ = "/sys/class/devfreq/gpufreq/min_freq"; 33 constexpr const char* const GPU_LOAD = "/sys/class/devfreq/gpufreq/gpu_scene_aware/utilisation"; 34 constexpr const char* const MEMINFO_SAVE_DIR = "/data/log/hiview/unified_collection/memory"; 35 const static int VSS_BIT = 4; 36 37 class CommonUtil { 38 private: 39 CommonUtil() = default; 40 ~CommonUtil() = default; 41 42 public: 43 static bool ParseTypeAndValue(const std::string &str, std::string &type, int64_t &value); 44 static void GetDirRegexFiles(const std::string& path, const std::string& pattern, std::vector<std::string>& files); 45 static int GetFileNameNum(const std::string& fileName, const std::string& ext); 46 static std::string CreateExportFile(const std::string& path, int32_t maxFileNum, const std::string& prefix, 47 const std::string& ext); 48 static int32_t ReadNodeWithOnlyNumber(const std::string& fileName); StrToNum(const std::string & sString,T & tX)49 template <typename T> static bool StrToNum(const std::string& sString, T &tX) 50 { 51 std::istringstream iStream(sString); 52 return (iStream >> tX) ? true : false; 53 } 54 }; // CommonUtil 55 } // UCollectUtil 56 } // HiviewDFX 57 } // OHOS 58 #endif // OHOS_HIVIEWDFX_UCOLLECTUTIL_COMMON_UTIL_H 59