• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #include "executor/memory/parse/parse_meminfo.h"
17 #include <fstream>
18 #include "executor/memory/memory_filter.h"
19 #include "executor/memory/memory_util.h"
20 #include "hilog_wrapper.h"
21 #include "util/string_utils.h"
22 #include "util/file_utils.h"
23 
24 using namespace std;
25 namespace OHOS {
26 namespace HiviewDFX {
ParseMeminfo()27 ParseMeminfo::ParseMeminfo()
28 {
29 }
30 
~ParseMeminfo()31 ParseMeminfo::~ParseMeminfo()
32 {
33 }
34 
35 /**
36  * @description: SetData
37  * @param {string} &str-String to be inserted into result
38  * @param {ValueMap} &result-Returned results
39  * @return void
40  */
SetData(const string & str,ValueMap & result)41 void ParseMeminfo::SetData(const string &str, ValueMap &result)
42 {
43     string type = "";
44     uint64_t value = 0;
45     if (MemoryUtil::GetInstance().GetTypeValue(str, MemoryFilter::GetInstance().MEMINFO_TAG_, type, value)) {
46         result.insert(pair<string, uint64_t>(type, value));
47     }
48 }
49 
50 /**
51  * @description: Get the data from meminfo
52  * @param {ValueMap} &meminfo - the meminfo result
53  * @return bool-true:success,false-fail
54  */
GetMeminfo(ValueMap & result)55 bool ParseMeminfo::GetMeminfo(ValueMap &result)
56 {
57     string path = "/proc/meminfo";
58     bool ret = FileUtils::GetInstance().LoadStringFromProcCb(path, false, true, [&](const string& line) -> void {
59         SetData(line, result);
60     });
61     return ret;
62 }
63 } // namespace HiviewDFX
64 } // namespace OHOS
65