100600bfbSopenharmony_ci/*
200600bfbSopenharmony_ci* Copyright (C) 2021-2022 Huawei Device Co., Ltd.
300600bfbSopenharmony_ci* Licensed under the Apache License, Version 2.0 (the "License");
400600bfbSopenharmony_ci* you may not use this file except in compliance with the License.
500600bfbSopenharmony_ci* You may obtain a copy of the License at
600600bfbSopenharmony_ci*
700600bfbSopenharmony_ci* http://www.apache.org/licenses/LICENSE-2.0
800600bfbSopenharmony_ci*
900600bfbSopenharmony_ci* Unless required by applicable law or agreed to in writing, software
1000600bfbSopenharmony_ci* distributed under the License is distributed on an "AS IS" BASIS,
1100600bfbSopenharmony_ci* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1200600bfbSopenharmony_ci* See the License for the specific language governing permissions and
1300600bfbSopenharmony_ci* limitations under the License.
1400600bfbSopenharmony_ci*/
1500600bfbSopenharmony_ci#include "include/dump_usage.h"
1600600bfbSopenharmony_ci#include "dump_manager_cpu_client.h"
1700600bfbSopenharmony_ci#include "executor/memory/parse/parse_smaps_rollup_info.h"
1800600bfbSopenharmony_ci#include "executor/memory/memory_util.h"
1900600bfbSopenharmony_ci#include "hilog_wrapper.h"
2000600bfbSopenharmony_ci
2100600bfbSopenharmony_ciusing namespace std;
2200600bfbSopenharmony_cinamespace OHOS {
2300600bfbSopenharmony_cinamespace HiviewDFX {
2400600bfbSopenharmony_ciDumpUsage::DumpUsage()
2500600bfbSopenharmony_ci{
2600600bfbSopenharmony_ci}
2700600bfbSopenharmony_ci
2800600bfbSopenharmony_ciDumpUsage::~DumpUsage()
2900600bfbSopenharmony_ci{
3000600bfbSopenharmony_ci}
3100600bfbSopenharmony_ci
3200600bfbSopenharmony_cibool DumpUsage::GetMemInfo(const int &pid, MemInfoData::MemInfo &info)
3300600bfbSopenharmony_ci{
3400600bfbSopenharmony_ci    MemoryUtil::GetInstance().InitMemInfo(info);
3500600bfbSopenharmony_ci    unique_ptr<ParseSmapsRollupInfo> parseSmapsRollupInfo = make_unique<ParseSmapsRollupInfo>();
3600600bfbSopenharmony_ci    return parseSmapsRollupInfo->GetMemInfo(pid, info);
3700600bfbSopenharmony_ci}
3800600bfbSopenharmony_ci
3900600bfbSopenharmony_ciuint64_t DumpUsage::GetPss(const int &pid)
4000600bfbSopenharmony_ci{
4100600bfbSopenharmony_ci    MemInfoData::MemInfo info;
4200600bfbSopenharmony_ci    return GetMemInfo(pid, info) ? info.pss + info.swapPss : 0;
4300600bfbSopenharmony_ci}
4400600bfbSopenharmony_ci
4500600bfbSopenharmony_ciuint64_t DumpUsage::GetPrivateDirty(const int &pid)
4600600bfbSopenharmony_ci{
4700600bfbSopenharmony_ci    MemInfoData::MemInfo info;
4800600bfbSopenharmony_ci    return GetMemInfo(pid, info) ? info.privateDirty : 0;
4900600bfbSopenharmony_ci}
5000600bfbSopenharmony_ci
5100600bfbSopenharmony_ciuint64_t DumpUsage::GetSharedDirty(const int &pid)
5200600bfbSopenharmony_ci{
5300600bfbSopenharmony_ci    MemInfoData::MemInfo info;
5400600bfbSopenharmony_ci    return GetMemInfo(pid, info) ? info.sharedDirty : 0;
5500600bfbSopenharmony_ci}
5600600bfbSopenharmony_ci
5700600bfbSopenharmony_cidouble DumpUsage::GetCpuUsage(const int &pid)
5800600bfbSopenharmony_ci{
5900600bfbSopenharmony_ci    double cpuUsage = 0.00;
6000600bfbSopenharmony_ci#ifdef HIDUMPER_HIVIEWDFX_HIVIEW_ENABLE
6100600bfbSopenharmony_ci    auto& dumpManagerCpuClient = DumpManagerCpuClient::GetInstance();
6200600bfbSopenharmony_ci    dumpManagerCpuClient.GetCpuUsageByPid(pid, cpuUsage);
6300600bfbSopenharmony_ci    DUMPER_HILOGD(MODULE_CPU_SERVICE, "GetCpuUsage end, pid = %{public}d, cpuUsage = %{public}f", pid, cpuUsage);
6400600bfbSopenharmony_ci#endif
6500600bfbSopenharmony_ci    return cpuUsage;
6600600bfbSopenharmony_ci}
6700600bfbSopenharmony_ci} // namespace HiviewDFX
6800600bfbSopenharmony_ci} // namespace OHOS