| 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/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "chrome/browser/task_manager/guest_information.h" | 24 #include "chrome/browser/task_manager/guest_information.h" |
| 25 #include "chrome/browser/task_manager/panel_information.h" | 25 #include "chrome/browser/task_manager/panel_information.h" |
| 26 #include "chrome/browser/task_manager/printing_information.h" | 26 #include "chrome/browser/task_manager/printing_information.h" |
| 27 #include "chrome/browser/task_manager/resource_provider.h" | 27 #include "chrome/browser/task_manager/resource_provider.h" |
| 28 #include "chrome/browser/task_manager/tab_contents_information.h" | 28 #include "chrome/browser/task_manager/tab_contents_information.h" |
| 29 #include "chrome/browser/task_manager/web_contents_resource_provider.h" | 29 #include "chrome/browser/task_manager/web_contents_resource_provider.h" |
| 30 #include "chrome/browser/task_manager/worker_resource_provider.h" | 30 #include "chrome/browser/task_manager/worker_resource_provider.h" |
| 31 #include "chrome/browser/ui/browser_navigator.h" | 31 #include "chrome/browser/ui/browser_navigator.h" |
| 32 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
| 33 #include "chrome/common/url_constants.h" | 33 #include "chrome/common/url_constants.h" |
| 34 #include "components/nacl/browser/nacl_browser.h" |
| 34 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
| 35 #include "content/public/browser/gpu_data_manager.h" | 36 #include "content/public/browser/gpu_data_manager.h" |
| 36 #include "content/public/browser/gpu_data_manager_observer.h" | 37 #include "content/public/browser/gpu_data_manager_observer.h" |
| 37 #include "content/public/browser/resource_request_info.h" | 38 #include "content/public/browser/resource_request_info.h" |
| 38 #include "content/public/browser/web_contents.h" | 39 #include "content/public/browser/web_contents.h" |
| 39 #include "content/public/browser/web_contents_delegate.h" | 40 #include "content/public/browser/web_contents_delegate.h" |
| 40 #include "content/public/common/result_codes.h" | 41 #include "content/public/common/result_codes.h" |
| 41 #include "extensions/browser/extension_system.h" | 42 #include "extensions/browser/extension_system.h" |
| 42 #include "grit/generated_resources.h" | 43 #include "grit/generated_resources.h" |
| 43 #include "grit/ui_resources.h" | 44 #include "grit/ui_resources.h" |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 BrowserThread::PostTask( | 185 BrowserThread::PostTask( |
| 185 BrowserThread::UI, FROM_HERE, base::Bind( | 186 BrowserThread::UI, FROM_HERE, base::Bind( |
| 186 &TaskManagerModelGpuDataManagerObserver:: | 187 &TaskManagerModelGpuDataManagerObserver:: |
| 187 NotifyVideoMemoryUsageStats, | 188 NotifyVideoMemoryUsageStats, |
| 188 video_memory_usage_stats)); | 189 video_memory_usage_stats)); |
| 189 } | 190 } |
| 190 } | 191 } |
| 191 }; | 192 }; |
| 192 | 193 |
| 193 TaskManagerModel::PerResourceValues::PerResourceValues() | 194 TaskManagerModel::PerResourceValues::PerResourceValues() |
| 194 : is_nacl_debug_stub_port_valid(false), | 195 : is_title_valid(false), |
| 195 nacl_debug_stub_port(0), | |
| 196 is_title_valid(false), | |
| 197 is_profile_name_valid(false), | 196 is_profile_name_valid(false), |
| 198 network_usage(0), | 197 network_usage(0), |
| 199 is_process_id_valid(false), | 198 is_process_id_valid(false), |
| 200 process_id(0), | 199 process_id(0), |
| 201 is_goats_teleported_valid(false), | 200 is_goats_teleported_valid(false), |
| 202 goats_teleported(0), | 201 goats_teleported(0), |
| 203 is_webcore_stats_valid(false), | 202 is_webcore_stats_valid(false), |
| 204 is_fps_valid(false), | 203 is_fps_valid(false), |
| 205 fps(0), | 204 fps(0), |
| 206 is_sqlite_memory_bytes_valid(false), | 205 is_sqlite_memory_bytes_valid(false), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 222 is_physical_memory_valid(false), | 221 is_physical_memory_valid(false), |
| 223 physical_memory(0), | 222 physical_memory(0), |
| 224 is_video_memory_valid(false), | 223 is_video_memory_valid(false), |
| 225 video_memory(0), | 224 video_memory(0), |
| 226 video_memory_has_duplicates(false), | 225 video_memory_has_duplicates(false), |
| 227 is_gdi_handles_valid(false), | 226 is_gdi_handles_valid(false), |
| 228 gdi_handles(0), | 227 gdi_handles(0), |
| 229 gdi_handles_peak(0), | 228 gdi_handles_peak(0), |
| 230 is_user_handles_valid(0), | 229 is_user_handles_valid(0), |
| 231 user_handles(0), | 230 user_handles(0), |
| 232 user_handles_peak(0) {} | 231 user_handles_peak(0), |
| 232 is_nacl_debug_stub_port_valid(false), |
| 233 nacl_debug_stub_port(0) {} |
| 233 | 234 |
| 234 TaskManagerModel::PerProcessValues::~PerProcessValues() {} | 235 TaskManagerModel::PerProcessValues::~PerProcessValues() {} |
| 235 | 236 |
| 236 //////////////////////////////////////////////////////////////////////////////// | 237 //////////////////////////////////////////////////////////////////////////////// |
| 237 // TaskManagerModel class | 238 // TaskManagerModel class |
| 238 //////////////////////////////////////////////////////////////////////////////// | 239 //////////////////////////////////////////////////////////////////////////////// |
| 239 | 240 |
| 240 TaskManagerModel::TaskManagerModel(TaskManager* task_manager) | 241 TaskManagerModel::TaskManagerModel(TaskManager* task_manager) |
| 241 : pending_video_memory_usage_stats_update_(false), | 242 : pending_video_memory_usage_stats_update_(false), |
| 242 update_requests_(0), | 243 update_requests_(0), |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 | 286 |
| 286 int TaskManagerModel::ResourceCount() const { | 287 int TaskManagerModel::ResourceCount() const { |
| 287 return resources_.size(); | 288 return resources_.size(); |
| 288 } | 289 } |
| 289 | 290 |
| 290 int TaskManagerModel::GroupCount() const { | 291 int TaskManagerModel::GroupCount() const { |
| 291 return group_map_.size(); | 292 return group_map_.size(); |
| 292 } | 293 } |
| 293 | 294 |
| 294 int TaskManagerModel::GetNaClDebugStubPort(int index) const { | 295 int TaskManagerModel::GetNaClDebugStubPort(int index) const { |
| 295 PerResourceValues& values(GetPerResourceValues(index)); | 296 base::ProcessHandle handle = GetResource(index)->GetProcess(); |
| 297 PerProcessValues& values(per_process_cache_[handle]); |
| 296 if (!values.is_nacl_debug_stub_port_valid) { | 298 if (!values.is_nacl_debug_stub_port_valid) { |
| 297 values.is_nacl_debug_stub_port_valid = true; | 299 return nacl::kGdbDebugStubPortUnknown; |
| 298 values.nacl_debug_stub_port = GetResource(index)->GetNaClDebugStubPort(); | |
| 299 } | 300 } |
| 300 return values.nacl_debug_stub_port; | 301 return values.nacl_debug_stub_port; |
| 301 } | 302 } |
| 302 | 303 |
| 303 int64 TaskManagerModel::GetNetworkUsage(int index) const { | 304 int64 TaskManagerModel::GetNetworkUsage(int index) const { |
| 304 return GetNetworkUsage(GetResource(index)); | 305 return GetNetworkUsage(GetResource(index)); |
| 305 } | 306 } |
| 306 | 307 |
| 307 double TaskManagerModel::GetCPUUsage(int index) const { | 308 double TaskManagerModel::GetCPUUsage(int index) const { |
| 308 return GetCPUUsage(GetResource(index)); | 309 return GetCPUUsage(GetResource(index)); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 PerResourceValues& values(GetPerResourceValues(index)); | 411 PerResourceValues& values(GetPerResourceValues(index)); |
| 411 if (!values.is_profile_name_valid) { | 412 if (!values.is_profile_name_valid) { |
| 412 values.is_profile_name_valid = true; | 413 values.is_profile_name_valid = true; |
| 413 values.profile_name = GetResource(index)->GetProfileName(); | 414 values.profile_name = GetResource(index)->GetProfileName(); |
| 414 } | 415 } |
| 415 return values.profile_name; | 416 return values.profile_name; |
| 416 } | 417 } |
| 417 | 418 |
| 418 base::string16 TaskManagerModel::GetResourceNaClDebugStubPort(int index) const { | 419 base::string16 TaskManagerModel::GetResourceNaClDebugStubPort(int index) const { |
| 419 int port = GetNaClDebugStubPort(index); | 420 int port = GetNaClDebugStubPort(index); |
| 420 if (port == 0) { | 421 if (port == nacl::kGdbDebugStubPortUnknown) { |
| 422 return base::ASCIIToUTF16("Unknown"); |
| 423 } else if (port == nacl::kGdbDebugStubPortUnused) { |
| 421 return base::ASCIIToUTF16("N/A"); | 424 return base::ASCIIToUTF16("N/A"); |
| 422 } else { | 425 } else { |
| 423 return base::IntToString16(port); | 426 return base::IntToString16(port); |
| 424 } | 427 } |
| 425 } | 428 } |
| 426 | 429 |
| 427 base::string16 TaskManagerModel::GetResourceNetworkUsage(int index) const { | 430 base::string16 TaskManagerModel::GetResourceNetworkUsage(int index) const { |
| 428 int64 net_usage = GetNetworkUsage(index); | 431 int64 net_usage = GetNetworkUsage(index); |
| 429 if (net_usage == -1) | 432 if (net_usage == -1) |
| 430 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT); | 433 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT); |
| (...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1172 // Notify the table that the contents have changed for it to redraw. | 1175 // Notify the table that the contents have changed for it to redraw. |
| 1173 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, OnModelChanged()); | 1176 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, OnModelChanged()); |
| 1174 } | 1177 } |
| 1175 | 1178 |
| 1176 void TaskManagerModel::Refresh() { | 1179 void TaskManagerModel::Refresh() { |
| 1177 goat_salt_ = base::RandUint64(); | 1180 goat_salt_ = base::RandUint64(); |
| 1178 | 1181 |
| 1179 per_resource_cache_.clear(); | 1182 per_resource_cache_.clear(); |
| 1180 per_process_cache_.clear(); | 1183 per_process_cache_.clear(); |
| 1181 | 1184 |
| 1182 // Compute the CPU usage values. | 1185 #if !defined(DISABLE_NACL) |
| 1186 nacl::NaClBrowser* nacl_browser = nacl::NaClBrowser::GetInstance(); |
| 1187 #endif // !defined(DISABLE_NACL) |
| 1188 |
| 1189 // Compute the CPU usage values and check if NaCl GDB debug stub port is |
| 1190 // known. |
| 1183 // Note that we compute the CPU usage for all resources (instead of doing it | 1191 // Note that we compute the CPU usage for all resources (instead of doing it |
| 1184 // lazily) as process_util::GetCPUUsage() returns the CPU usage since the last | 1192 // lazily) as process_util::GetCPUUsage() returns the CPU usage since the last |
| 1185 // time it was called, and not calling it everytime would skew the value the | 1193 // time it was called, and not calling it everytime would skew the value the |
| 1186 // next time it is retrieved (as it would be for more than 1 cycle). | 1194 // next time it is retrieved (as it would be for more than 1 cycle). |
| 1187 // The same is true for idle wakeups. | 1195 // The same is true for idle wakeups. |
| 1188 for (ResourceList::iterator iter = resources_.begin(); | 1196 for (ResourceList::iterator iter = resources_.begin(); |
| 1189 iter != resources_.end(); ++iter) { | 1197 iter != resources_.end(); ++iter) { |
| 1190 base::ProcessHandle process = (*iter)->GetProcess(); | 1198 base::ProcessHandle process = (*iter)->GetProcess(); |
| 1191 PerProcessValues& values(per_process_cache_[process]); | 1199 PerProcessValues& values(per_process_cache_[process]); |
| 1200 #if !defined(DISABLE_NACL) |
| 1201 // Debug stub port doesn't change once known. |
| 1202 if (!values.is_nacl_debug_stub_port_valid) { |
| 1203 values.nacl_debug_stub_port = nacl_browser->GetProcessGdbDebugStubPort( |
| 1204 (*iter)->GetUniqueChildProcessId()); |
| 1205 if (values.nacl_debug_stub_port != nacl::kGdbDebugStubPortUnknown) { |
| 1206 values.is_nacl_debug_stub_port_valid = true; |
| 1207 } |
| 1208 } |
| 1209 #endif // !defined(DISABLE_NACL) |
| 1192 if (values.is_cpu_usage_valid && values.is_idle_wakeups_valid) | 1210 if (values.is_cpu_usage_valid && values.is_idle_wakeups_valid) |
| 1193 continue; | 1211 continue; |
| 1194 MetricsMap::iterator metrics_iter = metrics_map_.find(process); | 1212 MetricsMap::iterator metrics_iter = metrics_map_.find(process); |
| 1195 DCHECK(metrics_iter != metrics_map_.end()); | 1213 DCHECK(metrics_iter != metrics_map_.end()); |
| 1196 if (!values.is_cpu_usage_valid) { | 1214 if (!values.is_cpu_usage_valid) { |
| 1197 values.is_cpu_usage_valid = true; | 1215 values.is_cpu_usage_valid = true; |
| 1198 values.cpu_usage = metrics_iter->second->GetCPUUsage(); | 1216 values.cpu_usage = metrics_iter->second->GetCPUUsage(); |
| 1199 } | 1217 } |
| 1200 #if defined(OS_MACOSX) | 1218 #if defined(OS_MACOSX) |
| 1201 // TODO: Implement GetIdleWakeupsPerSecond() on other platforms, | 1219 // TODO: Implement GetIdleWakeupsPerSecond() on other platforms, |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1581 params.host_desktop_type = desktop_type; | 1599 params.host_desktop_type = desktop_type; |
| 1582 chrome::Navigate(¶ms); | 1600 chrome::Navigate(¶ms); |
| 1583 } | 1601 } |
| 1584 | 1602 |
| 1585 TaskManager::TaskManager() | 1603 TaskManager::TaskManager() |
| 1586 : model_(new TaskManagerModel(this)) { | 1604 : model_(new TaskManagerModel(this)) { |
| 1587 } | 1605 } |
| 1588 | 1606 |
| 1589 TaskManager::~TaskManager() { | 1607 TaskManager::~TaskManager() { |
| 1590 } | 1608 } |
| OLD | NEW |