From 3d622cdd7be44b496b1a46a5aa02b5e33f16c0f5 Mon Sep 17 00:00:00 2001 From: nroskill Date: Fri, 30 Jul 2021 19:05:48 +0800 Subject: [PATCH] fix get_virtual_memory_used core in arm --- src/observer/main.cpp | 2 +- src/share/ob_tenant_mgr.cpp | 22 ++++++++-------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/observer/main.cpp b/src/observer/main.cpp index 74d97c6c6..185400c4e 100644 --- a/src/observer/main.cpp +++ b/src/observer/main.cpp @@ -461,7 +461,7 @@ int main(int argc, char* argv[]) if (0 == memory_used) { _LOG_INFO("Get virtual memory info failed"); } else { - _LOG_INFO("Virtual memory : %ld byte", memory_used); + _LOG_INFO("Virtual memory : %'15ld byte", memory_used); } // print in log file. print_args(argc, argv); diff --git a/src/share/ob_tenant_mgr.cpp b/src/share/ob_tenant_mgr.cpp index 0a3a94e15..ae993b961 100644 --- a/src/share/ob_tenant_mgr.cpp +++ b/src/share/ob_tenant_mgr.cpp @@ -10,6 +10,7 @@ * See the Mulan PubL v2 for more details. */ +#include #include "lib/utility/ob_print_utils.h" #include "lib/alloc/malloc_hook.h" #include "share/ob_tenant_mgr.h" @@ -26,20 +27,13 @@ int64_t get_virtual_memory_used() { constexpr int BUFFER_SIZE = 128; - char buf[BUFFER_SIZE]; - snprintf(buf, BUFFER_SIZE, "/proc/%d/status", getpid()); - std::ifstream status(buf); - int64_t used = 0; - while (status && 0 == used) { - status >> buf; - if (strncmp(buf, "VmSize:", BUFFER_SIZE) == 0) { - status >> buf; - used = std::stoi(buf); - } else { - status.ignore(std::numeric_limits::max(), '\n'); - } - } - return used * 1024; + char filename[BUFFER_SIZE]; + int64_t page_cnt = 0; + snprintf(filename, BUFFER_SIZE, "/proc/%d/statm", getpid()); + FILE* statm = fopen(filename, "r"); + fscanf(statm, "%ld", &page_cnt); + fclose(statm); + return page_cnt * sysconf(_SC_PAGESIZE); } namespace oceanbase {