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