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" |
11 #include "base/process/process_metrics.h" | 11 #include "base/process/process_metrics.h" |
12 #include "base/rand_util.h" | |
13 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
14 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
15 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
16 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
17 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
18 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
19 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
20 #include "chrome/browser/task_manager/background_information.h" | 19 #include "chrome/browser/task_manager/background_information.h" |
21 #include "chrome/browser/task_manager/browser_process_resource_provider.h" | 20 #include "chrome/browser/task_manager/browser_process_resource_provider.h" |
22 #include "chrome/browser/task_manager/child_process_resource_provider.h" | 21 #include "chrome/browser/task_manager/child_process_resource_provider.h" |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 } | 189 } |
191 } | 190 } |
192 }; | 191 }; |
193 | 192 |
194 TaskManagerModel::PerResourceValues::PerResourceValues() | 193 TaskManagerModel::PerResourceValues::PerResourceValues() |
195 : is_title_valid(false), | 194 : is_title_valid(false), |
196 is_profile_name_valid(false), | 195 is_profile_name_valid(false), |
197 network_usage(0), | 196 network_usage(0), |
198 is_process_id_valid(false), | 197 is_process_id_valid(false), |
199 process_id(0), | 198 process_id(0), |
200 is_goats_teleported_valid(false), | |
201 goats_teleported(0), | |
202 is_webcore_stats_valid(false), | 199 is_webcore_stats_valid(false), |
203 is_sqlite_memory_bytes_valid(false), | 200 is_sqlite_memory_bytes_valid(false), |
204 sqlite_memory_bytes(0), | 201 sqlite_memory_bytes(0), |
205 is_v8_memory_valid(false), | 202 is_v8_memory_valid(false), |
206 v8_memory_allocated(0), | 203 v8_memory_allocated(0), |
207 v8_memory_used(0) {} | 204 v8_memory_used(0) {} |
208 | 205 |
209 TaskManagerModel::PerResourceValues::~PerResourceValues() {} | 206 TaskManagerModel::PerResourceValues::~PerResourceValues() {} |
210 | 207 |
211 TaskManagerModel::PerProcessValues::PerProcessValues() | 208 TaskManagerModel::PerProcessValues::PerProcessValues() |
(...skipping 22 matching lines...) Expand all Loading... |
234 | 231 |
235 //////////////////////////////////////////////////////////////////////////////// | 232 //////////////////////////////////////////////////////////////////////////////// |
236 // TaskManagerModel class | 233 // TaskManagerModel class |
237 //////////////////////////////////////////////////////////////////////////////// | 234 //////////////////////////////////////////////////////////////////////////////// |
238 | 235 |
239 TaskManagerModel::TaskManagerModel(TaskManager* task_manager) | 236 TaskManagerModel::TaskManagerModel(TaskManager* task_manager) |
240 : pending_video_memory_usage_stats_update_(false), | 237 : pending_video_memory_usage_stats_update_(false), |
241 update_requests_(0), | 238 update_requests_(0), |
242 listen_requests_(0), | 239 listen_requests_(0), |
243 update_state_(IDLE), | 240 update_state_(IDLE), |
244 is_updating_byte_count_(false), | 241 is_updating_byte_count_(false) { |
245 goat_salt_(base::RandUint64()) { | |
246 AddResourceProvider( | 242 AddResourceProvider( |
247 new task_manager::BrowserProcessResourceProvider(task_manager)); | 243 new task_manager::BrowserProcessResourceProvider(task_manager)); |
248 AddResourceProvider(new task_manager::WebContentsResourceProvider( | 244 AddResourceProvider(new task_manager::WebContentsResourceProvider( |
249 task_manager, | 245 task_manager, |
250 scoped_ptr<WebContentsInformation>( | 246 scoped_ptr<WebContentsInformation>( |
251 new task_manager::BackgroundInformation()))); | 247 new task_manager::BackgroundInformation()))); |
252 AddResourceProvider(new task_manager::WebContentsResourceProvider( | 248 AddResourceProvider(new task_manager::WebContentsResourceProvider( |
253 task_manager, | 249 task_manager, |
254 scoped_ptr<WebContentsInformation>( | 250 scoped_ptr<WebContentsInformation>( |
255 new task_manager::TabContentsInformation()))); | 251 new task_manager::TabContentsInformation()))); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 | 352 |
357 case IDS_TASK_MANAGER_GDI_HANDLES_COLUMN: | 353 case IDS_TASK_MANAGER_GDI_HANDLES_COLUMN: |
358 return GetResourceGDIHandles(index); | 354 return GetResourceGDIHandles(index); |
359 | 355 |
360 case IDS_TASK_MANAGER_USER_HANDLES_COLUMN: | 356 case IDS_TASK_MANAGER_USER_HANDLES_COLUMN: |
361 return GetResourceUSERHandles(index); | 357 return GetResourceUSERHandles(index); |
362 | 358 |
363 case IDS_TASK_MANAGER_IDLE_WAKEUPS_COLUMN: | 359 case IDS_TASK_MANAGER_IDLE_WAKEUPS_COLUMN: |
364 return GetResourceIdleWakeupsPerSecond(index); | 360 return GetResourceIdleWakeupsPerSecond(index); |
365 | 361 |
366 case IDS_TASK_MANAGER_GOATS_TELEPORTED_COLUMN: | |
367 return GetResourceGoatsTeleported(index); | |
368 | |
369 case IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN: | 362 case IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN: |
370 return GetResourceWebCoreImageCacheSize(index); | 363 return GetResourceWebCoreImageCacheSize(index); |
371 | 364 |
372 case IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN: | 365 case IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN: |
373 return GetResourceWebCoreScriptsCacheSize(index); | 366 return GetResourceWebCoreScriptsCacheSize(index); |
374 | 367 |
375 case IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN: | 368 case IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN: |
376 return GetResourceWebCoreCSSCacheSize(index); | 369 return GetResourceWebCoreCSSCacheSize(index); |
377 | 370 |
378 case IDS_TASK_MANAGER_VIDEO_MEMORY_COLUMN: | 371 case IDS_TASK_MANAGER_VIDEO_MEMORY_COLUMN: |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 if (!GetSqliteMemoryUsedBytes(index, &bytes)) | 515 if (!GetSqliteMemoryUsedBytes(index, &bytes)) |
523 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT); | 516 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT); |
524 return GetMemCellText(bytes); | 517 return GetMemCellText(bytes); |
525 } | 518 } |
526 | 519 |
527 base::string16 TaskManagerModel::GetResourceIdleWakeupsPerSecond(int index) | 520 base::string16 TaskManagerModel::GetResourceIdleWakeupsPerSecond(int index) |
528 const { | 521 const { |
529 return base::FormatNumber(GetIdleWakeupsPerSecond(GetResource(index))); | 522 return base::FormatNumber(GetIdleWakeupsPerSecond(GetResource(index))); |
530 } | 523 } |
531 | 524 |
532 base::string16 TaskManagerModel::GetResourceGoatsTeleported(int index) const { | |
533 CHECK_LT(index, ResourceCount()); | |
534 return base::FormatNumber(GetGoatsTeleported(index)); | |
535 } | |
536 | |
537 base::string16 TaskManagerModel::GetResourceV8MemoryAllocatedSize( | 525 base::string16 TaskManagerModel::GetResourceV8MemoryAllocatedSize( |
538 int index) const { | 526 int index) const { |
539 size_t memory_allocated = 0, memory_used = 0; | 527 size_t memory_allocated = 0, memory_used = 0; |
540 if (!GetV8MemoryUsed(index, &memory_used) || | 528 if (!GetV8MemoryUsed(index, &memory_used) || |
541 !GetV8Memory(index, &memory_allocated)) | 529 !GetV8Memory(index, &memory_allocated)) |
542 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT); | 530 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT); |
543 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_CACHE_SIZE_CELL_TEXT, | 531 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_CACHE_SIZE_CELL_TEXT, |
544 ui::FormatBytesWithUnits(memory_allocated, | 532 ui::FormatBytesWithUnits(memory_allocated, |
545 ui::DATA_UNITS_KIBIBYTE, | 533 ui::DATA_UNITS_KIBIBYTE, |
546 false), | 534 false), |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 return false; | 684 return false; |
697 *result = GetPerResourceValues(index).v8_memory_used; | 685 *result = GetPerResourceValues(index).v8_memory_used; |
698 return true; | 686 return true; |
699 } | 687 } |
700 | 688 |
701 bool TaskManagerModel::CanActivate(int index) const { | 689 bool TaskManagerModel::CanActivate(int index) const { |
702 CHECK_LT(index, ResourceCount()); | 690 CHECK_LT(index, ResourceCount()); |
703 return GetResourceWebContents(index) != NULL; | 691 return GetResourceWebContents(index) != NULL; |
704 } | 692 } |
705 | 693 |
706 int TaskManagerModel::GetGoatsTeleported(int index) const { | |
707 PerResourceValues& values(GetPerResourceValues(index)); | |
708 if (!values.is_goats_teleported_valid) { | |
709 values.is_goats_teleported_valid = true; | |
710 values.goats_teleported = goat_salt_ * (index + 1); | |
711 values.goats_teleported = (values.goats_teleported >> 16) & 255; | |
712 } | |
713 return values.goats_teleported; | |
714 } | |
715 | |
716 bool TaskManagerModel::IsResourceFirstInGroup(int index) const { | 694 bool TaskManagerModel::IsResourceFirstInGroup(int index) const { |
717 Resource* resource = GetResource(index); | 695 Resource* resource = GetResource(index); |
718 GroupMap::const_iterator iter = group_map_.find(resource->GetProcess()); | 696 GroupMap::const_iterator iter = group_map_.find(resource->GetProcess()); |
719 DCHECK(iter != group_map_.end()); | 697 DCHECK(iter != group_map_.end()); |
720 const ResourceList& group = iter->second; | 698 const ResourceList& group = iter->second; |
721 return (group[0] == resource); | 699 return (group[0] == resource); |
722 } | 700 } |
723 | 701 |
724 bool TaskManagerModel::IsResourceLastInGroup(int index) const { | 702 bool TaskManagerModel::IsResourceLastInGroup(int index) const { |
725 Resource* resource = GetResource(index); | 703 Resource* resource = GetResource(index); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
900 case IDS_TASK_MANAGER_VIDEO_MEMORY_COLUMN: { | 878 case IDS_TASK_MANAGER_VIDEO_MEMORY_COLUMN: { |
901 size_t value1; | 879 size_t value1; |
902 size_t value2; | 880 size_t value2; |
903 bool has_duplicates; | 881 bool has_duplicates; |
904 bool value1_valid = GetVideoMemory(row1, &value1, &has_duplicates); | 882 bool value1_valid = GetVideoMemory(row1, &value1, &has_duplicates); |
905 bool value2_valid = GetVideoMemory(row2, &value2, &has_duplicates); | 883 bool value2_valid = GetVideoMemory(row2, &value2, &has_duplicates); |
906 return value1_valid && value2_valid ? ValueCompare(value1, value2) : | 884 return value1_valid && value2_valid ? ValueCompare(value1, value2) : |
907 OrderUnavailableValue(value1_valid, value2_valid); | 885 OrderUnavailableValue(value1_valid, value2_valid); |
908 } | 886 } |
909 | 887 |
910 case IDS_TASK_MANAGER_GOATS_TELEPORTED_COLUMN: | |
911 return ValueCompare(GetGoatsTeleported(row1), GetGoatsTeleported(row2)); | |
912 | |
913 case IDS_TASK_MANAGER_JAVASCRIPT_MEMORY_ALLOCATED_COLUMN: | 888 case IDS_TASK_MANAGER_JAVASCRIPT_MEMORY_ALLOCATED_COLUMN: |
914 return ValueCompareMember( | 889 return ValueCompareMember( |
915 this, &TaskManagerModel::GetV8Memory, row1, row2); | 890 this, &TaskManagerModel::GetV8Memory, row1, row2); |
916 | 891 |
917 case IDS_TASK_MANAGER_SQLITE_MEMORY_USED_COLUMN: | 892 case IDS_TASK_MANAGER_SQLITE_MEMORY_USED_COLUMN: |
918 return ValueCompareMember( | 893 return ValueCompareMember( |
919 this, &TaskManagerModel::GetSqliteMemoryUsedBytes, row1, row2); | 894 this, &TaskManagerModel::GetSqliteMemoryUsedBytes, row1, row2); |
920 | 895 |
921 default: | 896 default: |
922 NOTREACHED(); | 897 NOTREACHED(); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1138 OnItemsRemoved(0, size)); | 1113 OnItemsRemoved(0, size)); |
1139 } | 1114 } |
1140 } | 1115 } |
1141 | 1116 |
1142 void TaskManagerModel::ModelChanged() { | 1117 void TaskManagerModel::ModelChanged() { |
1143 // Notify the table that the contents have changed for it to redraw. | 1118 // Notify the table that the contents have changed for it to redraw. |
1144 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, OnModelChanged()); | 1119 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, OnModelChanged()); |
1145 } | 1120 } |
1146 | 1121 |
1147 void TaskManagerModel::Refresh() { | 1122 void TaskManagerModel::Refresh() { |
1148 goat_salt_ = base::RandUint64(); | |
1149 | |
1150 per_resource_cache_.clear(); | 1123 per_resource_cache_.clear(); |
1151 per_process_cache_.clear(); | 1124 per_process_cache_.clear(); |
1152 | 1125 |
1153 #if !defined(DISABLE_NACL) | 1126 #if !defined(DISABLE_NACL) |
1154 nacl::NaClBrowser* nacl_browser = nacl::NaClBrowser::GetInstance(); | 1127 nacl::NaClBrowser* nacl_browser = nacl::NaClBrowser::GetInstance(); |
1155 #endif // !defined(DISABLE_NACL) | 1128 #endif // !defined(DISABLE_NACL) |
1156 | 1129 |
1157 // Compute the CPU usage values and check if NaCl GDB debug stub port is | 1130 // Compute the CPU usage values and check if NaCl GDB debug stub port is |
1158 // known. | 1131 // known. |
1159 // Note that we compute the CPU usage for all resources (instead of doing it | 1132 // Note that we compute the CPU usage for all resources (instead of doing it |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1562 params.host_desktop_type = desktop_type; | 1535 params.host_desktop_type = desktop_type; |
1563 chrome::Navigate(¶ms); | 1536 chrome::Navigate(¶ms); |
1564 } | 1537 } |
1565 | 1538 |
1566 TaskManager::TaskManager() | 1539 TaskManager::TaskManager() |
1567 : model_(new TaskManagerModel(this)) { | 1540 : model_(new TaskManagerModel(this)) { |
1568 } | 1541 } |
1569 | 1542 |
1570 TaskManager::~TaskManager() { | 1543 TaskManager::~TaskManager() { |
1571 } | 1544 } |
OLD | NEW |