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

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

Issue 1181263005: Make task manager memory data more efficient and meaningful. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adjust high threshold so it works with Dr Memory. Created 5 years, 5 months 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
« no previous file with comments | « chrome/browser/task_manager/task_manager.h ('k') | chrome/chrome_browser.gypi » ('j') | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/task_manager.h" 5 #include "chrome/browser/task_manager/task_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/i18n/number_formatting.h" 8 #include "base/i18n/number_formatting.h"
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/prefs/pref_registry_simple.h" 11 #include "base/prefs/pref_registry_simple.h"
12 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
13 #include "base/process/process_metrics.h"
14 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
15 #include "base/stl_util.h" 14 #include "base/stl_util.h"
16 #include "base/strings/string16.h" 15 #include "base/strings/string16.h"
17 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
19 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
20 #include "base/thread_task_runner_handle.h" 19 #include "base/thread_task_runner_handle.h"
21 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
21 #include "chrome/browser/private_working_set_snapshot.h"
22 #include "chrome/browser/profiles/profile_manager.h" 22 #include "chrome/browser/profiles/profile_manager.h"
23 #include "chrome/browser/profiles/profile_window.h" 23 #include "chrome/browser/profiles/profile_window.h"
24 #include "chrome/browser/task_manager/background_information.h" 24 #include "chrome/browser/task_manager/background_information.h"
25 #include "chrome/browser/task_manager/browser_process_resource_provider.h" 25 #include "chrome/browser/task_manager/browser_process_resource_provider.h"
26 #include "chrome/browser/task_manager/child_process_resource_provider.h" 26 #include "chrome/browser/task_manager/child_process_resource_provider.h"
27 #include "chrome/browser/task_manager/extension_information.h" 27 #include "chrome/browser/task_manager/extension_information.h"
28 #include "chrome/browser/task_manager/guest_information.h" 28 #include "chrome/browser/task_manager/guest_information.h"
29 #include "chrome/browser/task_manager/panel_information.h" 29 #include "chrome/browser/task_manager/panel_information.h"
30 #include "chrome/browser/task_manager/printing_information.h" 30 #include "chrome/browser/task_manager/printing_information.h"
31 #include "chrome/browser/task_manager/resource_provider.h" 31 #include "chrome/browser/task_manager/resource_provider.h"
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 AddResourceProvider( 267 AddResourceProvider(
268 new task_manager::ChildProcessResourceProvider(task_manager)); 268 new task_manager::ChildProcessResourceProvider(task_manager));
269 AddResourceProvider(new task_manager::WebContentsResourceProvider( 269 AddResourceProvider(new task_manager::WebContentsResourceProvider(
270 task_manager, 270 task_manager,
271 scoped_ptr<WebContentsInformation>( 271 scoped_ptr<WebContentsInformation>(
272 new task_manager::ExtensionInformation()))); 272 new task_manager::ExtensionInformation())));
273 AddResourceProvider(new task_manager::WebContentsResourceProvider( 273 AddResourceProvider(new task_manager::WebContentsResourceProvider(
274 task_manager, 274 task_manager,
275 scoped_ptr<WebContentsInformation>( 275 scoped_ptr<WebContentsInformation>(
276 new task_manager::GuestInformation()))); 276 new task_manager::GuestInformation())));
277 #if defined(OS_WIN)
278 working_set_snapshot_.reset(new PrivateWorkingSetSnapshot);
279 working_set_snapshot_->AddToMonitorList("chrome");
280 working_set_snapshot_->AddToMonitorList("nacl64");
281 #endif
277 } 282 }
278 283
279 void TaskManagerModel::AddObserver(TaskManagerModelObserver* observer) { 284 void TaskManagerModel::AddObserver(TaskManagerModelObserver* observer) {
280 observer_list_.AddObserver(observer); 285 observer_list_.AddObserver(observer);
281 } 286 }
282 287
283 void TaskManagerModel::RemoveObserver(TaskManagerModelObserver* observer) { 288 void TaskManagerModel::RemoveObserver(TaskManagerModelObserver* observer) {
284 observer_list_.RemoveObserver(observer); 289 observer_list_.RemoveObserver(observer);
285 } 290 }
286 291
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 MetricsMap::const_iterator iter = metrics_map_.find(handle); 576 MetricsMap::const_iterator iter = metrics_map_.find(handle);
572 if (iter == metrics_map_.end() || 577 if (iter == metrics_map_.end() ||
573 !iter->second->GetWorkingSetKBytes(&ws_usage)) 578 !iter->second->GetWorkingSetKBytes(&ws_usage))
574 return false; 579 return false;
575 580
576 values.is_physical_memory_valid = true; 581 values.is_physical_memory_valid = true;
577 #if defined(OS_LINUX) 582 #if defined(OS_LINUX)
578 // On Linux private memory is also resident. Just use it. 583 // On Linux private memory is also resident. Just use it.
579 values.physical_memory = ws_usage.priv * 1024; 584 values.physical_memory = ws_usage.priv * 1024;
580 #else 585 #else
581 // Memory = working_set.private + working_set.shareable. 586 // Memory = working_set.private which is working set minus shareable. This
582 // We exclude the shared memory. 587 // avoids the unpredictable counting that occurs when calculating memory as
588 // working set minus shared (renderer code counted when one tab is open and
589 // not counted when two or more are open) and it is much more efficient to
590 // calculate on Windows.
583 values.physical_memory = iter->second->GetWorkingSetSize(); 591 values.physical_memory = iter->second->GetWorkingSetSize();
584 values.physical_memory -= ws_usage.shared * 1024; 592 values.physical_memory -= ws_usage.shareable * 1024;
585 #endif 593 #endif
586 } 594 }
587 *result = values.physical_memory; 595 *result = values.physical_memory;
588 return true; 596 return true;
589 } 597 }
590 598
591 void TaskManagerModel::GetGDIHandles(int index, 599 void TaskManagerModel::GetGDIHandles(int index,
592 size_t* current, 600 size_t* current,
593 size_t* peak) const { 601 size_t* peak) const {
594 *current = 0; 602 *current = 0;
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
1116 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, 1124 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_,
1117 OnItemsRemoved(0, size)); 1125 OnItemsRemoved(0, size));
1118 } 1126 }
1119 } 1127 }
1120 1128
1121 void TaskManagerModel::ModelChanged() { 1129 void TaskManagerModel::ModelChanged() {
1122 // Notify the table that the contents have changed for it to redraw. 1130 // Notify the table that the contents have changed for it to redraw.
1123 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, OnModelChanged()); 1131 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, OnModelChanged());
1124 } 1132 }
1125 1133
1134 void TaskManagerModel::RefreshPhysicalMemoryFromWorkingSetSnapshot() {
1135 #if defined(OS_WIN)
1136 // Collect working-set data for all monitored processes in one operation, to
1137 // avoid the inefficiency of retrieving it one at a time.
1138 working_set_snapshot_->Sample();
1139
1140 for (size_t i = 0; i < resources_.size(); ++i) {
1141 size_t private_working_set =
1142 working_set_snapshot_->GetPrivateWorkingSet(GetProcessId(i));
1143
1144 // If working-set data is available then use it. If not then
1145 // GetWorkingSetKBytes will retrieve the data. This is rare except on
1146 // Windows XP where GetWorkingSetKBytes will always be used.
1147 if (private_working_set) {
1148 // Fill in the cache with the retrieved private working set value.
1149 base::ProcessHandle handle = GetResource(i)->GetProcess();
1150 PerProcessValues& values(per_process_cache_[handle]);
1151 values.is_physical_memory_valid = true;
1152 // Note that the other memory fields are *not* filled in.
1153 values.physical_memory = private_working_set;
1154 }
1155 }
1156 #else
1157 // This is a NOP on other platforms because they can efficiently retrieve
1158 // the private working-set data on a per-process basis.
1159 #endif
1160 }
1161
1126 void TaskManagerModel::Refresh() { 1162 void TaskManagerModel::Refresh() {
1127 per_resource_cache_.clear(); 1163 per_resource_cache_.clear();
1128 per_process_cache_.clear(); 1164 per_process_cache_.clear();
1165 RefreshPhysicalMemoryFromWorkingSetSnapshot();
1129 1166
1130 #if !defined(DISABLE_NACL) 1167 #if !defined(DISABLE_NACL)
1131 nacl::NaClBrowser* nacl_browser = nacl::NaClBrowser::GetInstance(); 1168 nacl::NaClBrowser* nacl_browser = nacl::NaClBrowser::GetInstance();
1132 #endif // !defined(DISABLE_NACL) 1169 #endif // !defined(DISABLE_NACL)
1133 1170
1134 // Compute the CPU usage values and check if NaCl GDB debug stub port is 1171 // Compute the CPU usage values and check if NaCl GDB debug stub port is
1135 // known. 1172 // known.
1136 // Note that we compute the CPU usage for all resources (instead of doing it 1173 // Note that we compute the CPU usage for all resources (instead of doing it
1137 // lazily) as process_util::GetCPUUsage() returns the CPU usage since the last 1174 // lazily) as process_util::GetCPUUsage() returns the CPU usage since the last
1138 // time it was called, and not calling it everytime would skew the value the 1175 // time it was called, and not calling it everytime would skew the value the
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
1525 params.host_desktop_type = desktop_type; 1562 params.host_desktop_type = desktop_type;
1526 chrome::Navigate(&params); 1563 chrome::Navigate(&params);
1527 } 1564 }
1528 1565
1529 TaskManager::TaskManager() 1566 TaskManager::TaskManager()
1530 : model_(new TaskManagerModel(this)) { 1567 : model_(new TaskManagerModel(this)) {
1531 } 1568 }
1532 1569
1533 TaskManager::~TaskManager() { 1570 TaskManager::~TaskManager() {
1534 } 1571 }
OLDNEW
« no previous file with comments | « chrome/browser/task_manager/task_manager.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698