diff --git a/libmeminfo/src/meminfo.cpp b/libmeminfo/src/meminfo.cpp index ee424d3ce5f4132b30d7c8e95dbc93528a78c81d..7bb2408953d0bce6e72e43daeec8631c744f3ea0 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 c6d3df59d3277dc69f3dcc62013ffbb1c962658d..379efe3102f2c9edb206393c6d73dc407418de9e 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 {