diff options
author | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-11 17:46:08 +0000 |
---|---|---|
committer | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-11 17:46:08 +0000 |
commit | 98947a0beaa29f997e77e010cfaec72666e045e2 (patch) | |
tree | 7ed453cb5d337cf6d83208a16a95d0e1394be0b2 /base | |
parent | e2327e1c76276b05492c4d7909432d323c7fdb55 (diff) | |
download | chromium_src-98947a0beaa29f997e77e010cfaec72666e045e2.zip chromium_src-98947a0beaa29f997e77e010cfaec72666e045e2.tar.gz chromium_src-98947a0beaa29f997e77e010cfaec72666e045e2.tar.bz2 |
Speed up the Task Manager on linux.
- Unify the calls to get shared memory and private memory. On Linux, these call the same API and on Linux, it takes >10ms to fetch both values each time it is called.
- Cache the returned memory values. While sorting the task manager by memory, it would make the expensive memory call for each row on each sort operation.
BUG=40033
TEST=Existing task manager tests.
Review URL: http://codereview.chromium.org/2047009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46938 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/process_util.h | 10 | ||||
-rw-r--r-- | base/process_util_linux.cc | 15 | ||||
-rw-r--r-- | base/process_util_mac.mm | 12 | ||||
-rw-r--r-- | base/process_util_win.cc | 23 |
4 files changed, 44 insertions, 16 deletions
diff --git a/base/process_util.h b/base/process_util.h index ec3510a..b8bcfd4 100644 --- a/base/process_util.h +++ b/base/process_util.h @@ -481,10 +481,12 @@ class ProcessMetrics { size_t GetWorkingSetSize() const; // Returns the peak working set size, in bytes. size_t GetPeakWorkingSetSize() const; - // Returns private usage, in bytes. Private bytes is the amount - // of memory currently allocated to a process that cannot be shared. - // Note: returns 0 on unsupported OSes: prior to XP SP2. - size_t GetPrivateBytes() const; + // Returns private and sharedusage, in bytes. Private bytes is the amount of + // memory currently allocated to a process that cannot be shared. Returns + // false on platform specific error conditions. Note: |private_bytes| + // returns 0 on unsupported OSes: prior to XP SP2. + bool GetMemoryBytes(size_t* private_bytes, + size_t* shared_bytes); // Fills a CommittedKBytes with both resident and paged // memory usage as per definition of CommittedBytes. void GetCommittedKBytes(CommittedKBytes* usage) const; diff --git a/base/process_util_linux.cc b/base/process_util_linux.cc index 0a2cc0d..ee44638 100644 --- a/base/process_util_linux.cc +++ b/base/process_util_linux.cc @@ -244,10 +244,19 @@ size_t ProcessMetrics::GetPeakWorkingSetSize() const { return 0; } -size_t ProcessMetrics::GetPrivateBytes() const { +bool ProcessMetrics::GetMemoryBytes(size_t* private_bytes, + size_t* shared_bytes) { WorkingSetKBytes ws_usage; - GetWorkingSetKBytes(&ws_usage); - return ws_usage.priv << 10; + if (!GetWorkingSetKBytes(&ws_usage)) + return false; + + if (private_bytes) + *private_bytes = ws_usage.priv << 10; + + if (shared_bytes) + *shared_bytes = ws_usage.shared * 1024; + + return true; } // Private and Shared working set sizes are obtained from /proc/<pid>/smaps. diff --git a/base/process_util_mac.mm b/base/process_util_mac.mm index f119e78..9fcc43c 100644 --- a/base/process_util_mac.mm +++ b/base/process_util_mac.mm @@ -222,10 +222,16 @@ size_t ProcessMetrics::GetPeakWorkingSetSize() const { return 0; } -size_t ProcessMetrics::GetPrivateBytes() const { - return 0; +// OSX appears to use a different system to get its memory. +bool ProcessMetrics::GetMemoryBytes(size_t* private_bytes, + size_t* shared_bytes) { + if (private_bytes) + *private_bytes = 0; + if (shared_bytes) + *shared_bytes = 0; + return true; } - + void ProcessMetrics::GetCommittedKBytes(CommittedKBytes* usage) const { } diff --git a/base/process_util_win.cc b/base/process_util_win.cc index 8df8de5..2eb73ca 100644 --- a/base/process_util_win.cc +++ b/base/process_util_win.cc @@ -515,18 +515,29 @@ size_t ProcessMetrics::GetPeakWorkingSetSize() const { return 0; } -size_t ProcessMetrics::GetPrivateBytes() const { +bool ProcessMetrics::GetMemoryBytes(size_t* private_bytes, + size_t* shared_bytes) { // PROCESS_MEMORY_COUNTERS_EX is not supported until XP SP2. // GetProcessMemoryInfo() will simply fail on prior OS. So the requested // information is simply not available. Hence, we will return 0 on unsupported // OSes. Unlike most Win32 API, we don't need to initialize the "cb" member. PROCESS_MEMORY_COUNTERS_EX pmcx; - if (GetProcessMemoryInfo(process_, - reinterpret_cast<PROCESS_MEMORY_COUNTERS*>(&pmcx), - sizeof(pmcx))) { - return pmcx.PrivateUsage; + if (private_bytes && + GetProcessMemoryInfo(process_, + reinterpret_cast<PROCESS_MEMORY_COUNTERS*>(&pmcx), + sizeof(pmcx))) { + *private_bytes = pmcx.PrivateUsage; } - return 0; + + if (shared_bytes) { + WorkingSetKBytes ws_usage; + if (!GetWorkingSetKBytes(&ws_usage)) + return false; + + *shared_bytes = ws_usage.shared * 1024; + } + + return true; } void ProcessMetrics::GetCommittedKBytes(CommittedKBytes* usage) const { |