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/get_kernel_info.h" 17 #include <memory> 18 #include "executor/memory/memory_filter.h" 19 #include "executor/memory/memory_util.h" 20 #include "executor/memory/parse/parse_vmallocinfo.h" 21 using namespace std; 22 namespace OHOS { 23 namespace HiviewDFX { GetKernelInfo()24GetKernelInfo::GetKernelInfo() 25 { 26 } ~GetKernelInfo()27GetKernelInfo::~GetKernelInfo() 28 { 29 } 30 31 /** 32 * @description: Get the usage of kernel 33 * @param {ValueMap} &infos-the meminfo 34 * @param {uint64_t} &value-the usage of kernel 35 * @return {bool} - true:success,false-fail 36 */ GetKernel(const ValueMap & infos,uint64_t & totalValue)37bool GetKernelInfo::GetKernel(const ValueMap &infos, uint64_t &totalValue) 38 { 39 for (const auto &str : MemoryFilter::GetInstance().CALC_KERNEL_TOTAL_) { 40 auto it = infos.find(str); 41 if (it != infos.end()) { 42 totalValue += it->second; 43 } 44 } 45 46 uint64_t vmallocValue = 0; 47 unique_ptr<ParseVmallocinfo> parseVmallocinfo = make_unique<ParseVmallocinfo>(); 48 bool success = parseVmallocinfo->GetVmallocinfo(vmallocValue); 49 if (success) { 50 totalValue += vmallocValue / MemoryUtil::GetInstance().BYTE_TO_KB_; 51 } 52 53 return success; 54 } 55 } // namespace HiviewDFX 56 } // namespace OHOS 57