 Chromium Code Reviews
 Chromium Code Reviews Issue 2181493002:
  Return unique_ptrs from base::ProcessMetrics.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 2181493002:
  Return unique_ptrs from base::ProcessMetrics.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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" | 
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 #include "chrome/browser/ui/browser_navigator.h" | 35 #include "chrome/browser/ui/browser_navigator.h" | 
| 36 #include "chrome/browser/ui/browser_navigator_params.h" | 36 #include "chrome/browser/ui/browser_navigator_params.h" | 
| 37 #include "chrome/browser/ui/user_manager.h" | 37 #include "chrome/browser/ui/user_manager.h" | 
| 38 #include "chrome/common/chrome_switches.h" | 38 #include "chrome/common/chrome_switches.h" | 
| 39 #include "chrome/common/pref_names.h" | 39 #include "chrome/common/pref_names.h" | 
| 40 #include "chrome/common/url_constants.h" | 40 #include "chrome/common/url_constants.h" | 
| 41 #include "chrome/grit/generated_resources.h" | 41 #include "chrome/grit/generated_resources.h" | 
| 42 #include "components/nacl/browser/nacl_browser.h" | 42 #include "components/nacl/browser/nacl_browser.h" | 
| 43 #include "components/prefs/pref_registry_simple.h" | 43 #include "components/prefs/pref_registry_simple.h" | 
| 44 #include "components/prefs/pref_service.h" | 44 #include "components/prefs/pref_service.h" | 
| 45 #include "content/public/browser/browser_child_process_host.h" | |
| 45 #include "content/public/browser/browser_thread.h" | 46 #include "content/public/browser/browser_thread.h" | 
| 46 #include "content/public/browser/gpu_data_manager.h" | 47 #include "content/public/browser/gpu_data_manager.h" | 
| 47 #include "content/public/browser/gpu_data_manager_observer.h" | 48 #include "content/public/browser/gpu_data_manager_observer.h" | 
| 48 #include "content/public/browser/resource_request_info.h" | 49 #include "content/public/browser/resource_request_info.h" | 
| 49 #include "content/public/browser/web_contents.h" | 50 #include "content/public/browser/web_contents.h" | 
| 50 #include "content/public/browser/web_contents_delegate.h" | 51 #include "content/public/browser/web_contents_delegate.h" | 
| 51 #include "content/public/browser/worker_service.h" | 52 #include "content/public/browser/worker_service.h" | 
| 52 #include "content/public/common/result_codes.h" | 53 #include "content/public/common/result_codes.h" | 
| 53 #include "extensions/browser/extension_system.h" | 54 #include "extensions/browser/extension_system.h" | 
| 54 #include "third_party/icu/source/i18n/unicode/coll.h" | 55 #include "third_party/icu/source/i18n/unicode/coll.h" | 
| 55 #include "ui/base/l10n/l10n_util.h" | 56 #include "ui/base/l10n/l10n_util.h" | 
| 56 #include "ui/base/resource/resource_bundle.h" | 57 #include "ui/base/resource/resource_bundle.h" | 
| 57 #include "ui/base/text/bytes_formatting.h" | 58 #include "ui/base/text/bytes_formatting.h" | 
| 58 #include "ui/gfx/image/image_skia.h" | 59 #include "ui/gfx/image/image_skia.h" | 
| 59 #include "ui/resources/grit/ui_resources.h" | 60 #include "ui/resources/grit/ui_resources.h" | 
| 60 | 61 | 
| 61 #if defined(OS_MACOSX) | |
| 62 #include "content/public/browser/browser_child_process_host.h" | |
| 63 #endif | |
| 64 | |
| 65 #if defined(OS_WIN) | |
| 66 #include "chrome/browser/win/private_working_set_snapshot.h" | |
| 67 #endif | |
| 68 | |
| 69 using content::BrowserThread; | 62 using content::BrowserThread; | 
| 70 using content::ResourceRequestInfo; | 63 using content::ResourceRequestInfo; | 
| 71 using content::WebContents; | 64 using content::WebContents; | 
| 72 using task_manager::Resource; | 65 using task_manager::Resource; | 
| 73 using task_manager::ResourceProvider; | 66 using task_manager::ResourceProvider; | 
| 74 using task_manager::WebContentsInformation; | 67 using task_manager::WebContentsInformation; | 
| 75 | 68 | 
| 76 class Profile; | 69 class Profile; | 
| 77 | 70 | 
| 78 namespace { | 71 namespace { | 
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 case IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN: | 121 case IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN: | 
| 129 case IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN: | 122 case IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN: | 
| 130 case IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN: | 123 case IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN: | 
| 131 case IDS_TASK_MANAGER_NACL_DEBUG_STUB_PORT_COLUMN: | 124 case IDS_TASK_MANAGER_NACL_DEBUG_STUB_PORT_COLUMN: | 
| 132 return true; | 125 return true; | 
| 133 default: | 126 default: | 
| 134 return false; | 127 return false; | 
| 135 } | 128 } | 
| 136 } | 129 } | 
| 137 | 130 | 
| 138 #if defined(OS_WIN) | |
| 139 void GetWinGDIHandles(base::ProcessHandle process, | |
| 140 size_t* current, | |
| 141 size_t* peak) { | |
| 142 *current = 0; | |
| 143 *peak = 0; | |
| 144 // Get a handle to |process| that has PROCESS_QUERY_INFORMATION rights. | |
| 145 HANDLE current_process = GetCurrentProcess(); | |
| 146 HANDLE process_with_query_rights; | |
| 147 if (DuplicateHandle(current_process, process, current_process, | |
| 148 &process_with_query_rights, PROCESS_QUERY_INFORMATION, | |
| 149 false, 0)) { | |
| 150 *current = GetGuiResources(process_with_query_rights, GR_GDIOBJECTS); | |
| 151 *peak = GetGuiResources(process_with_query_rights, GR_GDIOBJECTS_PEAK); | |
| 152 CloseHandle(process_with_query_rights); | |
| 153 } | |
| 154 } | |
| 155 | |
| 156 void GetWinUSERHandles(base::ProcessHandle process, | |
| 157 size_t* current, | |
| 158 size_t* peak) { | |
| 159 *current = 0; | |
| 160 *peak = 0; | |
| 161 // Get a handle to |process| that has PROCESS_QUERY_INFORMATION rights. | |
| 162 HANDLE current_process = GetCurrentProcess(); | |
| 163 HANDLE process_with_query_rights; | |
| 164 if (DuplicateHandle(current_process, process, current_process, | |
| 165 &process_with_query_rights, PROCESS_QUERY_INFORMATION, | |
| 166 false, 0)) { | |
| 167 *current = GetGuiResources(process_with_query_rights, GR_USEROBJECTS); | |
| 168 *peak = GetGuiResources(process_with_query_rights, GR_USEROBJECTS_PEAK); | |
| 169 CloseHandle(process_with_query_rights); | |
| 170 } | |
| 171 } | |
| 172 #endif | |
| 173 | |
| 174 } // namespace | 131 } // namespace | 
| 175 | 132 | 
| 176 class TaskManagerModelGpuDataManagerObserver | 133 class TaskManagerModelGpuDataManagerObserver | 
| 177 : public content::GpuDataManagerObserver { | 134 : public content::GpuDataManagerObserver { | 
| 178 public: | 135 public: | 
| 179 TaskManagerModelGpuDataManagerObserver() { | 136 TaskManagerModelGpuDataManagerObserver() { | 
| 180 content::GpuDataManager::GetInstance()->AddObserver(this); | 137 content::GpuDataManager::GetInstance()->AddObserver(this); | 
| 181 } | 138 } | 
| 182 | 139 | 
| 183 ~TaskManagerModelGpuDataManagerObserver() override { | 140 ~TaskManagerModelGpuDataManagerObserver() override { | 
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 task_manager, std::unique_ptr<WebContentsInformation>( | 233 task_manager, std::unique_ptr<WebContentsInformation>( | 
| 277 new task_manager::PanelInformation()))); | 234 new task_manager::PanelInformation()))); | 
| 278 AddResourceProvider( | 235 AddResourceProvider( | 
| 279 new task_manager::ChildProcessResourceProvider(task_manager)); | 236 new task_manager::ChildProcessResourceProvider(task_manager)); | 
| 280 AddResourceProvider(new task_manager::WebContentsResourceProvider( | 237 AddResourceProvider(new task_manager::WebContentsResourceProvider( | 
| 281 task_manager, std::unique_ptr<WebContentsInformation>( | 238 task_manager, std::unique_ptr<WebContentsInformation>( | 
| 282 new task_manager::ExtensionInformation()))); | 239 new task_manager::ExtensionInformation()))); | 
| 283 AddResourceProvider(new task_manager::WebContentsResourceProvider( | 240 AddResourceProvider(new task_manager::WebContentsResourceProvider( | 
| 284 task_manager, std::unique_ptr<WebContentsInformation>( | 241 task_manager, std::unique_ptr<WebContentsInformation>( | 
| 285 new task_manager::GuestInformation()))); | 242 new task_manager::GuestInformation()))); | 
| 286 #if defined(OS_WIN) | |
| 287 working_set_snapshot_.reset(new PrivateWorkingSetSnapshot); | |
| 288 working_set_snapshot_->AddToMonitorList("chrome"); | |
| 289 working_set_snapshot_->AddToMonitorList("nacl64"); | |
| 290 #endif | |
| 291 } | 243 } | 
| 292 | 244 | 
| 293 void TaskManagerModel::AddObserver(TaskManagerModelObserver* observer) { | 245 void TaskManagerModel::AddObserver(TaskManagerModelObserver* observer) { | 
| 294 observer_list_.AddObserver(observer); | 246 observer_list_.AddObserver(observer); | 
| 295 } | 247 } | 
| 296 | 248 | 
| 297 void TaskManagerModel::RemoveObserver(TaskManagerModelObserver* observer) { | 249 void TaskManagerModel::RemoveObserver(TaskManagerModelObserver* observer) { | 
| 298 observer_list_.RemoveObserver(observer); | 250 observer_list_.RemoveObserver(observer); | 
| 299 } | 251 } | 
| 300 | 252 | 
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 444 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT); | 396 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT); | 
| 445 if (net_usage == 0) | 397 if (net_usage == 0) | 
| 446 return base::ASCIIToUTF16("0"); | 398 return base::ASCIIToUTF16("0"); | 
| 447 base::string16 net_byte = ui::FormatSpeed(net_usage); | 399 base::string16 net_byte = ui::FormatSpeed(net_usage); | 
| 448 // Force number string to have LTR directionality. | 400 // Force number string to have LTR directionality. | 
| 449 return base::i18n::GetDisplayStringInLTRDirectionality(net_byte); | 401 return base::i18n::GetDisplayStringInLTRDirectionality(net_byte); | 
| 450 } | 402 } | 
| 451 | 403 | 
| 452 base::string16 TaskManagerModel::GetResourceCPUUsage(int index) const { | 404 base::string16 TaskManagerModel::GetResourceCPUUsage(int index) const { | 
| 453 return base::UTF8ToUTF16(base::StringPrintf( | 405 return base::UTF8ToUTF16(base::StringPrintf( | 
| 454 #if defined(OS_MACOSX) | |
| 455 // Activity Monitor shows %cpu with one decimal digit -- be | 406 // Activity Monitor shows %cpu with one decimal digit -- be | 
| 456 // consistent with that. | 407 // consistent with that. | 
| 457 "%.1f", | 408 "%.1f", | 
| 458 #else | |
| 459 "%.0f", | |
| 460 #endif | |
| 461 GetCPUUsage(GetResource(index)))); | 409 GetCPUUsage(GetResource(index)))); | 
| 462 } | 410 } | 
| 463 | 411 | 
| 464 base::string16 TaskManagerModel::GetResourcePrivateMemory(int index) const { | 412 base::string16 TaskManagerModel::GetResourcePrivateMemory(int index) const { | 
| 465 size_t private_mem; | 413 size_t private_mem; | 
| 466 if (!GetPrivateMemory(index, &private_mem)) | 414 if (!GetPrivateMemory(index, &private_mem)) | 
| 467 return base::ASCIIToUTF16("N/A"); | 415 return base::ASCIIToUTF16("N/A"); | 
| 468 return GetMemCellText(private_mem); | 416 return GetMemCellText(private_mem); | 
| 469 } | 417 } | 
| 470 | 418 | 
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 584 PerProcessValues& values(per_process_cache_[handle]); | 532 PerProcessValues& values(per_process_cache_[handle]); | 
| 585 | 533 | 
| 586 if (!values.is_physical_memory_valid) { | 534 if (!values.is_physical_memory_valid) { | 
| 587 base::WorkingSetKBytes ws_usage; | 535 base::WorkingSetKBytes ws_usage; | 
| 588 MetricsMap::const_iterator iter = metrics_map_.find(handle); | 536 MetricsMap::const_iterator iter = metrics_map_.find(handle); | 
| 589 if (iter == metrics_map_.end() || | 537 if (iter == metrics_map_.end() || | 
| 590 !iter->second->GetWorkingSetKBytes(&ws_usage)) | 538 !iter->second->GetWorkingSetKBytes(&ws_usage)) | 
| 591 return false; | 539 return false; | 
| 592 | 540 | 
| 593 values.is_physical_memory_valid = true; | 541 values.is_physical_memory_valid = true; | 
| 594 #if defined(OS_LINUX) | |
| 595 // On Linux private memory is also resident. Just use it. | |
| 596 values.physical_memory = ws_usage.priv * 1024; | |
| 597 #else | |
| 598 // Memory = working_set.private which is working set minus shareable. This | 542 // Memory = working_set.private which is working set minus shareable. This | 
| 599 // avoids the unpredictable counting that occurs when calculating memory as | 543 // avoids the unpredictable counting that occurs when calculating memory as | 
| 600 // working set minus shared (renderer code counted when one tab is open and | 544 // working set minus shared (renderer code counted when one tab is open and | 
| 601 // not counted when two or more are open) and it is much more efficient to | 545 // not counted when two or more are open) and it is much more efficient to | 
| 602 // calculate on Windows. | 546 // calculate on Windows. | 
| 603 values.physical_memory = iter->second->GetWorkingSetSize(); | 547 values.physical_memory = iter->second->GetWorkingSetSize(); | 
| 604 values.physical_memory -= ws_usage.shareable * 1024; | 548 values.physical_memory -= ws_usage.shareable * 1024; | 
| 605 #endif | |
| 606 } | 549 } | 
| 607 *result = values.physical_memory; | 550 *result = values.physical_memory; | 
| 608 return true; | 551 return true; | 
| 609 } | 552 } | 
| 610 | 553 | 
| 611 void TaskManagerModel::GetGDIHandles(int index, | 554 void TaskManagerModel::GetGDIHandles(int index, | 
| 612 size_t* current, | 555 size_t* current, | 
| 613 size_t* peak) const { | 556 size_t* peak) const { | 
| 614 *current = 0; | 557 *current = 0; | 
| 615 *peak = 0; | 558 *peak = 0; | 
| 616 #if defined(OS_WIN) | |
| 617 base::ProcessHandle handle = GetResource(index)->GetProcess(); | |
| 618 PerProcessValues& values(per_process_cache_[handle]); | |
| 619 | |
| 620 if (!values.is_gdi_handles_valid) { | |
| 621 GetWinGDIHandles(GetResource(index)->GetProcess(), | |
| 
afakhry
2016/07/25 17:58:47
You can now remove c/b/task_manager/os_resource_wi
 
Lei Zhang
2016/07/25 18:26:12
Done.
 | |
| 622 &values.gdi_handles, | |
| 623 &values.gdi_handles_peak); | |
| 624 values.is_gdi_handles_valid = true; | |
| 625 } | |
| 626 *current = values.gdi_handles; | |
| 627 *peak = values.gdi_handles_peak; | |
| 628 #endif | |
| 629 } | 559 } | 
| 630 | 560 | 
| 631 void TaskManagerModel::GetUSERHandles(int index, | 561 void TaskManagerModel::GetUSERHandles(int index, | 
| 632 size_t* current, | 562 size_t* current, | 
| 633 size_t* peak) const { | 563 size_t* peak) const { | 
| 634 *current = 0; | 564 *current = 0; | 
| 635 *peak = 0; | 565 *peak = 0; | 
| 636 #if defined(OS_WIN) | |
| 637 base::ProcessHandle handle = GetResource(index)->GetProcess(); | |
| 638 PerProcessValues& values(per_process_cache_[handle]); | |
| 639 | |
| 640 if (!values.is_user_handles_valid) { | |
| 641 GetWinUSERHandles(GetResource(index)->GetProcess(), | |
| 642 &values.user_handles, | |
| 643 &values.user_handles_peak); | |
| 644 values.is_user_handles_valid = true; | |
| 645 } | |
| 646 *current = values.user_handles; | |
| 647 *peak = values.user_handles_peak; | |
| 648 #endif | |
| 649 } | 566 } | 
| 650 | 567 | 
| 651 bool TaskManagerModel::GetWebCoreCacheStats( | 568 bool TaskManagerModel::GetWebCoreCacheStats( | 
| 652 int index, | 569 int index, | 
| 653 blink::WebCache::ResourceTypeStats* result) const { | 570 blink::WebCache::ResourceTypeStats* result) const { | 
| 654 if (!CacheWebCoreStats(index)) | 571 if (!CacheWebCoreStats(index)) | 
| 655 return false; | 572 return false; | 
| 656 *result = GetPerResourceValues(index).webcore_stats; | 573 *result = GetPerResourceValues(index).webcore_stats; | 
| 657 return true; | 574 return true; | 
| 658 } | 575 } | 
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 960 std::find(resources_.begin(), | 877 std::find(resources_.begin(), | 
| 961 resources_.end(), | 878 resources_.end(), | 
| 962 (*group_entries)[group_entries->size() - 2]); | 879 (*group_entries)[group_entries->size() - 2]); | 
| 963 DCHECK(iter != resources_.end()); | 880 DCHECK(iter != resources_.end()); | 
| 964 new_entry_index = static_cast<int>(iter - resources_.begin()) + 1; | 881 new_entry_index = static_cast<int>(iter - resources_.begin()) + 1; | 
| 965 resources_.insert(++iter, resource); | 882 resources_.insert(++iter, resource); | 
| 966 } | 883 } | 
| 967 | 884 | 
| 968 // Create the ProcessMetrics for this process if needed (not in map). | 885 // Create the ProcessMetrics for this process if needed (not in map). | 
| 969 if (metrics_map_.find(process) == metrics_map_.end()) { | 886 if (metrics_map_.find(process) == metrics_map_.end()) { | 
| 970 base::ProcessMetrics* pm = | 887 std::unique_ptr<base::ProcessMetrics> pm = | 
| 971 #if !defined(OS_MACOSX) | |
| 972 base::ProcessMetrics::CreateProcessMetrics(process); | |
| 973 #else | |
| 974 base::ProcessMetrics::CreateProcessMetrics( | 888 base::ProcessMetrics::CreateProcessMetrics( | 
| 975 process, content::BrowserChildProcessHost::GetPortProvider()); | 889 process, content::BrowserChildProcessHost::GetPortProvider()); | 
| 976 #endif | 890 metrics_map_[process] = pm.release(); | 
| 977 | |
| 978 metrics_map_[process] = pm; | |
| 979 } | 891 } | 
| 980 | 892 | 
| 981 // Notify the table that the contents have changed for it to redraw. | 893 // Notify the table that the contents have changed for it to redraw. | 
| 982 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, | 894 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, | 
| 983 OnItemsAdded(new_entry_index, 1)); | 895 OnItemsAdded(new_entry_index, 1)); | 
| 984 } | 896 } | 
| 985 | 897 | 
| 986 void TaskManagerModel::RemoveResource(Resource* resource) { | 898 void TaskManagerModel::RemoveResource(Resource* resource) { | 
| 987 base::ProcessHandle process = resource->GetProcess(); | 899 base::ProcessHandle process = resource->GetProcess(); | 
| 988 | 900 | 
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1140 OnItemsRemoved(0, size)); | 1052 OnItemsRemoved(0, size)); | 
| 1141 } | 1053 } | 
| 1142 } | 1054 } | 
| 1143 | 1055 | 
| 1144 void TaskManagerModel::ModelChanged() { | 1056 void TaskManagerModel::ModelChanged() { | 
| 1145 // Notify the table that the contents have changed for it to redraw. | 1057 // Notify the table that the contents have changed for it to redraw. | 
| 1146 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, OnModelChanged()); | 1058 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, OnModelChanged()); | 
| 1147 } | 1059 } | 
| 1148 | 1060 | 
| 1149 void TaskManagerModel::RefreshPhysicalMemoryFromWorkingSetSnapshot() { | 1061 void TaskManagerModel::RefreshPhysicalMemoryFromWorkingSetSnapshot() { | 
| 1150 #if defined(OS_WIN) | |
| 1151 // Collect working-set data for all monitored processes in one operation, to | |
| 1152 // avoid the inefficiency of retrieving it one at a time. | |
| 1153 working_set_snapshot_->Sample(); | |
| 1154 | |
| 1155 for (size_t i = 0; i < resources_.size(); ++i) { | |
| 1156 size_t private_working_set = | |
| 1157 working_set_snapshot_->GetPrivateWorkingSet(GetProcessId(i)); | |
| 1158 | |
| 1159 // If working-set data is available then use it. If not then | |
| 1160 // GetWorkingSetKBytes will retrieve the data. This is rare except on | |
| 1161 // Windows XP where GetWorkingSetKBytes will always be used. | |
| 1162 if (private_working_set) { | |
| 1163 // Fill in the cache with the retrieved private working set value. | |
| 1164 base::ProcessHandle handle = GetResource(i)->GetProcess(); | |
| 1165 PerProcessValues& values(per_process_cache_[handle]); | |
| 1166 values.is_physical_memory_valid = true; | |
| 1167 // Note that the other memory fields are *not* filled in. | |
| 1168 values.physical_memory = private_working_set; | |
| 1169 } | |
| 1170 } | |
| 1171 #else | |
| 1172 // This is a NOP on other platforms because they can efficiently retrieve | 1062 // This is a NOP on other platforms because they can efficiently retrieve | 
| 1173 // the private working-set data on a per-process basis. | 1063 // the private working-set data on a per-process basis. | 
| 1174 #endif | |
| 1175 } | 1064 } | 
| 1176 | 1065 | 
| 1177 void TaskManagerModel::Refresh() { | 1066 void TaskManagerModel::Refresh() { | 
| 1178 per_resource_cache_.clear(); | 1067 per_resource_cache_.clear(); | 
| 1179 per_process_cache_.clear(); | 1068 per_process_cache_.clear(); | 
| 1180 RefreshPhysicalMemoryFromWorkingSetSnapshot(); | 1069 RefreshPhysicalMemoryFromWorkingSetSnapshot(); | 
| 1181 | 1070 | 
| 1182 #if !defined(DISABLE_NACL) | 1071 #if !defined(DISABLE_NACL) | 
| 1183 nacl::NaClBrowser* nacl_browser = nacl::NaClBrowser::GetInstance(); | 1072 nacl::NaClBrowser* nacl_browser = nacl::NaClBrowser::GetInstance(); | 
| 1184 #endif // !defined(DISABLE_NACL) | 1073 #endif // !defined(DISABLE_NACL) | 
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1205 } | 1094 } | 
| 1206 #endif // !defined(DISABLE_NACL) | 1095 #endif // !defined(DISABLE_NACL) | 
| 1207 if (values.is_cpu_usage_valid && values.is_idle_wakeups_valid) | 1096 if (values.is_cpu_usage_valid && values.is_idle_wakeups_valid) | 
| 1208 continue; | 1097 continue; | 
| 1209 MetricsMap::iterator metrics_iter = metrics_map_.find(process); | 1098 MetricsMap::iterator metrics_iter = metrics_map_.find(process); | 
| 1210 DCHECK(metrics_iter != metrics_map_.end()); | 1099 DCHECK(metrics_iter != metrics_map_.end()); | 
| 1211 if (!values.is_cpu_usage_valid) { | 1100 if (!values.is_cpu_usage_valid) { | 
| 1212 values.is_cpu_usage_valid = true; | 1101 values.is_cpu_usage_valid = true; | 
| 1213 values.cpu_usage = metrics_iter->second->GetCPUUsage(); | 1102 values.cpu_usage = metrics_iter->second->GetCPUUsage(); | 
| 1214 } | 1103 } | 
| 1215 #if defined(OS_MACOSX) || defined(OS_LINUX) | |
| 1216 // TODO(port): Implement GetIdleWakeupsPerSecond() on other platforms, | 1104 // TODO(port): Implement GetIdleWakeupsPerSecond() on other platforms, | 
| 1217 // crbug.com/120488 | 1105 // crbug.com/120488 | 
| 1218 if (!values.is_idle_wakeups_valid) { | 1106 if (!values.is_idle_wakeups_valid) { | 
| 1219 values.is_idle_wakeups_valid = true; | 1107 values.is_idle_wakeups_valid = true; | 
| 1220 values.idle_wakeups = metrics_iter->second->GetIdleWakeupsPerSecond(); | 1108 values.idle_wakeups = metrics_iter->second->GetIdleWakeupsPerSecond(); | 
| 1221 } | 1109 } | 
| 1222 #endif // defined(OS_MACOSX) || defined(OS_LINUX) | |
| 1223 } | 1110 } | 
| 1224 | 1111 | 
| 1225 // Send a request to refresh GPU memory consumption values | 1112 // Send a request to refresh GPU memory consumption values | 
| 1226 RefreshVideoMemoryUsageStats(); | 1113 RefreshVideoMemoryUsageStats(); | 
| 1227 | 1114 | 
| 1228 // Compute the new network usage values. | 1115 // Compute the new network usage values. | 
| 1229 base::TimeDelta update_time = | 1116 base::TimeDelta update_time = | 
| 1230 base::TimeDelta::FromMilliseconds(kUpdateTimeMs); | 1117 base::TimeDelta::FromMilliseconds(kUpdateTimeMs); | 
| 1231 for (ResourceValueMap::iterator iter = current_byte_count_map_.begin(); | 1118 for (ResourceValueMap::iterator iter = current_byte_count_map_.begin(); | 
| 1232 iter != current_byte_count_map_.end(); ++iter) { | 1119 iter != current_byte_count_map_.end(); ++iter) { | 
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1429 return values.cpu_usage; | 1316 return values.cpu_usage; | 
| 1430 } | 1317 } | 
| 1431 | 1318 | 
| 1432 int TaskManagerModel::GetIdleWakeupsPerSecond(Resource* resource) const { | 1319 int TaskManagerModel::GetIdleWakeupsPerSecond(Resource* resource) const { | 
| 1433 const PerProcessValues& values(per_process_cache_[resource->GetProcess()]); | 1320 const PerProcessValues& values(per_process_cache_[resource->GetProcess()]); | 
| 1434 // Returns 0 if not valid, which is fine. | 1321 // Returns 0 if not valid, which is fine. | 
| 1435 return values.idle_wakeups; | 1322 return values.idle_wakeups; | 
| 1436 } | 1323 } | 
| 1437 | 1324 | 
| 1438 base::string16 TaskManagerModel::GetMemCellText(int64_t number) const { | 1325 base::string16 TaskManagerModel::GetMemCellText(int64_t number) const { | 
| 1439 #if !defined(OS_MACOSX) | |
| 1440 base::string16 str = base::FormatNumber(number / 1024); | |
| 1441 | |
| 1442 // Adjust number string if necessary. | |
| 1443 base::i18n::AdjustStringForLocaleDirection(&str); | |
| 1444 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_MEM_CELL_TEXT, str); | |
| 1445 #else | |
| 1446 // System expectation is to show "100 kB", "200 MB", etc. | 1326 // System expectation is to show "100 kB", "200 MB", etc. | 
| 1447 // TODO(thakis): Switch to metric units (as opposed to powers of two). | 1327 // TODO(thakis): Switch to metric units (as opposed to powers of two). | 
| 1448 return ui::FormatBytes(number); | 1328 return ui::FormatBytes(number); | 
| 1449 #endif | |
| 1450 } | 1329 } | 
| 1451 | 1330 | 
| 1452 bool TaskManagerModel::CachePrivateAndSharedMemory( | 1331 bool TaskManagerModel::CachePrivateAndSharedMemory( | 
| 1453 base::ProcessHandle handle) const { | 1332 base::ProcessHandle handle) const { | 
| 1454 PerProcessValues& values(per_process_cache_[handle]); | 1333 PerProcessValues& values(per_process_cache_[handle]); | 
| 1455 if (values.is_private_and_shared_valid) | 1334 if (values.is_private_and_shared_valid) | 
| 1456 return true; | 1335 return true; | 
| 1457 | 1336 | 
| 1458 MetricsMap::const_iterator iter = metrics_map_.find(handle); | 1337 MetricsMap::const_iterator iter = metrics_map_.find(handle); | 
| 1459 if (iter == metrics_map_.end() || | 1338 if (iter == metrics_map_.end() || | 
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1557 CHECK(!task_management::TaskManagerInterface::IsNewTaskManagerEnabled()); | 1436 CHECK(!task_management::TaskManagerInterface::IsNewTaskManagerEnabled()); | 
| 1558 return base::Singleton<TaskManager>::get(); | 1437 return base::Singleton<TaskManager>::get(); | 
| 1559 } | 1438 } | 
| 1560 | 1439 | 
| 1561 TaskManager::TaskManager() | 1440 TaskManager::TaskManager() | 
| 1562 : model_(new TaskManagerModel(this)) { | 1441 : model_(new TaskManagerModel(this)) { | 
| 1563 } | 1442 } | 
| 1564 | 1443 | 
| 1565 TaskManager::~TaskManager() { | 1444 TaskManager::~TaskManager() { | 
| 1566 } | 1445 } | 
| OLD | NEW |