106f6ba60Sopenharmony_ci/*
206f6ba60Sopenharmony_ci * Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
306f6ba60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
406f6ba60Sopenharmony_ci * you may not use this file except in compliance with the License.
506f6ba60Sopenharmony_ci * You may obtain a copy of the License at
606f6ba60Sopenharmony_ci *
706f6ba60Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
806f6ba60Sopenharmony_ci *
906f6ba60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1006f6ba60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1106f6ba60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1206f6ba60Sopenharmony_ci * See the License for the specific language governing permissions and
1306f6ba60Sopenharmony_ci * limitations under the License.
1406f6ba60Sopenharmony_ci */
1506f6ba60Sopenharmony_ci#include "smaps_stats.h"
1606f6ba60Sopenharmony_ci
1706f6ba60Sopenharmony_ci#include "securec.h"
1806f6ba60Sopenharmony_ci
1906f6ba60Sopenharmony_cinamespace {
2006f6ba60Sopenharmony_cibool MatchHead(const std::string& name, const char* str)
2106f6ba60Sopenharmony_ci{
2206f6ba60Sopenharmony_ci    return strncmp(name.c_str(), str, strlen(str)) == 0;
2306f6ba60Sopenharmony_ci}
2406f6ba60Sopenharmony_ci
2506f6ba60Sopenharmony_cibool MatchTail(const std::string& name, const char* str)
2606f6ba60Sopenharmony_ci{
2706f6ba60Sopenharmony_ci    int index = name.size() - strlen(str);
2806f6ba60Sopenharmony_ci    if (index < 0) {
2906f6ba60Sopenharmony_ci        return false;
3006f6ba60Sopenharmony_ci    }
3106f6ba60Sopenharmony_ci    return (name.substr(index) == str);
3206f6ba60Sopenharmony_ci}
3306f6ba60Sopenharmony_ci} // namespace
3406f6ba60Sopenharmony_cistd::string SmapsStats::ParseCategory(const SmapsHeadInfo& smapsHeadInfo)
3506f6ba60Sopenharmony_ci{
3606f6ba60Sopenharmony_ci    std::string category;
3706f6ba60Sopenharmony_ci    if (GetCategoryFromMap(smapsHeadInfo.path, category, endMap_, &MatchTail) ||
3806f6ba60Sopenharmony_ci        GetCategoryFromMap(smapsHeadInfo.path, category, beginMap_, &MatchHead)) {
3906f6ba60Sopenharmony_ci        return category;
4006f6ba60Sopenharmony_ci    }
4106f6ba60Sopenharmony_ci    category = smapsHeadInfo.iNode > 0 ? FILE_PAGE_TAG : ANON_PAGE_TAG;
4206f6ba60Sopenharmony_ci    return category;
4306f6ba60Sopenharmony_ci}
4406f6ba60Sopenharmony_ci
4506f6ba60Sopenharmony_cibool SmapsStats::GetCategoryFromMap(const std::string &name, std::string &category,
4606f6ba60Sopenharmony_ci                                    const std::map<std::string, std::string> &map, MatchFunc func)
4706f6ba60Sopenharmony_ci{
4806f6ba60Sopenharmony_ci    for (const auto &p : map) {
4906f6ba60Sopenharmony_ci        if (func(name, p.first.c_str())) {
5006f6ba60Sopenharmony_ci            category = p.second;
5106f6ba60Sopenharmony_ci            return true;
5206f6ba60Sopenharmony_ci        }
5306f6ba60Sopenharmony_ci    }
5406f6ba60Sopenharmony_ci    return false;
5506f6ba60Sopenharmony_ci}
5606f6ba60Sopenharmony_ci
5706f6ba60Sopenharmony_cibool SmapsStats::GetVMAStuId(int ops,
5806f6ba60Sopenharmony_ci                             std::string name,
5906f6ba60Sopenharmony_ci                             const VmeminfoAreaMapping vma[],
6006f6ba60Sopenharmony_ci                             int count,
6106f6ba60Sopenharmony_ci                             int32_t heapIndex[2],
6206f6ba60Sopenharmony_ci                             bool& swappable)
6306f6ba60Sopenharmony_ci{
6406f6ba60Sopenharmony_ci    for (int i = 0; i < count; i++) {
6506f6ba60Sopenharmony_ci        if (ops == OPS_START) {
6606f6ba60Sopenharmony_ci            if (MatchHead(name, vma[i].heapstr)) {
6706f6ba60Sopenharmony_ci                heapIndex[0] = vma[i].heapid[0];
6806f6ba60Sopenharmony_ci                heapIndex[1] = vma[i].heapid[1];
6906f6ba60Sopenharmony_ci                swappable = false;
7006f6ba60Sopenharmony_ci                return true;
7106f6ba60Sopenharmony_ci            }
7206f6ba60Sopenharmony_ci        } else if (ops == OPS_END) {
7306f6ba60Sopenharmony_ci            if (MatchTail(name, vma[i].heapstr)) {
7406f6ba60Sopenharmony_ci                if (vma[i].heapid[1] == VMHEAP_NEEDFIX) {
7506f6ba60Sopenharmony_ci                    HeapIndexFix(name, vma[i].heapstr, heapIndex);
7606f6ba60Sopenharmony_ci                } else {
7706f6ba60Sopenharmony_ci                    heapIndex[0] = vma[i].heapid[0];
7806f6ba60Sopenharmony_ci                    heapIndex[1] = vma[i].heapid[1];
7906f6ba60Sopenharmony_ci                }
8006f6ba60Sopenharmony_ci                swappable = true;
8106f6ba60Sopenharmony_ci                return true;
8206f6ba60Sopenharmony_ci            }
8306f6ba60Sopenharmony_ci        }
8406f6ba60Sopenharmony_ci    }
8506f6ba60Sopenharmony_ci    return false;
8606f6ba60Sopenharmony_ci}
8706f6ba60Sopenharmony_ci
8806f6ba60Sopenharmony_cibool SmapsStats::GetVmaIndex(std::string name, uint32_t namesz, int32_t heapIndex[2], bool& swappable)
8906f6ba60Sopenharmony_ci{
9006f6ba60Sopenharmony_ci    switch (name[0]) {
9106f6ba60Sopenharmony_ci        case '[':
9206f6ba60Sopenharmony_ci            if (MatchHead(name, "[heap]") || MatchHead(name, "[stack")) {
9306f6ba60Sopenharmony_ci                return GetVMAStuId(OPS_START, name, g_vmaMemHeap, sizeof(g_vmaMemHeap) /
9406f6ba60Sopenharmony_ci                                    sizeof(g_vmaMemHeap[0]), heapIndex, swappable);
9506f6ba60Sopenharmony_ci            } else if (MatchHead(name, "[anon:")) {
9606f6ba60Sopenharmony_ci                if (MatchHead(name, "[anon:sensitive_vm-") &&
9706f6ba60Sopenharmony_ci                    GetVMAStuId(OPS_END, name, g_vmaMemSuffix, sizeof(g_vmaMemSuffix) /
9806f6ba60Sopenharmony_ci                    sizeof(g_vmaMemSuffix[0]), heapIndex, swappable)) {
9906f6ba60Sopenharmony_ci                        return true;
10006f6ba60Sopenharmony_ci                }
10106f6ba60Sopenharmony_ci                return GetVMAStuId(OPS_START, name, g_vmaMemAnon, sizeof(g_vmaMemAnon) /
10206f6ba60Sopenharmony_ci                                    sizeof(g_vmaMemAnon[0]), heapIndex, swappable);
10306f6ba60Sopenharmony_ci            }
10406f6ba60Sopenharmony_ci            break;
10506f6ba60Sopenharmony_ci        case '/':
10606f6ba60Sopenharmony_ci            if (MatchHead(name, "/memfd:")) {
10706f6ba60Sopenharmony_ci                return GetVMAStuId(OPS_START, name, g_vmaMemFd, sizeof(g_vmaMemFd) /
10806f6ba60Sopenharmony_ci                                    sizeof(g_vmaMemFd[0]), heapIndex, swappable);
10906f6ba60Sopenharmony_ci            } else if (MatchHead(name, "/dev/")) {
11006f6ba60Sopenharmony_ci                return GetVMAStuId(OPS_START, name, g_vmaMemDev, sizeof(g_vmaMemDev) /
11106f6ba60Sopenharmony_ci                                    sizeof(g_vmaMemDev[0]), heapIndex, swappable);
11206f6ba60Sopenharmony_ci            } else {
11306f6ba60Sopenharmony_ci                return GetVMAStuId(OPS_END, name, g_vmaMemSuffix, sizeof(g_vmaMemSuffix) /
11406f6ba60Sopenharmony_ci                                    sizeof(g_vmaMemSuffix[0]), heapIndex, swappable);
11506f6ba60Sopenharmony_ci            }
11606f6ba60Sopenharmony_ci            break;
11706f6ba60Sopenharmony_ci        default:
11806f6ba60Sopenharmony_ci            return GetVMAStuId(OPS_END, name, g_vmaMemSuffix, sizeof(g_vmaMemSuffix) /
11906f6ba60Sopenharmony_ci                                sizeof(g_vmaMemSuffix[0]), heapIndex, swappable);
12006f6ba60Sopenharmony_ci            break;
12106f6ba60Sopenharmony_ci    }
12206f6ba60Sopenharmony_ci    if (namesz > strlen(".sensitive_jvbin") && strstr(name.c_str(), ".sensitive_jvbin") != nullptr) {
12306f6ba60Sopenharmony_ci        heapIndex[0] = VMHEAP_SENSITIVE_JVBIN;
12406f6ba60Sopenharmony_ci        heapIndex[1] = VMHEAP_SENSITIVE_JVBIN_APP_SENSITIVE_JVBIN;
12506f6ba60Sopenharmony_ci        swappable = true;
12606f6ba60Sopenharmony_ci        return true;
12706f6ba60Sopenharmony_ci    }
12806f6ba60Sopenharmony_ci    return false;
12906f6ba60Sopenharmony_ci}
13006f6ba60Sopenharmony_ci
13106f6ba60Sopenharmony_civoid SmapsStats::CollectVmemAreasData(const MapPiecesInfo& mempic,
13206f6ba60Sopenharmony_ci                                      const MemUsageInfo& memusage,
13306f6ba60Sopenharmony_ci                                      uint64_t& prevEnd,
13406f6ba60Sopenharmony_ci                                      int& prevHeap)
13506f6ba60Sopenharmony_ci{
13606f6ba60Sopenharmony_ci    std::string name;
13706f6ba60Sopenharmony_ci    int32_t heapIndex[2] = {VMHEAP_UNKNOWN, VMHEAP_NULL};
13806f6ba60Sopenharmony_ci    bool swappable = false;
13906f6ba60Sopenharmony_ci    uint64_t swapablePss = 0;
14006f6ba60Sopenharmony_ci
14106f6ba60Sopenharmony_ci    if (MatchTail(mempic.name, " (deleted)")) {
14206f6ba60Sopenharmony_ci        name = mempic.name.substr(0, mempic.name.size() - strlen(" (deleted)"));
14306f6ba60Sopenharmony_ci    } else {
14406f6ba60Sopenharmony_ci        name = mempic.name;
14506f6ba60Sopenharmony_ci    }
14606f6ba60Sopenharmony_ci    uint32_t namesz = name.size();
14706f6ba60Sopenharmony_ci    if (!GetVmaIndex(name, namesz, heapIndex, swappable)) {
14806f6ba60Sopenharmony_ci        if (namesz > 0) {
14906f6ba60Sopenharmony_ci            heapIndex[0] = VMHEAP_UNKNOWN_MAP;
15006f6ba60Sopenharmony_ci        } else if (mempic.startAddr == prevEnd && prevHeap == VMHEAP_SO) {
15106f6ba60Sopenharmony_ci            // bss section of a shared library
15206f6ba60Sopenharmony_ci            heapIndex[0] = VMHEAP_SO;
15306f6ba60Sopenharmony_ci        }
15406f6ba60Sopenharmony_ci    }
15506f6ba60Sopenharmony_ci    prevEnd = mempic.endAddr;
15606f6ba60Sopenharmony_ci    prevHeap = heapIndex[0];
15706f6ba60Sopenharmony_ci    swapablePss = GetSwapablepssValue(memusage, swappable);
15806f6ba60Sopenharmony_ci    SetVmemAreasData(heapIndex[0], swapablePss, memusage);
15906f6ba60Sopenharmony_ci    if ((heapIndex[1] != VMHEAP_NULL) && (heapIndex[1] != VMHEAP_NEEDFIX)) {
16006f6ba60Sopenharmony_ci        SetVmemAreasData(heapIndex[1], swapablePss, memusage);
16106f6ba60Sopenharmony_ci    }
16206f6ba60Sopenharmony_ci}
16306f6ba60Sopenharmony_ci
16406f6ba60Sopenharmony_civoid SmapsStats::ReviseStatsData()
16506f6ba60Sopenharmony_ci{
16606f6ba60Sopenharmony_ci    // Summary data to VMHEAP_UNKNOWN
16706f6ba60Sopenharmony_ci    for (int i = VMHEAP_NUM_CORE_HEAP; i < VMHEAP_NUM_EXCLUSIVE_HEAP; i++) {
16806f6ba60Sopenharmony_ci        stats_[VMHEAP_UNKNOWN] += stats_[i];
16906f6ba60Sopenharmony_ci    }
17006f6ba60Sopenharmony_ci}
17106f6ba60Sopenharmony_ci
17206f6ba60Sopenharmony_cibool SmapsStats::SetMapAddrInfo(std::string& line, MapPiecesInfo& head)
17306f6ba60Sopenharmony_ci{
17406f6ba60Sopenharmony_ci    const char* pStr = line.c_str();
17506f6ba60Sopenharmony_ci    char* end = nullptr;
17606f6ba60Sopenharmony_ci    head.startAddr = strtoull(pStr, &end, HEX_BASE);
17706f6ba60Sopenharmony_ci    CHECK_TRUE(!(end == pStr || *end != '-'), false, "SetMapAddrInfo fail");
17806f6ba60Sopenharmony_ci    pStr = end + 1;
17906f6ba60Sopenharmony_ci    head.endAddr = strtoull(pStr, &end, HEX_BASE);
18006f6ba60Sopenharmony_ci    CHECK_TRUE(end != pStr, false, "end == pStr");
18106f6ba60Sopenharmony_ci    return true;
18206f6ba60Sopenharmony_ci}
18306f6ba60Sopenharmony_ci
18406f6ba60Sopenharmony_cibool SmapsStats::ParseMapHead(std::string& line, MapPiecesInfo& head, SmapsHeadInfo& smapsHeadInfo)
18506f6ba60Sopenharmony_ci{
18606f6ba60Sopenharmony_ci    std::string newline = line;
18706f6ba60Sopenharmony_ci    for (int i = 0; i < FIFTH_FIELD; i++) {
18806f6ba60Sopenharmony_ci        std::string word = newline;
18906f6ba60Sopenharmony_ci        size_t wordsz = word.find(" ");
19006f6ba60Sopenharmony_ci        CHECK_TRUE(wordsz != std::string::npos, false, "wordsz == std::string::npos");
19106f6ba60Sopenharmony_ci        word = newline.substr(0, wordsz);
19206f6ba60Sopenharmony_ci        if (i == 0) {
19306f6ba60Sopenharmony_ci            size_t pos = word.find("-");
19406f6ba60Sopenharmony_ci            if (pos != std::string::npos) {
19506f6ba60Sopenharmony_ci                smapsHeadInfo.startAddrStr = word.substr(0, pos);
19606f6ba60Sopenharmony_ci                smapsHeadInfo.endAddrStr = word.substr(pos + 1, word.size());
19706f6ba60Sopenharmony_ci                head.startAddr = strtoull(smapsHeadInfo.startAddrStr.c_str(), nullptr, HEX_BASE);
19806f6ba60Sopenharmony_ci                head.endAddr = strtoull(smapsHeadInfo.endAddrStr.c_str(), nullptr, HEX_BASE);
19906f6ba60Sopenharmony_ci            }
20006f6ba60Sopenharmony_ci        } else if (i == 1) {
20106f6ba60Sopenharmony_ci            size_t dataLen = word.size() > 1 ? word.size() - 1 : 0;
20206f6ba60Sopenharmony_ci            smapsHeadInfo.permission = word.substr(0, dataLen);
20306f6ba60Sopenharmony_ci        } else if (i == 4) { // 4: iNode index
20406f6ba60Sopenharmony_ci            smapsHeadInfo.iNode = strtoll(word.substr(0, word.size()).c_str(), nullptr, DEC_BASE);
20506f6ba60Sopenharmony_ci        }
20606f6ba60Sopenharmony_ci        size_t newlineops = newline.find_first_not_of(" ", wordsz);
20706f6ba60Sopenharmony_ci        newline = newline.substr(newlineops);
20806f6ba60Sopenharmony_ci    }
20906f6ba60Sopenharmony_ci    head.name = newline.substr(0, newline.size() - 1);
21006f6ba60Sopenharmony_ci    smapsHeadInfo.path = head.name;
21106f6ba60Sopenharmony_ci    return true;
21206f6ba60Sopenharmony_ci}
21306f6ba60Sopenharmony_ci
21406f6ba60Sopenharmony_cibool SmapsStats::GetMemUsageField(std::string& line, MemUsageInfo& memusage)
21506f6ba60Sopenharmony_ci{
21606f6ba60Sopenharmony_ci    char field[64];
21706f6ba60Sopenharmony_ci    int len = 0;
21806f6ba60Sopenharmony_ci    const char* pLine = line.c_str();
21906f6ba60Sopenharmony_ci    int ret = sscanf_s(pLine, "%63s %n", field, sizeof(field), &len);
22006f6ba60Sopenharmony_ci    size_t dataIndex = strlen(field) > 1 ? strlen(field) - 1 : 0;
22106f6ba60Sopenharmony_ci    if (ret == 1 && *field && field[dataIndex] == ':') {
22206f6ba60Sopenharmony_ci        const char* c = pLine + len;
22306f6ba60Sopenharmony_ci        std::string strfield(field);
22406f6ba60Sopenharmony_ci        switch (field[0]) {
22506f6ba60Sopenharmony_ci            case 'P':
22606f6ba60Sopenharmony_ci                if (MatchHead(strfield, "Pss:")) {
22706f6ba60Sopenharmony_ci                    memusage.pss = strtoull(c, nullptr, DEC_BASE);
22806f6ba60Sopenharmony_ci                } else if (MatchHead(strfield, "Private_Clean:")) {
22906f6ba60Sopenharmony_ci                    uint64_t prcl = strtoull(c, nullptr, DEC_BASE);
23006f6ba60Sopenharmony_ci                    memusage.privateClean = prcl;
23106f6ba60Sopenharmony_ci                    memusage.uss += prcl;
23206f6ba60Sopenharmony_ci                } else if (MatchHead(strfield, "Private_Dirty:")) {
23306f6ba60Sopenharmony_ci                    uint64_t prdi = strtoull(c, nullptr, DEC_BASE);
23406f6ba60Sopenharmony_ci                    memusage.privateDirty = prdi;
23506f6ba60Sopenharmony_ci                    memusage.uss += prdi;
23606f6ba60Sopenharmony_ci                }
23706f6ba60Sopenharmony_ci                break;
23806f6ba60Sopenharmony_ci            case 'S':
23906f6ba60Sopenharmony_ci                if (MatchHead(strfield, "Size:")) {
24006f6ba60Sopenharmony_ci                    memusage.vss = strtoull(c, nullptr, DEC_BASE);
24106f6ba60Sopenharmony_ci                } else if (MatchHead(strfield, "Shared_Clean:")) {
24206f6ba60Sopenharmony_ci                    memusage.sharedClean = strtoull(c, nullptr, DEC_BASE);
24306f6ba60Sopenharmony_ci                } else if (MatchHead(strfield, "Shared_Dirty:")) {
24406f6ba60Sopenharmony_ci                    memusage.sharedDirty = strtoull(c, nullptr, DEC_BASE);
24506f6ba60Sopenharmony_ci                } else if (MatchHead(strfield, "Swap:")) {
24606f6ba60Sopenharmony_ci                    memusage.swap = strtoull(c, nullptr, DEC_BASE);
24706f6ba60Sopenharmony_ci                } else if (MatchHead(strfield, "SwapPss:")) {
24806f6ba60Sopenharmony_ci                    memusage.swapPss = strtoull(c, nullptr, DEC_BASE);
24906f6ba60Sopenharmony_ci                }
25006f6ba60Sopenharmony_ci                break;
25106f6ba60Sopenharmony_ci            case 'R':
25206f6ba60Sopenharmony_ci                if (MatchHead(strfield, "Rss:")) {
25306f6ba60Sopenharmony_ci                    memusage.rss = strtoull(c, nullptr, DEC_BASE);
25406f6ba60Sopenharmony_ci                }
25506f6ba60Sopenharmony_ci                break;
25606f6ba60Sopenharmony_ci            case 'V':
25706f6ba60Sopenharmony_ci                if (MatchHead(strfield, "VmFlags:")) {
25806f6ba60Sopenharmony_ci                    lastline_ = true;
25906f6ba60Sopenharmony_ci                }
26006f6ba60Sopenharmony_ci                break;
26106f6ba60Sopenharmony_ci            default:
26206f6ba60Sopenharmony_ci                break;
26306f6ba60Sopenharmony_ci        }
26406f6ba60Sopenharmony_ci        return true;
26506f6ba60Sopenharmony_ci    }
26606f6ba60Sopenharmony_ci
26706f6ba60Sopenharmony_ci    return false;
26806f6ba60Sopenharmony_ci}
26906f6ba60Sopenharmony_ci
27006f6ba60Sopenharmony_ciuint64_t SmapsStats::GetSwapablepssValue(const MemUsageInfo& memusage, bool swappable)
27106f6ba60Sopenharmony_ci{
27206f6ba60Sopenharmony_ci    if (!swappable || (memusage.pss == 0)) {
27306f6ba60Sopenharmony_ci        return 0;
27406f6ba60Sopenharmony_ci    }
27506f6ba60Sopenharmony_ci
27606f6ba60Sopenharmony_ci    if ((memusage.sharedClean == 0) && (memusage.sharedDirty == 0)) {
27706f6ba60Sopenharmony_ci        return memusage.privateClean;
27806f6ba60Sopenharmony_ci    }
27906f6ba60Sopenharmony_ci    int proportion = (memusage.pss - memusage.uss) / (memusage.sharedClean + memusage.sharedDirty);
28006f6ba60Sopenharmony_ci
28106f6ba60Sopenharmony_ci    return (proportion * memusage.sharedClean) + memusage.privateClean;
28206f6ba60Sopenharmony_ci}
28306f6ba60Sopenharmony_ci
28406f6ba60Sopenharmony_civoid SmapsStats::SetVmemAreasData(int index, uint64_t swapablePss, const MemUsageInfo& usage)
28506f6ba60Sopenharmony_ci{
28606f6ba60Sopenharmony_ci    StatsInfo oobj(swapablePss, usage);
28706f6ba60Sopenharmony_ci    stats_[index] += oobj;
28806f6ba60Sopenharmony_ci}
28906f6ba60Sopenharmony_ci
29006f6ba60Sopenharmony_civoid SmapsStats::HeapIndexFix(std::string name, const char* key, int32_t heapIndex[2])
29106f6ba60Sopenharmony_ci{
29206f6ba60Sopenharmony_ci    if (!strncmp(key, ".vdex", sizeof(".vdex"))) {
29306f6ba60Sopenharmony_ci        if ((strstr(name.c_str(), "@boot") != nullptr) || (strstr(name.c_str(), "/boot") != nullptr) ||
29406f6ba60Sopenharmony_ci            (strstr(name.c_str(), "/apex") != nullptr)) {
29506f6ba60Sopenharmony_ci            heapIndex[0] = VMHEAP_SENSITIVE_JVBIN;
29606f6ba60Sopenharmony_ci            heapIndex[1] = VMHEAP_SENSITIVE_JVBIN_BOOT_VDEX;
29706f6ba60Sopenharmony_ci        } else {
29806f6ba60Sopenharmony_ci            heapIndex[0] = VMHEAP_SENSITIVE_JVBIN;
29906f6ba60Sopenharmony_ci            heapIndex[1] = VMHEAP_SENSITIVE_JVBIN_APP_VDEX;
30006f6ba60Sopenharmony_ci        }
30106f6ba60Sopenharmony_ci    } else if (!strncmp(key, ".hrt", sizeof(".hrt")) || !strncmp(key, ".hrt]", sizeof(".hrt]"))) {
30206f6ba60Sopenharmony_ci        if ((strstr(name.c_str(), "@boot") != nullptr) || (strstr(name.c_str(), "/boot") != nullptr) ||
30306f6ba60Sopenharmony_ci            (strstr(name.c_str(), "/apex") != nullptr)) {
30406f6ba60Sopenharmony_ci            heapIndex[0] = VMHEAP_HRT;
30506f6ba60Sopenharmony_ci            heapIndex[1] = VMHEAP_HRT_BOOT;
30606f6ba60Sopenharmony_ci        } else {
30706f6ba60Sopenharmony_ci            heapIndex[0] = VMHEAP_HRT;
30806f6ba60Sopenharmony_ci            heapIndex[1] = VMHEAP_HRT_APP;
30906f6ba60Sopenharmony_ci        }
31006f6ba60Sopenharmony_ci    }
31106f6ba60Sopenharmony_ci}
31206f6ba60Sopenharmony_ci
31306f6ba60Sopenharmony_ciint SmapsStats::GetProcessJavaHeap()
31406f6ba60Sopenharmony_ci{
31506f6ba60Sopenharmony_ci    return stats_[VMHEAP_SENSITIVE_VM].privateDirty_ + GetPrivate(VMHEAP_HRT);
31606f6ba60Sopenharmony_ci}
31706f6ba60Sopenharmony_ci
31806f6ba60Sopenharmony_ciint SmapsStats::GetProcessNativeHeap()
31906f6ba60Sopenharmony_ci{
32006f6ba60Sopenharmony_ci    return stats_[VMHEAP_NATIVE].privateDirty_;
32106f6ba60Sopenharmony_ci}
32206f6ba60Sopenharmony_ci
32306f6ba60Sopenharmony_ciint SmapsStats::GetProcessCode()
32406f6ba60Sopenharmony_ci{
32506f6ba60Sopenharmony_ci    return GetPrivate(VMHEAP_SO) + GetPrivate(VMHEAP_JAR) + GetPrivate(VMHEAP_TTF) +
32606f6ba60Sopenharmony_ci           GetPrivate(VMHEAP_SENSITIVE_JVBIN) + GetPrivate(VMHEAP_OAT) +
32706f6ba60Sopenharmony_ci           GetPrivate(VMHEAP_SENSITIVE_VM_OTHER_ZYGOTE_CODE_CACHE) +
32806f6ba60Sopenharmony_ci           GetPrivate(VMHEAP_SENSITIVE_VM_OTHER_APP_CODE_CACHE);
32906f6ba60Sopenharmony_ci}
33006f6ba60Sopenharmony_ci
33106f6ba60Sopenharmony_ciint SmapsStats::GetProcessStack()
33206f6ba60Sopenharmony_ci{
33306f6ba60Sopenharmony_ci    return stats_[VMHEAP_STACK].privateDirty_;
33406f6ba60Sopenharmony_ci}
33506f6ba60Sopenharmony_ci
33606f6ba60Sopenharmony_ciint SmapsStats::GetProcessGraphics()
33706f6ba60Sopenharmony_ci{
33806f6ba60Sopenharmony_ci    return GetPrivate(VMHEAP_GL_DEV) + GetPrivate(VMHEAP_GRAPHICS) + GetPrivate(VMHEAP_GL);
33906f6ba60Sopenharmony_ci}
34006f6ba60Sopenharmony_ci
34106f6ba60Sopenharmony_ciint SmapsStats::GetProcessPrivateOther()
34206f6ba60Sopenharmony_ci{
34306f6ba60Sopenharmony_ci    return GetTotalPrivateClean() + GetTotalPrivateDirty() - GetProcessJavaHeap() - GetProcessNativeHeap() -
34406f6ba60Sopenharmony_ci           GetProcessCode() - GetProcessStack() - GetProcessGraphics();
34506f6ba60Sopenharmony_ci}
34606f6ba60Sopenharmony_ci
34706f6ba60Sopenharmony_ciint SmapsStats::GetProcessSystem()
34806f6ba60Sopenharmony_ci{
34906f6ba60Sopenharmony_ci    return GetTotalPss() - GetTotalPrivateClean() - GetTotalPrivateDirty();
35006f6ba60Sopenharmony_ci}
35106f6ba60Sopenharmony_ci
35206f6ba60Sopenharmony_ciint SmapsStats::GetTotalPrivateClean()
35306f6ba60Sopenharmony_ci{
35406f6ba60Sopenharmony_ci    return stats_[VMHEAP_UNKNOWN].privateClean_ + stats_[VMHEAP_NATIVE].privateClean_ +
35506f6ba60Sopenharmony_ci           stats_[VMHEAP_SENSITIVE_VM].privateClean_;
35606f6ba60Sopenharmony_ci}
35706f6ba60Sopenharmony_ci
35806f6ba60Sopenharmony_ciint SmapsStats::GetTotalPrivateDirty()
35906f6ba60Sopenharmony_ci{
36006f6ba60Sopenharmony_ci    return stats_[VMHEAP_UNKNOWN].privateDirty_ + stats_[VMHEAP_NATIVE].privateDirty_ +
36106f6ba60Sopenharmony_ci           stats_[VMHEAP_SENSITIVE_VM].privateDirty_;
36206f6ba60Sopenharmony_ci}
36306f6ba60Sopenharmony_ci
36406f6ba60Sopenharmony_ciint SmapsStats::GetPrivate(int type)
36506f6ba60Sopenharmony_ci{
36606f6ba60Sopenharmony_ci    return stats_[type].privateDirty_ + stats_[type].privateClean_;
36706f6ba60Sopenharmony_ci}
36806f6ba60Sopenharmony_ci
36906f6ba60Sopenharmony_ciint SmapsStats::GetTotalPss()
37006f6ba60Sopenharmony_ci{
37106f6ba60Sopenharmony_ci    return stats_[VMHEAP_UNKNOWN].pss_ + stats_[VMHEAP_NATIVE].pss_ + stats_[VMHEAP_SENSITIVE_VM].pss_
37206f6ba60Sopenharmony_ci            + GetTotalSwappedOutPss();
37306f6ba60Sopenharmony_ci}
37406f6ba60Sopenharmony_ci
37506f6ba60Sopenharmony_ciint SmapsStats::GetTotalSwappedOutPss()
37606f6ba60Sopenharmony_ci{
37706f6ba60Sopenharmony_ci    return stats_[VMHEAP_UNKNOWN].swappedOutPss_ + stats_[VMHEAP_NATIVE].swappedOutPss_ +
37806f6ba60Sopenharmony_ci           stats_[VMHEAP_SENSITIVE_VM].swappedOutPss_;
37906f6ba60Sopenharmony_ci}
380