Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(500)

Side by Side Diff: chrome/browser/task_manager.cc

Issue 339012: Report "N/A" for memory columns in Linux Task Manager. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Also fix minor bug in linux PorcessMetrics Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/task_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/task_manager.h" 5 #include "chrome/browser/task_manager.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/i18n/number_formatting.h" 10 #include "base/i18n/number_formatting.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 l10n_util::WrapStringWithLTRFormatting(&net_byte); 117 l10n_util::WrapStringWithLTRFormatting(&net_byte);
118 return net_byte; 118 return net_byte;
119 } 119 }
120 120
121 std::wstring TaskManagerModel::GetResourceCPUUsage(int index) const { 121 std::wstring TaskManagerModel::GetResourceCPUUsage(int index) const {
122 DCHECK(index < ResourceCount()); 122 DCHECK(index < ResourceCount());
123 return IntToWString(GetCPUUsage(resources_[index])); 123 return IntToWString(GetCPUUsage(resources_[index]));
124 } 124 }
125 125
126 std::wstring TaskManagerModel::GetResourcePrivateMemory(int index) const { 126 std::wstring TaskManagerModel::GetResourcePrivateMemory(int index) const {
127 DCHECK(index < ResourceCount()); 127 size_t private_mem;
128 // We report committed (working set + paged) private usage. This is NOT 128 if (!GetPrivateMemory(index, &private_mem))
129 // going to match what Windows Task Manager shows (which is working set). 129 return L"N/A";
130 MetricsMap::const_iterator iter = 130 return GetMemCellText(private_mem);
131 metrics_map_.find(resources_[index]->GetProcess());
132 DCHECK(iter != metrics_map_.end());
133 base::ProcessMetrics* process_metrics = iter->second;
134 return GetMemCellText(GetPrivateMemory(process_metrics));
135 } 131 }
136 132
137 std::wstring TaskManagerModel::GetResourceSharedMemory(int index) const { 133 std::wstring TaskManagerModel::GetResourceSharedMemory(int index) const {
138 DCHECK(index < ResourceCount()); 134 size_t shared_mem;
139 MetricsMap::const_iterator iter = 135 if (!GetSharedMemory(index, &shared_mem))
140 metrics_map_.find(resources_[index]->GetProcess()); 136 return L"N/A";
141 DCHECK(iter != metrics_map_.end()); 137 return GetMemCellText(shared_mem);
142 base::ProcessMetrics* process_metrics = iter->second;
143 return GetMemCellText(GetSharedMemory(process_metrics));
144 } 138 }
145 139
146 std::wstring TaskManagerModel::GetResourcePhysicalMemory(int index) const { 140 std::wstring TaskManagerModel::GetResourcePhysicalMemory(int index) const {
147 DCHECK(index < ResourceCount()); 141 size_t phys_mem;
148 MetricsMap::const_iterator iter = 142 GetPhysicalMemory(index, &phys_mem);
149 metrics_map_.find(resources_[index]->GetProcess()); 143 return GetMemCellText(phys_mem);
150 DCHECK(iter != metrics_map_.end());
151 base::ProcessMetrics* process_metrics = iter->second;
152 return GetMemCellText(GetPhysicalMemory(process_metrics));
153 } 144 }
154 145
155 std::wstring TaskManagerModel::GetResourceProcessId(int index) const { 146 std::wstring TaskManagerModel::GetResourceProcessId(int index) const {
156 DCHECK(index < ResourceCount()); 147 DCHECK(index < ResourceCount());
157 return IntToWString(base::GetProcId(resources_[index]->GetProcess())); 148 return IntToWString(base::GetProcId(resources_[index]->GetProcess()));
158 } 149 }
159 150
160 std::wstring TaskManagerModel::GetResourceStatsValue(int index, int col_id) 151 std::wstring TaskManagerModel::GetResourceStatsValue(int index, int col_id)
161 const { 152 const {
162 DCHECK(index < ResourceCount()); 153 DCHECK(index < ResourceCount());
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 } 264 }
274 265
275 case IDS_TASK_MANAGER_NET_COLUMN: 266 case IDS_TASK_MANAGER_NET_COLUMN:
276 return ValueCompare<int64>(GetNetworkUsage(resources_[row1]), 267 return ValueCompare<int64>(GetNetworkUsage(resources_[row1]),
277 GetNetworkUsage(resources_[row2])); 268 GetNetworkUsage(resources_[row2]));
278 269
279 case IDS_TASK_MANAGER_CPU_COLUMN: 270 case IDS_TASK_MANAGER_CPU_COLUMN:
280 return ValueCompare<int>(GetCPUUsage(resources_[row1]), 271 return ValueCompare<int>(GetCPUUsage(resources_[row1]),
281 GetCPUUsage(resources_[row2])); 272 GetCPUUsage(resources_[row2]));
282 273
283 case IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN: 274 case IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN: {
284 case IDS_TASK_MANAGER_SHARED_MEM_COLUMN: 275 size_t value1;
276 size_t value2;
277 if (!GetPrivateMemory(row1, &value1) || !GetPrivateMemory(row2, &value2))
278 return 0;
279 return ValueCompare<size_t>(value1, value2);
280 }
281
282 case IDS_TASK_MANAGER_SHARED_MEM_COLUMN: {
283 size_t value1;
284 size_t value2;
285 if (!GetSharedMemory(row1, &value1) || !GetSharedMemory(row2, &value2))
286 return 0;
287 return ValueCompare<size_t>(value1, value2);
288 }
289
285 case IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN: { 290 case IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN: {
286 base::ProcessMetrics* pm1; 291 size_t value1;
287 base::ProcessMetrics* pm2; 292 size_t value2;
288 if (!GetProcessMetricsForRows(row1, row2, &pm1, &pm2)) 293 if (!GetPhysicalMemory(row1, &value1) ||
294 !GetPhysicalMemory(row2, &value2))
289 return 0; 295 return 0;
290 if (col_id == IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN) { 296 return ValueCompare<size_t>(value1, value2);
291 return ValueCompare<size_t>(GetPrivateMemory(pm1),
292 GetPrivateMemory(pm2));
293 }
294 if (col_id == IDS_TASK_MANAGER_SHARED_MEM_COLUMN)
295 return ValueCompare<size_t>(GetSharedMemory(pm1), GetSharedMemory(pm2));
296 return ValueCompare<size_t>(GetPhysicalMemory(pm1),
297 GetPhysicalMemory(pm2));
298 } 297 }
299 298
300 case IDS_TASK_MANAGER_PROCESS_ID_COLUMN: { 299 case IDS_TASK_MANAGER_PROCESS_ID_COLUMN: {
301 int proc1_id = base::GetProcId(resources_[row1]->GetProcess()); 300 int proc1_id = base::GetProcId(resources_[row1]->GetProcess());
302 int proc2_id = base::GetProcId(resources_[row2]->GetProcess()); 301 int proc2_id = base::GetProcId(resources_[row2]->GetProcess());
303 return ValueCompare<int>(proc1_id, proc2_id); 302 return ValueCompare<int>(proc1_id, proc2_id);
304 } 303 }
305 304
306 case IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN: 305 case IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN:
307 case IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN: 306 case IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN:
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 } 350 }
352 351
353 int TaskManagerModel::GetCPUUsage(TaskManager::Resource* resource) const { 352 int TaskManagerModel::GetCPUUsage(TaskManager::Resource* resource) const {
354 CPUUsageMap::const_iterator iter = 353 CPUUsageMap::const_iterator iter =
355 cpu_usage_map_.find(resource->GetProcess()); 354 cpu_usage_map_.find(resource->GetProcess());
356 if (iter == cpu_usage_map_.end()) 355 if (iter == cpu_usage_map_.end())
357 return 0; 356 return 0;
358 return iter->second; 357 return iter->second;
359 } 358 }
360 359
361 size_t TaskManagerModel::GetPrivateMemory( 360 bool TaskManagerModel::GetPrivateMemory(int index, size_t* result) const {
362 const base::ProcessMetrics* process_metrics) const { 361 *result = 0;
363 return process_metrics->GetPrivateBytes() / 1024; 362 base::ProcessMetrics* process_metrics;
363 if (!GetProcessMetricsForRow(index, &process_metrics))
364 return false;
365 *result = process_metrics->GetPrivateBytes() / 1024;
366 // On Linux (so far) and win XP, this is not supported and returns 0.
367 // Remove with crbug.com/23258
368 if (*result == 0)
369 return false;
370 return true;
364 } 371 }
365 372
366 size_t TaskManagerModel::GetSharedMemory( 373 bool TaskManagerModel::GetSharedMemory(int index, size_t* result) const {
367 const base::ProcessMetrics* process_metrics) const { 374 *result = 0;
375 base::ProcessMetrics* process_metrics;
376 if (!GetProcessMetricsForRow(index, &process_metrics))
377 return false;
368 base::WorkingSetKBytes ws_usage; 378 base::WorkingSetKBytes ws_usage;
369 process_metrics->GetWorkingSetKBytes(&ws_usage); 379 if (!process_metrics->GetWorkingSetKBytes(&ws_usage))
370 return ws_usage.shared; 380 return false;
381 *result = ws_usage.shared;
382 return true;
371 } 383 }
372 384
373 size_t TaskManagerModel::GetPhysicalMemory( 385 bool TaskManagerModel::GetPhysicalMemory(int index, size_t* result) const {
374 const base::ProcessMetrics* process_metrics) const { 386 *result = 0;
387 base::ProcessMetrics* process_metrics;
388 if (!GetProcessMetricsForRow(index, &process_metrics))
389 return false;
390 base::WorkingSetKBytes ws_usage;
391 if (!process_metrics->GetWorkingSetKBytes(&ws_usage))
392 return false;
393
375 // Memory = working_set.private + working_set.shareable. 394 // Memory = working_set.private + working_set.shareable.
376 // We exclude the shared memory. 395 // We exclude the shared memory.
377 size_t total_kbytes = process_metrics->GetWorkingSetSize() / 1024; 396 size_t total_kbytes = process_metrics->GetWorkingSetSize() / 1024;
378 base::WorkingSetKBytes ws_usage;
379 process_metrics->GetWorkingSetKBytes(&ws_usage);
380 total_kbytes -= ws_usage.shared; 397 total_kbytes -= ws_usage.shared;
381 return total_kbytes; 398 *result = total_kbytes;
399 return true;
382 } 400 }
383 401
384 int TaskManagerModel::GetStatsValue(const TaskManager::Resource* resource, 402 int TaskManagerModel::GetStatsValue(const TaskManager::Resource* resource,
385 int col_id) const { 403 int col_id) const {
386 StatsTable* table = StatsTable::current(); 404 StatsTable* table = StatsTable::current();
387 if (table != NULL) { 405 if (table != NULL) {
388 const char* counter = table->GetRowName(col_id); 406 const char* counter = table->GetRowName(col_id);
389 if (counter != NULL && counter[0] != '\0') { 407 if (counter != NULL && counter[0] != '\0') {
390 return table->GetCounterValue(counter, 408 return table->GetCounterValue(counter,
391 base::GetProcId(resource->GetProcess())); 409 base::GetProcId(resource->GetProcess()));
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 chrome_browser_net::GetOriginProcessUniqueIDForRequest(job->request()); 764 chrome_browser_net::GetOriginProcessUniqueIDForRequest(job->request());
747 ui_loop_->PostTask(FROM_HERE, 765 ui_loop_->PostTask(FROM_HERE,
748 NewRunnableMethod( 766 NewRunnableMethod(
749 this, 767 this,
750 &TaskManagerModel::BytesRead, 768 &TaskManagerModel::BytesRead,
751 BytesReadParam(origin_child_id, 769 BytesReadParam(origin_child_id,
752 render_process_host_child_id, 770 render_process_host_child_id,
753 routing_id, byte_count))); 771 routing_id, byte_count)));
754 } 772 }
755 773
756 bool TaskManagerModel::GetProcessMetricsForRows( 774 bool TaskManagerModel::GetProcessMetricsForRow(
757 int row1, int row2, 775 int row, base::ProcessMetrics** proc_metrics) const {
758 base::ProcessMetrics** proc_metrics1, 776 DCHECK(row < ResourceCount());
759 base::ProcessMetrics** proc_metrics2) const { 777 *proc_metrics = NULL;
760 DCHECK(row1 < ResourceCount() && row2 < ResourceCount());
761 *proc_metrics1 = NULL;
762 *proc_metrics2 = NULL;
763 778
764 MetricsMap::const_iterator iter = 779 MetricsMap::const_iterator iter =
765 metrics_map_.find(resources_[row1]->GetProcess()); 780 metrics_map_.find(resources_[row]->GetProcess());
766 if (iter == metrics_map_.end()) 781 if (iter == metrics_map_.end())
767 return false; 782 return false;
768 *proc_metrics1 = iter->second; 783 *proc_metrics = iter->second;
769
770 iter = metrics_map_.find(resources_[row2]->GetProcess());
771 if (iter == metrics_map_.end())
772 return false;
773 *proc_metrics2 = iter->second;
774
775 return true; 784 return true;
776 } 785 }
777 786
778 //////////////////////////////////////////////////////////////////////////////// 787 ////////////////////////////////////////////////////////////////////////////////
779 // TaskManager class 788 // TaskManager class
780 //////////////////////////////////////////////////////////////////////////////// 789 ////////////////////////////////////////////////////////////////////////////////
781 790
782 // static 791 // static
783 void TaskManager::RegisterPrefs(PrefService* prefs) { 792 void TaskManager::RegisterPrefs(PrefService* prefs) {
784 prefs->RegisterDictionaryPref(prefs::kTaskManagerWindowPlacement); 793 prefs->RegisterDictionaryPref(prefs::kTaskManagerWindowPlacement);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 // or popup, we can only have one tab, hence we need to process this in a 859 // or popup, we can only have one tab, hence we need to process this in a
851 // tabbed browser window. Currently, |browser| is pointing to the application, 860 // tabbed browser window. Currently, |browser| is pointing to the application,
852 // popup window. Therefore, we have to retrieve the last active tab again, 861 // popup window. Therefore, we have to retrieve the last active tab again,
853 // since a new window has been used. 862 // since a new window has been used.
854 if (browser->type() & Browser::TYPE_APP_POPUP) { 863 if (browser->type() & Browser::TYPE_APP_POPUP) {
855 browser = BrowserList::GetLastActive(); 864 browser = BrowserList::GetLastActive();
856 DCHECK(browser); 865 DCHECK(browser);
857 } 866 }
858 browser->window()->Show(); 867 browser->window()->Show();
859 } 868 }
OLDNEW
« no previous file with comments | « chrome/browser/task_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698