summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-30 18:28:44 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-30 18:28:44 +0000
commit149fd6df098f406fcb8bcabc12c9a8fefda49058 (patch)
treee7b1838eb63d9ba7883cc8c2c85fdde6a84a1759
parentadeedaff76d28c2dd2c75bd399dbae21c415d037 (diff)
downloadchromium_src-149fd6df098f406fcb8bcabc12c9a8fefda49058.zip
chromium_src-149fd6df098f406fcb8bcabc12c9a8fefda49058.tar.gz
chromium_src-149fd6df098f406fcb8bcabc12c9a8fefda49058.tar.bz2
Make it possible to sort the WebCore Cache size columns in the Task Manager. Also only show cache sizes once per process since the WebCore Cahce is a singleton within the renderer process.
BUG=16221 TEST=none Review URL: http://codereview.chromium.org/244041 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27636 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/task_manager.cc81
-rw-r--r--chrome/browser/task_manager.h9
-rw-r--r--chrome/browser/task_manager_resource_providers.cc29
-rw-r--r--chrome/browser/task_manager_resource_providers.h9
-rw-r--r--chrome/browser/views/task_manager_view.cc6
5 files changed, 65 insertions, 69 deletions
diff --git a/chrome/browser/task_manager.cc b/chrome/browser/task_manager.cc
index 1ac2411..d01e94f 100644
--- a/chrome/browser/task_manager.cc
+++ b/chrome/browser/task_manager.cc
@@ -25,11 +25,13 @@
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_job.h"
+namespace {
+
// The delay between updates of the information (in ms).
-static const int kUpdateTimeMs = 1000;
+const int kUpdateTimeMs = 1000;
template <class T>
-static int ValueCompare(T value1, T value2) {
+int ValueCompare(T value1, T value2) {
if (value1 < value2)
return -1;
if (value1 == value2)
@@ -37,18 +39,12 @@ static int ValueCompare(T value1, T value2) {
return 1;
}
-// TaskManager::Resource default impls.
-
-std::wstring TaskManager::Resource::GetWebCoreImageCacheSize() {
- return l10n_util::GetString(IDS_TASK_MANAGER_NA_CELL_TEXT);
-}
-
-std::wstring TaskManager::Resource::GetWebCoreScriptsCacheSize() {
- return l10n_util::GetString(IDS_TASK_MANAGER_NA_CELL_TEXT);
+std::wstring FormatStatsSize(const WebKit::WebCache::ResourceTypeStat& stat) {
+ return l10n_util::GetStringF(IDS_TASK_MANAGER_CACHE_SIZE_CELL_TEXT,
+ FormatBytes(stat.size, DATA_UNITS_KILOBYTE, false),
+ FormatBytes(stat.liveSize, DATA_UNITS_KILOBYTE, false));
}
-std::wstring TaskManager::Resource::GetWebCoreCSSCacheSize() {
- return l10n_util::GetString(IDS_TASK_MANAGER_NA_CELL_TEXT);
}
////////////////////////////////////////////////////////////////////////////////
@@ -176,19 +172,31 @@ std::wstring TaskManagerModel::GetResourceGoatsTeleported(int index) const {
std::wstring TaskManagerModel::GetResourceWebCoreImageCacheSize(
int index) const {
DCHECK(index < ResourceCount());
- return resources_[index]->GetWebCoreImageCacheSize();
+ if (!resources_[index]->ReportsCacheStats())
+ return l10n_util::GetString(IDS_TASK_MANAGER_NA_CELL_TEXT);
+ const WebKit::WebCache::ResourceTypeStats stats(
+ resources_[index]->GetWebCoreCacheStats());
+ return FormatStatsSize(stats.images);
}
std::wstring TaskManagerModel::GetResourceWebCoreScriptsCacheSize(
int index) const {
DCHECK(index < ResourceCount());
- return resources_[index]->GetWebCoreScriptsCacheSize();
+ if (!resources_[index]->ReportsCacheStats())
+ return l10n_util::GetString(IDS_TASK_MANAGER_NA_CELL_TEXT);
+ const WebKit::WebCache::ResourceTypeStats stats(
+ resources_[index]->GetWebCoreCacheStats());
+ return FormatStatsSize(stats.scripts);
}
std::wstring TaskManagerModel::GetResourceWebCoreCSSCacheSize(
int index) const {
DCHECK(index < ResourceCount());
- return resources_[index]->GetWebCoreCSSCacheSize();
+ if (!resources_[index]->ReportsCacheStats())
+ return l10n_util::GetString(IDS_TASK_MANAGER_NA_CELL_TEXT);
+ const WebKit::WebCache::ResourceTypeStats stats(
+ resources_[index]->GetWebCoreCacheStats());
+ return FormatStatsSize(stats.cssStyleSheets);
}
@@ -266,29 +274,19 @@ int TaskManagerModel::CompareValues(int row1, int row2, int col_id) const {
return ValueCompare<int>(GetCPUUsage(resources_[row1]),
GetCPUUsage(resources_[row2]));
- case IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN: {
- base::ProcessMetrics* pm1;
- base::ProcessMetrics* pm2;
- if (!GetProcessMetricsForRows(row1, row2, &pm1, &pm2))
- return 0;
- return ValueCompare<size_t>(GetPrivateMemory(pm1),
- GetPrivateMemory(pm2));
- }
-
- case IDS_TASK_MANAGER_SHARED_MEM_COLUMN: {
- base::ProcessMetrics* pm1;
- base::ProcessMetrics* pm2;
- if (!GetProcessMetricsForRows(row1, row2, &pm1, &pm2))
- return 0;
- return ValueCompare<size_t>(GetSharedMemory(pm1),
- GetSharedMemory(pm2));
- }
-
+ case IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN:
+ case IDS_TASK_MANAGER_SHARED_MEM_COLUMN:
case IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN: {
base::ProcessMetrics* pm1;
base::ProcessMetrics* pm2;
if (!GetProcessMetricsForRows(row1, row2, &pm1, &pm2))
return 0;
+ if (col_id == IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN) {
+ return ValueCompare<size_t>(GetPrivateMemory(pm1),
+ GetPrivateMemory(pm2));
+ }
+ if (col_id == IDS_TASK_MANAGER_SHARED_MEM_COLUMN)
+ return ValueCompare<size_t>(GetSharedMemory(pm1), GetSharedMemory(pm2));
return ValueCompare<size_t>(GetPhysicalMemory(pm1),
GetPhysicalMemory(pm2));
}
@@ -299,6 +297,23 @@ int TaskManagerModel::CompareValues(int row1, int row2, int col_id) const {
return ValueCompare<int>(proc1_id, proc2_id);
}
+ case IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN:
+ case IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN:
+ case IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN: {
+ WebKit::WebCache::ResourceTypeStats stats1 = { { 0 } };
+ WebKit::WebCache::ResourceTypeStats stats2 = { { 0 } };
+ if (resources_[row1]->ReportsCacheStats())
+ stats1 = resources_[row1]->GetWebCoreCacheStats();
+ if (resources_[row2]->ReportsCacheStats())
+ stats2 = resources_[row2]->GetWebCoreCacheStats();
+ if (col_id == IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN)
+ return ValueCompare<size_t>(stats1.images.size, stats2.images.size);
+ if (col_id == IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN)
+ return ValueCompare<size_t>(stats1.scripts.size, stats2.scripts.size);
+ return ValueCompare<size_t>(stats1.cssStyleSheets.size,
+ stats2.cssStyleSheets.size);
+ }
+
default:
return ValueCompare<int>(GetStatsValue(resources_[row1], col_id),
GetStatsValue(resources_[row2], col_id));
diff --git a/chrome/browser/task_manager.h b/chrome/browser/task_manager.h
index 666b643..ff402a4 100644
--- a/chrome/browser/task_manager.h
+++ b/chrome/browser/task_manager.h
@@ -47,13 +47,14 @@ class TaskManager {
virtual SkBitmap GetIcon() const = 0;
virtual base::ProcessHandle GetProcess() const = 0;
- virtual std::wstring GetWebCoreImageCacheSize();
- virtual std::wstring GetWebCoreScriptsCacheSize();
- virtual std::wstring GetWebCoreCSSCacheSize();
+ virtual bool ReportsCacheStats() const { return false; }
+ virtual WebKit::WebCache::ResourceTypeStats GetWebCoreCacheStats() const {
+ return WebKit::WebCache::ResourceTypeStats();
+ }
// A helper function for ActivateFocusedTab. Returns NULL by default
// because not all resources have an assoiciated tab.
- virtual TabContents* GetTabContents() const {return NULL;}
+ virtual TabContents* GetTabContents() const { return NULL; }
// Whether this resource does report the network usage accurately.
// This controls whether 0 or N/A is displayed when no bytes have been
diff --git a/chrome/browser/task_manager_resource_providers.cc b/chrome/browser/task_manager_resource_providers.cc
index 8899463..20ef4d1a 100644
--- a/chrome/browser/task_manager_resource_providers.cc
+++ b/chrome/browser/task_manager_resource_providers.cc
@@ -85,36 +85,13 @@ std::wstring TaskManagerTabContentsResource::GetTitle() const {
return l10n_util::GetStringF(IDS_TASK_MANAGER_TAB_PREFIX, tab_title);
}
-std::wstring FormatStatsSize(const WebKit::WebCache::ResourceTypeStat& stat) {
- std::wstring size = FormatBytes(stat.size, DATA_UNITS_KILOBYTE, false);
- std::wstring live_size = FormatBytes(stat.liveSize,
- DATA_UNITS_KILOBYTE,
- false);
- return l10n_util::GetStringF(IDS_TASK_MANAGER_CACHE_SIZE_CELL_TEXT,
- size,
- live_size);
-}
-
-void TaskManagerTabContentsResource::UpdateResourceStats() {
+WebKit::WebCache::ResourceTypeStats
+ TaskManagerTabContentsResource::GetWebCoreCacheStats() const {
if (!pending_stats_update_) {
tab_contents_->render_view_host()->Send(new ViewMsg_GetCacheResourceStats);
pending_stats_update_ = true;
}
-}
-
-std::wstring TaskManagerTabContentsResource::GetWebCoreImageCacheSize() {
- UpdateResourceStats();
- return FormatStatsSize(stats_.images);
-}
-
-std::wstring TaskManagerTabContentsResource::GetWebCoreScriptsCacheSize() {
- UpdateResourceStats();
- return FormatStatsSize(stats_.scripts);
-}
-
-std::wstring TaskManagerTabContentsResource::GetWebCoreCSSCacheSize() {
- UpdateResourceStats();
- return FormatStatsSize(stats_.cssStyleSheets);
+ return stats_;
}
void TaskManagerTabContentsResource::NotifyResourceTypeStats(
diff --git a/chrome/browser/task_manager_resource_providers.h b/chrome/browser/task_manager_resource_providers.h
index d92767f..3253d869 100644
--- a/chrome/browser/task_manager_resource_providers.h
+++ b/chrome/browser/task_manager_resource_providers.h
@@ -32,9 +32,8 @@ class TaskManagerTabContentsResource : public TaskManager::Resource {
base::ProcessHandle GetProcess() const;
TabContents* GetTabContents() const;
- virtual std::wstring GetWebCoreImageCacheSize();
- virtual std::wstring GetWebCoreScriptsCacheSize();
- virtual std::wstring GetWebCoreCSSCacheSize();
+ virtual bool ReportsCacheStats() const { return true; }
+ virtual WebKit::WebCache::ResourceTypeStats GetWebCoreCacheStats() const;
// TabContents always provide the network usage.
bool SupportNetworkUsage() const { return true; }
@@ -44,8 +43,6 @@ class TaskManagerTabContentsResource : public TaskManager::Resource {
const WebKit::WebCache::ResourceTypeStats& stats);
private:
- void UpdateResourceStats();
-
TabContents* tab_contents_;
base::ProcessHandle process_;
int pid_;
@@ -55,7 +52,7 @@ class TaskManagerTabContentsResource : public TaskManager::Resource {
// for an update unless a query is already outstanding.
WebKit::WebCache::ResourceTypeStats stats_;
// This flag is true if we are waiting for the renderer to report its stats.
- bool pending_stats_update_;
+ mutable bool pending_stats_update_;
DISALLOW_COPY_AND_ASSIGN(TaskManagerTabContentsResource);
};
diff --git a/chrome/browser/views/task_manager_view.cc b/chrome/browser/views/task_manager_view.cc
index b41fbe1..195a67e 100644
--- a/chrome/browser/views/task_manager_view.cc
+++ b/chrome/browser/views/task_manager_view.cc
@@ -113,12 +113,18 @@ std::wstring TaskManagerTableModel::GetText(int row, int col_id) {
return model_->GetResourceGoatsTeleported(row);
case IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN:
+ if (!model_->IsResourceFirstInGroup(row))
+ return std::wstring();
return model_->GetResourceWebCoreImageCacheSize(row);
case IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN:
+ if (!model_->IsResourceFirstInGroup(row))
+ return std::wstring();
return model_->GetResourceWebCoreScriptsCacheSize(row);
case IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN:
+ if (!model_->IsResourceFirstInGroup(row))
+ return std::wstring();
return model_->GetResourceWebCoreCSSCacheSize(row);
default: