summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorerg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-11 17:46:08 +0000
committererg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-11 17:46:08 +0000
commit98947a0beaa29f997e77e010cfaec72666e045e2 (patch)
tree7ed453cb5d337cf6d83208a16a95d0e1394be0b2 /chrome/browser
parente2327e1c76276b05492c4d7909432d323c7fdb55 (diff)
downloadchromium_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 'chrome/browser')
-rw-r--r--chrome/browser/task_manager.cc56
-rw-r--r--chrome/browser/task_manager.h19
2 files changed, 58 insertions, 17 deletions
diff --git a/chrome/browser/task_manager.cc b/chrome/browser/task_manager.cc
index a604b70..1d2907a 100644
--- a/chrome/browser/task_manager.cc
+++ b/chrome/browser/task_manager.cc
@@ -404,25 +404,34 @@ double TaskManagerModel::GetCPUUsage(TaskManager::Resource* resource) const {
}
bool TaskManagerModel::GetPrivateMemory(int index, size_t* result) const {
- *result = 0;
- base::ProcessMetrics* process_metrics;
- if (!GetProcessMetricsForRow(index, &process_metrics))
- return false;
- *result = process_metrics->GetPrivateBytes();
- if (*result == 0)
- return false;
+ base::ProcessHandle handle = resources_[index]->GetProcess();
+ MemoryUsageMap::const_iterator iter = memory_usage_map_.find(handle);
+ if (iter == memory_usage_map_.end()) {
+ std::pair<size_t, size_t> usage;
+ if (!GetAndCacheMemoryMetrics(handle, &usage))
+ return false;
+
+ *result = usage.first;
+ } else {
+ *result = iter->second.first;
+ }
+
return true;
}
bool TaskManagerModel::GetSharedMemory(int index, size_t* result) const {
- *result = 0;
- base::ProcessMetrics* process_metrics;
- if (!GetProcessMetricsForRow(index, &process_metrics))
- return false;
- base::WorkingSetKBytes ws_usage;
- if (!process_metrics->GetWorkingSetKBytes(&ws_usage))
- return false;
- *result = ws_usage.shared * 1024;
+ base::ProcessHandle handle = resources_[index]->GetProcess();
+ MemoryUsageMap::const_iterator iter = memory_usage_map_.find(handle);
+ if (iter == memory_usage_map_.end()) {
+ std::pair<size_t, size_t> usage;
+ if (!GetAndCacheMemoryMetrics(handle, &usage))
+ return false;
+
+ *result = usage.second;
+ } else {
+ *result = iter->second.second;
+ }
+
return true;
}
@@ -718,6 +727,9 @@ void TaskManagerModel::Refresh() {
cpu_usage_map_[process] = metrics_iter->second->GetCPUUsage();
}
+ // Clear the memory values so they can be querried lazily.
+ memory_usage_map_.clear();
+
// Compute the new network usage values.
displayed_network_usage_map_.clear();
for (ResourceValueMap::iterator iter = current_byte_count_map_.begin();
@@ -952,3 +964,17 @@ void TaskManager::OpenAboutMemory() {
browser->window()->Show();
}
}
+
+bool TaskManagerModel::GetAndCacheMemoryMetrics(
+ base::ProcessHandle handle,
+ std::pair<size_t, size_t>* usage) const {
+ MetricsMap::const_iterator iter = metrics_map_.find(handle);
+ if (iter == metrics_map_.end())
+ return false;
+
+ if (!iter->second->GetMemoryBytes(&usage->first, &usage->second))
+ return false;
+
+ memory_usage_map_.insert(std::make_pair(handle, *usage));
+ return true;
+}
diff --git a/chrome/browser/task_manager.h b/chrome/browser/task_manager.h
index 88b452d..6f807b8 100644
--- a/chrome/browser/task_manager.h
+++ b/chrome/browser/task_manager.h
@@ -300,6 +300,8 @@ class TaskManagerModel : public URLRequestJobTracker::JobObserver,
typedef std::map<base::ProcessHandle, base::ProcessMetrics*> MetricsMap;
typedef std::map<base::ProcessHandle, double> CPUUsageMap;
typedef std::map<TaskManager::Resource*, int64> ResourceValueMap;
+ typedef std::map<base::ProcessHandle,
+ std::pair<size_t, size_t> > MemoryUsageMap;
// Updates the values for all rows.
void Refresh();
@@ -328,11 +330,13 @@ class TaskManagerModel : public URLRequestJobTracker::JobObserver,
double GetCPUUsage(TaskManager::Resource* resource) const;
// Gets the private memory (in bytes) that should be displayed for the passed
- // resource index.
+ // resource index. Caches the result since this calculation can take time on
+ // some platforms.
bool GetPrivateMemory(int index, size_t* result) const;
// Gets the shared memory (in bytes) that should be displayed for the passed
- // resource index.
+ // resource index. Caches the result since this calculation can take time on
+ // some platforms.
bool GetSharedMemory(int index, size_t* result) const;
// Gets the physical memory (in bytes) that should be displayed for the passed
@@ -355,6 +359,11 @@ class TaskManagerModel : public URLRequestJobTracker::JobObserver,
// displayed in the task manager's memory cell.
std::wstring GetMemCellText(int64 number) const;
+ // Looks up the data for |handle| and puts it in the mutable cache
+ // |memory_usage_map_|.
+ bool GetAndCacheMemoryMetrics(base::ProcessHandle handle,
+ std::pair<size_t, size_t>* usage) const;
+
// The list of providers to the task manager. They are ref counted.
ResourceProviderList providers_;
@@ -383,6 +392,12 @@ class TaskManagerModel : public URLRequestJobTracker::JobObserver,
// A map that contains the CPU usage (in %) for a process since last refresh.
CPUUsageMap cpu_usage_map_;
+ // A map that contains the private/shared memory usage of the process. We
+ // cache this because the same APIs are called on linux and windows, and
+ // because the linux call takes >10ms to complete. This cache is cleared on
+ // every Refresh().
+ mutable MemoryUsageMap memory_usage_map_;
+
ObserverList<TaskManagerModelObserver> observer_list_;
// Whether we are currently in the process of updating.