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