From 3839f89ec5ee34c3ece62ca87f90954269ac8622 Mon Sep 17 00:00:00 2001 From: sakura_pc Date: Thu, 13 Jul 2023 17:08:12 +0800 Subject: [PATCH] add SwapPss for GetPssByPid Signed-off-by: sakura_pc Signed-off-by: sakura_pc --- libmeminfo/src/meminfo.cpp | 12 ++++++------ libmeminfo/test/unittest/meminfo_test.cpp | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/libmeminfo/src/meminfo.cpp b/libmeminfo/src/meminfo.cpp index ee424d3..7bb2408 100644 --- a/libmeminfo/src/meminfo.cpp +++ b/libmeminfo/src/meminfo.cpp @@ -13,13 +13,14 @@ * limitations under the License. */ +#include "meminfo.h" + #include #include #include #include "file_ex.h" // LoadStringFromFile #include "hilog/log.h" -#include "meminfo.h" namespace OHOS { namespace MemInfo { @@ -68,7 +69,7 @@ uint64_t GetRssByPid(const int pid) return size; } -// get pss from smaps_rollup, include graphics memory +// get Pss and SwapPss from smaps_rollup, include graphics memory uint64_t GetPssByPid(const int pid) { uint64_t size = 0; @@ -80,15 +81,14 @@ uint64_t GetPssByPid(const int pid) } std::string content; - while (getline(in, content)) { + while (in.good() && getline(in, content)) { std::string::size_type typePos = content.find(":"); if (typePos != content.npos) { std::string type = content.substr(0, typePos); - if (type == "Pss") { + if (type == "Pss" || type == "SwapPss") { std::string valueStr = content.substr(typePos + 1); const int base = 10; - size = strtoull(valueStr.c_str(), nullptr, base); - break; + size += strtoull(valueStr.c_str(), nullptr, base); } } } diff --git a/libmeminfo/test/unittest/meminfo_test.cpp b/libmeminfo/test/unittest/meminfo_test.cpp index c6d3df5..379efe3 100644 --- a/libmeminfo/test/unittest/meminfo_test.cpp +++ b/libmeminfo/test/unittest/meminfo_test.cpp @@ -13,10 +13,11 @@ * limitations under the License. */ +#include "meminfo.h" + #include #include "gtest/gtest.h" -#include "meminfo.h" namespace OHOS { namespace MemInfo { -- Gitee