• 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/memory_filter.h"
17 #include "util/string_utils.h"
18 
19 using namespace std;
20 namespace OHOS {
21 namespace HiviewDFX {
MemoryFilter()22 MemoryFilter::MemoryFilter()
23 {
24 }
~MemoryFilter()25 MemoryFilter::~MemoryFilter()
26 {
27 }
28 
ParseMemoryGroup(const string & name,string & group,uint64_t iNode)29 void MemoryFilter::ParseMemoryGroup(const string &name, string &group, uint64_t iNode)
30 {
31     group = iNode > 0 ? FILE_PAGE_TAG : ANON_PAGE_TAG;
32     group += "#";
33     if (GetGroupFromMap(name, group, endMap_, bind(
34                         &StringUtils::IsEnd, &StringUtils::GetInstance(), placeholders::_1, placeholders::_2)) ||
35         GetGroupFromMap(name, group, beginMap_, bind(
36             &StringUtils::IsBegin, &StringUtils::GetInstance(), placeholders::_1, placeholders::_2))) {
37         return;
38     }
39     group += "other";
40 }
41 
GetGroupFromMap(const string & name,string & group,const std::map<std::string,std::string> & map,MatchFunc func)42 bool MemoryFilter::GetGroupFromMap(const string &name, string &group,
43                                    const std::map<std::string, std::string> &map, MatchFunc func)
44 {
45     for (const auto &p : map) {
46         if (func(name, p.first)) {
47             group += p.second;
48             return true;
49         }
50     }
51     return false;
52 }
53 } // namespace HiviewDFX
54 } // namespace OHOS
55