OLD | NEW |
---|---|
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" | 13 #include "base/process/private_working_set_snapshot.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
20 #include "base/thread_task_runner_handle.h" | 20 #include "base/thread_task_runner_handle.h" |
21 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.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" |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 base::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 Loading... | |
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 Loading... | |
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::PopulateCache() { | |
ncarter (slow)
2015/06/26 21:46:16
Add a comment here (or at the bottom of the functi
brucedawson
2015/06/27 00:13:06
Done.
| |
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 rIndex = 0; rIndex < resources_.size(); ++rIndex) { | |
ncarter (slow)
2015/06/26 21:46:16
"i", "index", "resource", or "resource_index", but
brucedawson
2015/06/27 00:13:06
Done.
| |
1141 size_t privateWS = working_set_snapshot_->GetPrivateWorkingSet( | |
ncarter (slow)
2015/06/26 21:46:17
private_working_set
brucedawson
2015/06/27 00:13:06
Done.
| |
1142 GetProcessId(rIndex)); | |
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 (privateWS) { | |
1148 // Fill in the cache with the retrieved private working set value. | |
1149 base::ProcessHandle handle = GetResource(rIndex)->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 = privateWS; | |
1154 } | |
1155 } | |
1156 #endif | |
1157 } | |
1158 | |
1126 void TaskManagerModel::Refresh() { | 1159 void TaskManagerModel::Refresh() { |
1127 per_resource_cache_.clear(); | 1160 per_resource_cache_.clear(); |
1128 per_process_cache_.clear(); | 1161 per_process_cache_.clear(); |
1162 PopulateCache(); | |
ncarter (slow)
2015/06/26 21:46:16
Maybe: RefreshPhysicalMemoryFromWorkingSetSnapshot
brucedawson
2015/06/27 00:13:06
Done.
| |
1129 | 1163 |
1130 #if !defined(DISABLE_NACL) | 1164 #if !defined(DISABLE_NACL) |
1131 nacl::NaClBrowser* nacl_browser = nacl::NaClBrowser::GetInstance(); | 1165 nacl::NaClBrowser* nacl_browser = nacl::NaClBrowser::GetInstance(); |
1132 #endif // !defined(DISABLE_NACL) | 1166 #endif // !defined(DISABLE_NACL) |
1133 | 1167 |
1134 // Compute the CPU usage values and check if NaCl GDB debug stub port is | 1168 // Compute the CPU usage values and check if NaCl GDB debug stub port is |
1135 // known. | 1169 // known. |
1136 // Note that we compute the CPU usage for all resources (instead of doing it | 1170 // 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 | 1171 // 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 | 1172 // 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 Loading... | |
1525 params.host_desktop_type = desktop_type; | 1559 params.host_desktop_type = desktop_type; |
1526 chrome::Navigate(¶ms); | 1560 chrome::Navigate(¶ms); |
1527 } | 1561 } |
1528 | 1562 |
1529 TaskManager::TaskManager() | 1563 TaskManager::TaskManager() |
1530 : model_(new TaskManagerModel(this)) { | 1564 : model_(new TaskManagerModel(this)) { |
1531 } | 1565 } |
1532 | 1566 |
1533 TaskManager::~TaskManager() { | 1567 TaskManager::~TaskManager() { |
1534 } | 1568 } |
OLD | NEW |