• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, std::vector<std::string> paramsInfo,
48         const std::string pid, size_t index) const;
49     std::map<std::string, std::string> ParsePssValues(FILE *fd, std::vector<std::string> &paramsInfo,
50         const std::string pid, size_t index) const;
51     void FillPssRamInfo(size_t index, std::string pid, const PssValues &pssValues,
52         std::map<std::string, std::string> &pssRamInfo) const;
53     std::map<std::string, std::string> SaveSumRamInfo(std::vector<std::string> paramsInfo,
54         const std::string pid, size_t index) const;
55     std::map<std::string, std::string> ProcMemNaInfo() const;
56     std::map<std::string, std::string> ChildProcMemNaInfo() const;
57     void SetRamValue(std::promise<std::map<std::string, std::string>> p, std::string ramPid, size_t index) const;
58     std::map<std::string, std::string> CollectRam(std::string ramPid, size_t index) const;
59     std::future<std::map<std::string, std::string>> AsyncCollectRam(std::string ramPid, size_t index) const;
60     void CheckFutureRam(std::future<std::map<std::string, std::string>> &fdsResult,
61         std::map<std::string, std::string> &dataMap, std::string pid, size_t index) const;
GetInstance()62     static RAM &GetInstance()
63     {
64         static RAM instance;
65         return instance;
66     }
67     std::map<std::string, std::string> ItemData() override;
68     void SetPackageName(const std::string &pName);
69     void ThreadGetPss() const;
70     void TriggerGetPss() const;
71     void SetFirstFlag();
72     void SetHapFirstFlag();
73     void SetProcessId(const std::string &pid);
74 private:
RAM()75     RAM() {};
76     RAM(const RAM &);
77     RAM &operator = (const RAM &);
78     std::string packageName = "";
79     std::vector<std::string> processId;
80 };
81 }
82 }
83 #endif
84