summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorthomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-11 12:03:29 +0000
committerthomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-11 12:03:29 +0000
commit6233deeca757293ccf93110e470e7f42520f6fd9 (patch)
tree6569818da2d620cd7eb610012803ac3348422b20 /base
parent0a6fc039802f84e286934bf8069f3cbf35311e14 (diff)
downloadchromium_src-6233deeca757293ccf93110e470e7f42520f6fd9.zip
chromium_src-6233deeca757293ccf93110e470e7f42520f6fd9.tar.gz
chromium_src-6233deeca757293ccf93110e470e7f42520f6fd9.tar.bz2
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
Diffstat (limited to 'base')
-rw-r--r--base/process_util.h8
-rw-r--r--base/process_util_mac.mm46
2 files changed, 46 insertions, 8 deletions
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 <Cocoa/Cocoa.h>
#include <crt_externs.h>
+#include <mach/shared_memory_server.h>
+#include <mach/task_info.h>
+#include <mach/task.h>
#include <spawn.h>
#include <sys/sysctl.h>
#include <sys/types.h>
@@ -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<task_info_t>(static_cast<void*>(&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<task_info_t>(static_cast<void*>(&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 {