From 6233deeca757293ccf93110e470e7f42520f6fd9 Mon Sep 17 00:00:00 2001 From: "thomasvl@chromium.org" Date: Thu, 11 Jun 2009 12:03:29 +0000 Subject: Some basic memory api support that is needed for perf tests and i think the task window. BUG=none TEST=perf bots should have memory numbers now like linux. Review URL: http://codereview.chromium.org/118436 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18159 0039d316-1c4b-4281-b951-d872f2087c98 --- base/process_util.h | 8 ++++---- base/process_util_mac.mm | 46 ++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 46 insertions(+), 8 deletions(-) (limited to 'base') diff --git a/base/process_util.h b/base/process_util.h index 4fe081f..81b6d18 100644 --- a/base/process_util.h +++ b/base/process_util.h @@ -332,13 +332,13 @@ class ProcessMetrics { ~ProcessMetrics(); // Returns the current space allocated for the pagefile, in bytes (these pages - // may or may not be in memory). On Linux, this returns the total virtual - // memory size. + // may or may not be in memory). On Linux and Mac, this returns the total + // virtual memory size of the calling process. size_t GetPagefileUsage() const; // Returns the peak space allocated for the pagefile, in bytes. size_t GetPeakPagefileUsage() const; - // Returns the current working set size, in bytes. On Linux, this returns - // the resident set size. + // Returns the current working set size, in bytes. On Linux & Mac, this + // returns the resident set size. size_t GetWorkingSetSize() const; // Returns the peak working set size, in bytes. size_t GetPeakWorkingSetSize() const; diff --git a/base/process_util_mac.mm b/base/process_util_mac.mm index de59896..a55e279 100644 --- a/base/process_util_mac.mm +++ b/base/process_util_mac.mm @@ -7,6 +7,9 @@ #import #include +#include +#include +#include #include #include #include @@ -234,8 +237,29 @@ bool ProcessMetrics::GetIOCounters(IoCounters* io_counters) const { } size_t ProcessMetrics::GetPagefileUsage() const { - NOTIMPLEMENTED(); - return 0; + size_t result = 0; + + kern_return_t kr; + struct task_basic_info info; + mach_msg_type_number_t info_count = TASK_BASIC_INFO_COUNT; + + kr = task_info(mach_task_self(), TASK_BASIC_INFO, + reinterpret_cast(static_cast(&info)), + &info_count); + if (kr == KERN_SUCCESS) { + // The app's virtual address map contains lots of shared code that will + // show up as part of our virtual_size. So, in order to reflect a "vsize" + // that is more inline with what Activity Monitor and top report, we need + // to subtract this stuff out. + if (info.virtual_size > (SHARED_TEXT_REGION_SIZE + SHARED_DATA_REGION_SIZE)) + info.virtual_size -= (SHARED_TEXT_REGION_SIZE + SHARED_DATA_REGION_SIZE); + + result = info.virtual_size; + } else { + LOG(ERROR) << "failed to collect the process virtual size"; + } + + return result; } size_t ProcessMetrics::GetPeakPagefileUsage() const { @@ -244,8 +268,22 @@ size_t ProcessMetrics::GetPeakPagefileUsage() const { } size_t ProcessMetrics::GetWorkingSetSize() const { - NOTIMPLEMENTED(); - return 0; + size_t result = 0; + + kern_return_t kr; + struct task_basic_info info; + mach_msg_type_number_t info_count = TASK_BASIC_INFO_COUNT; + + kr = task_info(mach_task_self(), TASK_BASIC_INFO, + reinterpret_cast(static_cast(&info)), + &info_count); + if (kr == KERN_SUCCESS) { + result = info.resident_size; + } else { + LOG(ERROR) << "failed to collect the process resident size"; + } + + return result; } size_t ProcessMetrics::GetPeakWorkingSetSize() const { -- cgit v1.1