1 /* 2 * Copyright (C) 2021-2022 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 MEMORY_UTIL_H 16 #define MEMORY_UTIL_H 17 #include <map> 18 #include <string> 19 #include <vector> 20 #include <memory> 21 #include "singleton.h" 22 #include "executor/memory/parse/meminfo_data.h" 23 namespace OHOS { 24 namespace HiviewDFX { 25 class MemoryUtil : public Singleton<MemoryUtil> { 26 public: 27 MemoryUtil(); 28 ~MemoryUtil(); 29 30 MemoryUtil(MemoryUtil const &) = delete; 31 void operator=(MemoryUtil const &) = delete; 32 33 using ValueMap = std::map<std::string, uint64_t>; 34 using GroupMap = std::map<std::string, ValueMap>; 35 36 std::string KB_UNIT_ = " kB"; 37 uint64_t BYTE_TO_KB_ = 1024; 38 39 void CalcGroup(const std::string &group, const std::string &type, const uint64_t &value, GroupMap &infos); 40 bool RunCMD(const std::string &cmd, std::vector<std::string> &result); 41 size_t GetMaxThreadNum(const size_t &threadNum); 42 bool IsNameLine(const std::string &str, std::string &name, uint64_t &iNode); 43 bool GetTypeValue(const std::string &str, const std::vector<std::string> &tag, std::string &type, uint64_t &value); 44 void InitMemInfo(MemInfoData::MemInfo &memInfo); 45 void InitMemUsage(MemInfoData::MemUsage &usage); 46 void InitGraphicsMemory(MemInfoData::GraphicsMemory &graphicsMemory); 47 bool GetTypeAndValue(const std::string &str, std::string &type, uint64_t &value); 48 49 private: 50 }; 51 } // namespace HiviewDFX 52 } // namespace OHOS 53 #endif 54