1 /* 2 * Copyright (C) 2021 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 RAM_H 16 #define RAM_H 17 #include "sp_profiler.h" 18 #include <future> 19 #include <string> 20 21 enum { 22 RAM_ONE = 1, 23 RAM_SECOND, 24 RAM_THIRD, 25 RAM_FOURTH, 26 RAM_FIFTH, 27 RAM_SIXTH, 28 RAM_SEVENTH, 29 RAM_EIGHTH, 30 RAM_NINTH, 31 RAM_TENTH, 32 }; 33 34 struct PssValues { 35 std::string gpuPssValue = ""; 36 std::string graphicPssValue = ""; 37 std::string arktsHeapPssValue = ""; 38 std::string nativeHeapPssValue = ""; 39 std::string stackPssValue = ""; 40 }; 41 namespace OHOS { 42 namespace SmartPerf { 43 class RAM : public SpProfiler { 44 public: 45 std::map<std::string, std::string> GetSysRamInfo() const; 46 std::map<std::string, std::string> GetRamInfo() const; 47 std::map<std::string, std::string> GetPssRamInfo(FILE *fd, const std::string& pid, size_t index) const; 48 std::map<std::string, std::string> ParsePssValues(FILE *fd, std::vector<std::string> ¶msInfo, 49 const std::string pid, size_t index) const; 50 void FillPssRamInfo(size_t index, std::string pid, const PssValues &pssValues, 51 std::map<std::string, std::string> &pssRamInfo) const; 52 std::map<std::string, std::string> SaveSumRamInfo(std::vector<std::string>& paramsInfo, 53 const std::string& pid, size_t index) const; 54 std::map<std::string, std::string> ProcMemNaInfo() const; 55 std::map<std::string, std::string> ChildProcMemNaInfo() const; 56 void SetRamValue(std::promise<std::map<std::string, std::string>> p, std::string ramPid, size_t index) const; 57 std::map<std::string, std::string> CollectRam(const std::string& ramPid, size_t index) const; 58 std::future<std::map<std::string, std::string>> AsyncCollectRam(const std::string& ramPid, size_t index) const; 59 void CheckFutureRam(std::future<std::map<std::string, std::string>> &fdsResult, 60 std::map<std::string, std::string> &dataMap, const std::string& pid, size_t index) const; GetInstance()61 static RAM &GetInstance() 62 { 63 static RAM instance; 64 return instance; 65 } 66 std::map<std::string, std::string> ItemData() override; 67 void SetPackageName(const std::string &pName); 68 void ThreadGetPss() const; 69 void TriggerGetPss() const; 70 void SetFirstFlag(); 71 void SetHapFirstFlag(); 72 void SetProcessId(const std::string &pid); 73 private: RAM()74 RAM() {}; 75 RAM(const RAM &); 76 RAM &operator = (const RAM &); 77 std::string packageName = ""; 78 std::vector<std::string> processId; 79 std::map<std::string, std::string> result = {}; 80 }; 81 } 82 } 83 #endif 84