| 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/chromeos/memory/oom_priority_manager.h" | 5 #include "chrome/browser/chromeos/memory/oom_priority_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/metrics/field_trial.h" | 14 #include "base/metrics/field_trial.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/process.h" | 16 #include "base/process.h" |
| 17 #include "base/process_util.h" | 17 #include "base/process_util.h" |
| 18 #include "base/string16.h" | 18 #include "base/string16.h" |
| 19 #include "base/string_number_conversions.h" | 19 #include "base/string_number_conversions.h" |
| 20 #include "base/string_util.h" |
| 20 #include "base/synchronization/lock.h" | 21 #include "base/synchronization/lock.h" |
| 21 #include "base/threading/thread.h" | 22 #include "base/threading/thread.h" |
| 22 #include "base/time.h" | 23 #include "base/time.h" |
| 23 #include "base/utf_string_conversions.h" | 24 #include "base/utf_string_conversions.h" |
| 24 #include "build/build_config.h" | 25 #include "build/build_config.h" |
| 25 #include "chrome/browser/browser_process.h" | 26 #include "chrome/browser/browser_process.h" |
| 26 #include "chrome/browser/chromeos/memory/low_memory_observer.h" | 27 #include "chrome/browser/chromeos/memory/low_memory_observer.h" |
| 27 #include "chrome/browser/memory_details.h" | 28 #include "chrome/browser/memory_details.h" |
| 28 #include "chrome/browser/ui/browser.h" | 29 #include "chrome/browser/ui/browser.h" |
| 29 #include "chrome/browser/ui/browser_list.h" | 30 #include "chrome/browser/ui/browser_list.h" |
| 30 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 31 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 31 #include "chrome/common/chrome_constants.h" | 32 #include "chrome/common/chrome_constants.h" |
| 32 #include "chrome/common/chrome_switches.h" | 33 #include "chrome/common/chrome_switches.h" |
| 33 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
| 34 #include "content/public/browser/notification_service.h" | 35 #include "content/public/browser/notification_service.h" |
| 35 #include "content/public/browser/notification_types.h" | 36 #include "content/public/browser/notification_types.h" |
| 36 #include "content/public/browser/render_process_host.h" | 37 #include "content/public/browser/render_process_host.h" |
| 37 #include "content/public/browser/render_widget_host.h" | 38 #include "content/public/browser/render_widget_host.h" |
| 38 #include "content/public/browser/web_contents.h" | 39 #include "content/public/browser/web_contents.h" |
| 39 #include "content/public/browser/zygote_host_linux.h" | 40 #include "content/public/browser/zygote_host_linux.h" |
| 41 #include "ui/base/text/bytes_formatting.h" |
| 40 | 42 |
| 41 using base::TimeDelta; | 43 using base::TimeDelta; |
| 42 using base::TimeTicks; | 44 using base::TimeTicks; |
| 43 using content::BrowserThread; | 45 using content::BrowserThread; |
| 44 using content::WebContents; | 46 using content::WebContents; |
| 45 | 47 |
| 46 namespace chromeos { | 48 namespace chromeos { |
| 47 | 49 |
| 48 namespace { | 50 namespace { |
| 49 | 51 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 | 104 |
| 103 OomMemoryDetails::OomMemoryDetails() { | 105 OomMemoryDetails::OomMemoryDetails() { |
| 104 AddRef(); // Released in OnDetailsAvailable(). | 106 AddRef(); // Released in OnDetailsAvailable(). |
| 105 start_time_ = TimeTicks::Now(); | 107 start_time_ = TimeTicks::Now(); |
| 106 } | 108 } |
| 107 | 109 |
| 108 void OomMemoryDetails::OnDetailsAvailable() { | 110 void OomMemoryDetails::OnDetailsAvailable() { |
| 109 TimeDelta delta = TimeTicks::Now() - start_time_; | 111 TimeDelta delta = TimeTicks::Now() - start_time_; |
| 110 // These logs are collected by user feedback reports. We want them to help | 112 // These logs are collected by user feedback reports. We want them to help |
| 111 // diagnose user-reported problems with frequently discarded tabs. | 113 // diagnose user-reported problems with frequently discarded tabs. |
| 114 std::string log_string = ToLogString(); |
| 115 base::SystemMemoryInfoKB memory; |
| 116 if (base::GetSystemMemoryInfo(&memory) && memory.gem_size != -1) { |
| 117 log_string += "Graphics "; |
| 118 log_string += UTF16ToASCII(ui::FormatBytes(memory.gem_size)); |
| 119 } |
| 112 LOG(WARNING) << "OOM details (" << delta.InMilliseconds() << " ms):\n" | 120 LOG(WARNING) << "OOM details (" << delta.InMilliseconds() << " ms):\n" |
| 113 << ToLogString(); | 121 << log_string; |
| 114 if (g_browser_process && g_browser_process->oom_priority_manager()) | 122 if (g_browser_process && g_browser_process->oom_priority_manager()) |
| 115 g_browser_process->oom_priority_manager()->DiscardTab(); | 123 g_browser_process->oom_priority_manager()->DiscardTab(); |
| 116 // Delete ourselves so we don't have to worry about OomPriorityManager | 124 // Delete ourselves so we don't have to worry about OomPriorityManager |
| 117 // deleting us when we're still working. | 125 // deleting us when we're still working. |
| 118 Release(); | 126 Release(); |
| 119 } | 127 } |
| 120 | 128 |
| 121 } // namespace | 129 } // namespace |
| 122 | 130 |
| 123 //////////////////////////////////////////////////////////////////////////////// | 131 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 TimeDelta interval = TimeTicks::Now() - last_discard_time_; | 280 TimeDelta interval = TimeTicks::Now() - last_discard_time_; |
| 273 int interval_ms = static_cast<int>(interval.InMilliseconds()); | 281 int interval_ms = static_cast<int>(interval.InMilliseconds()); |
| 274 // Record time in milliseconds over an interval of approximately 1 day. | 282 // Record time in milliseconds over an interval of approximately 1 day. |
| 275 // Start at 100 ms to get extra resolution in the target 750 ms range. | 283 // Start at 100 ms to get extra resolution in the target 750 ms range. |
| 276 EXPERIMENT_CUSTOM_COUNTS( | 284 EXPERIMENT_CUSTOM_COUNTS( |
| 277 "Tabs.Discard.IntervalTime2", interval_ms, 100, 100000 * 1000, 50); | 285 "Tabs.Discard.IntervalTime2", interval_ms, 100, 100000 * 1000, 50); |
| 278 } | 286 } |
| 279 // Record Chrome's concept of system memory usage at the time of the discard. | 287 // Record Chrome's concept of system memory usage at the time of the discard. |
| 280 base::SystemMemoryInfoKB memory; | 288 base::SystemMemoryInfoKB memory; |
| 281 if (base::GetSystemMemoryInfo(&memory)) { | 289 if (base::GetSystemMemoryInfo(&memory)) { |
| 290 // TODO(jamescook): Remove this after R25 is deployed to stable. It does |
| 291 // not have sufficient resolution in the 2-4 GB range and does not properly |
| 292 // account for graphics memory on ARM. Replace with MemAllocatedMB below. |
| 282 int mem_anonymous_mb = (memory.active_anon + memory.inactive_anon) / 1024; | 293 int mem_anonymous_mb = (memory.active_anon + memory.inactive_anon) / 1024; |
| 283 EXPERIMENT_HISTOGRAM_MEGABYTES("Tabs.Discard.MemAnonymousMB", | 294 EXPERIMENT_HISTOGRAM_MEGABYTES("Tabs.Discard.MemAnonymousMB", |
| 284 mem_anonymous_mb); | 295 mem_anonymous_mb); |
| 285 | 296 |
| 297 // On Intel, graphics objects are in anonymous pages, but on ARM they are |
| 298 // not. For a total "allocated count" add in graphics pages on ARM. |
| 299 int mem_allocated_mb = mem_anonymous_mb; |
| 300 #if defined(ARCH_CPU_ARM_FAMILY) |
| 301 if (memory.gem_size != -1) |
| 302 mem_allocated_mb += memory.gem_size / 1024 / 1024; |
| 303 #endif |
| 304 EXPERIMENT_CUSTOM_COUNTS("Tabs.Discard.MemAllocatedMB", mem_allocated_mb, |
| 305 256, 32768, 50) |
| 306 |
| 286 int mem_available_mb = | 307 int mem_available_mb = |
| 287 (memory.active_file + memory.inactive_file + memory.free) / 1024; | 308 (memory.active_file + memory.inactive_file + memory.free) / 1024; |
| 288 EXPERIMENT_HISTOGRAM_MEGABYTES("Tabs.Discard.MemAvailableMB", | 309 EXPERIMENT_HISTOGRAM_MEGABYTES("Tabs.Discard.MemAvailableMB", |
| 289 mem_available_mb); | 310 mem_available_mb); |
| 290 } | 311 } |
| 291 // Set up to record the next interval. | 312 // Set up to record the next interval. |
| 292 last_discard_time_ = TimeTicks::Now(); | 313 last_discard_time_ = TimeTicks::Now(); |
| 293 } | 314 } |
| 294 | 315 |
| 295 int OomPriorityManager::GetTabCount() const { | 316 int OomPriorityManager::GetTabCount() const { |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 content::ZygoteHost::GetInstance()->AdjustRendererOOMScore( | 531 content::ZygoteHost::GetInstance()->AdjustRendererOOMScore( |
| 511 iterator->renderer_handle, score); | 532 iterator->renderer_handle, score); |
| 512 pid_to_oom_score_[iterator->renderer_handle] = score; | 533 pid_to_oom_score_[iterator->renderer_handle] = score; |
| 513 } | 534 } |
| 514 priority += priority_increment; | 535 priority += priority_increment; |
| 515 } | 536 } |
| 516 } | 537 } |
| 517 } | 538 } |
| 518 | 539 |
| 519 } // namespace chromeos | 540 } // namespace chromeos |
| OLD | NEW |