Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(475)

Side by Side Diff: chrome/browser/oom_priority_manager.cc

Issue 10151005: cros: Log per-process memory use on low memory events (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/oom_priority_manager.h" 5 #include "chrome/browser/oom_priority_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/process.h" 13 #include "base/process.h"
14 #include "base/process_util.h" 14 #include "base/process_util.h"
15 #include "base/string16.h" 15 #include "base/string16.h"
16 #include "base/string_number_conversions.h" 16 #include "base/string_number_conversions.h"
17 #include "base/synchronization/lock.h" 17 #include "base/synchronization/lock.h"
18 #include "base/threading/thread.h" 18 #include "base/threading/thread.h"
19 #include "base/timer.h" 19 #include "base/timer.h"
20 #include "base/utf_string_conversions.h" 20 #include "base/utf_string_conversions.h"
21 #include "build/build_config.h" 21 #include "build/build_config.h"
22 #include "chrome/browser/browser_process.h"
22 #include "chrome/browser/low_memory_observer.h" 23 #include "chrome/browser/low_memory_observer.h"
24 #include "chrome/browser/memory_details.h"
23 #include "chrome/browser/tabs/tab_strip_model.h" 25 #include "chrome/browser/tabs/tab_strip_model.h"
24 #include "chrome/browser/ui/browser_list.h" 26 #include "chrome/browser/ui/browser_list.h"
25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 27 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
26 #include "chrome/common/chrome_constants.h" 28 #include "chrome/common/chrome_constants.h"
27 #include "content/public/browser/browser_thread.h" 29 #include "content/public/browser/browser_thread.h"
28 #include "content/public/browser/notification_service.h" 30 #include "content/public/browser/notification_service.h"
29 #include "content/public/browser/notification_types.h" 31 #include "content/public/browser/notification_types.h"
30 #include "content/public/browser/render_process_host.h" 32 #include "content/public/browser/render_process_host.h"
31 #include "content/public/browser/render_widget_host.h" 33 #include "content/public/browser/render_widget_host.h"
32 #include "content/public/browser/web_contents.h" 34 #include "content/public/browser/web_contents.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 // The default interval in milliseconds to wait before setting the score of 69 // The default interval in milliseconds to wait before setting the score of
68 // currently focused tab. 70 // currently focused tab.
69 const int kFocusedTabScoreAdjustIntervalMs = 500; 71 const int kFocusedTabScoreAdjustIntervalMs = 500;
70 72
71 // Returns a unique ID for a WebContents. Do not cast back to a pointer, as 73 // Returns a unique ID for a WebContents. Do not cast back to a pointer, as
72 // the WebContents could be deleted if the user closed the tab. 74 // the WebContents could be deleted if the user closed the tab.
73 int64 IdFromTabContents(WebContents* web_contents) { 75 int64 IdFromTabContents(WebContents* web_contents) {
74 return reinterpret_cast<int64>(web_contents); 76 return reinterpret_cast<int64>(web_contents);
75 } 77 }
76 78
79 ////////////////////////////////////////////////////////////////////////////////
80 // OomMemoryDetails logs details about all Chrome processes during an out-of-
81 // memory event in an attempt to identify the culprit, then discards a tab and
82 // deletes itself.
83 class OomMemoryDetails : public MemoryDetails {
84 public:
85 OomMemoryDetails();
86
87 // MemoryDetails overrides:
88 virtual void OnDetailsAvailable() OVERRIDE;
89
90 private:
91 virtual ~OomMemoryDetails() {}
92
93 TimeTicks start_time_;
94
95 DISALLOW_COPY_AND_ASSIGN(OomMemoryDetails);
96 };
97
98 OomMemoryDetails::OomMemoryDetails() {
99 start_time_ = TimeTicks::Now();
100 }
101
102 void OomMemoryDetails::OnDetailsAvailable() {
103 TimeDelta delta = TimeTicks::Now() - start_time_;
104 // These logs are collected by user feedback reports. We want them to help
105 // diagnose user-reported problems with frequently discarded tabs.
106 LOG(INFO) << "OOM details (" << delta.InMilliseconds() << " ms):\n"
107 << ToLogString();
108 if (g_browser_process && g_browser_process->oom_priority_manager())
109 g_browser_process->oom_priority_manager()->DiscardTab();
110 // Delete ourselves so we don't have to worry about OomPriorityManager
111 // deleting us when we're still working.
112 delete this;
Greg Spencer (Chromium) 2012/04/20 00:28:21 Interesting solution. I like it.
113 }
114
77 } // namespace 115 } // namespace
78 116
79 //////////////////////////////////////////////////////////////////////////////// 117 ////////////////////////////////////////////////////////////////////////////////
80 // OomPriorityManager 118 // OomPriorityManager
81 119
82 OomPriorityManager::TabStats::TabStats() 120 OomPriorityManager::TabStats::TabStats()
83 : is_pinned(false), 121 : is_pinned(false),
84 is_selected(false), 122 is_selected(false),
85 renderer_handle(0), 123 renderer_handle(0),
86 sudden_termination_allowed(false), 124 sudden_termination_allowed(false),
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 for (TabStatsList::const_reverse_iterator stats_rit = stats.rbegin(); 192 for (TabStatsList::const_reverse_iterator stats_rit = stats.rbegin();
155 stats_rit != stats.rend(); 193 stats_rit != stats.rend();
156 ++stats_rit) { 194 ++stats_rit) {
157 int64 least_important_tab_id = stats_rit->tab_contents_id; 195 int64 least_important_tab_id = stats_rit->tab_contents_id;
158 if (DiscardTabById(least_important_tab_id)) 196 if (DiscardTabById(least_important_tab_id))
159 return true; 197 return true;
160 } 198 }
161 return false; 199 return false;
162 } 200 }
163 201
202 void OomPriorityManager::LogMemoryAndDiscardTab() {
203 // Deletes itself upon completion.
204 OomMemoryDetails* details = new OomMemoryDetails();
205 details->StartFetch();
206 }
207
164 bool OomPriorityManager::DiscardTabById(int64 target_web_contents_id) { 208 bool OomPriorityManager::DiscardTabById(int64 target_web_contents_id) {
165 for (BrowserList::const_iterator browser_iterator = BrowserList::begin(); 209 for (BrowserList::const_iterator browser_iterator = BrowserList::begin();
166 browser_iterator != BrowserList::end(); ++browser_iterator) { 210 browser_iterator != BrowserList::end(); ++browser_iterator) {
167 Browser* browser = *browser_iterator; 211 Browser* browser = *browser_iterator;
168 TabStripModel* model = browser->tabstrip_model(); 212 TabStripModel* model = browser->tabstrip_model();
169 for (int idx = 0; idx < model->count(); idx++) { 213 for (int idx = 0; idx < model->count(); idx++) {
170 // Can't discard tabs that are already discarded. 214 // Can't discard tabs that are already discarded.
171 if (model->IsTabDiscarded(idx)) 215 if (model->IsTabDiscarded(idx))
172 continue; 216 continue;
173 WebContents* web_contents = model->GetTabContentsAt(idx)->web_contents(); 217 WebContents* web_contents = model->GetTabContentsAt(idx)->web_contents();
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 content::ZygoteHost::GetInstance()->AdjustRendererOOMScore( 468 content::ZygoteHost::GetInstance()->AdjustRendererOOMScore(
425 iterator->renderer_handle, score); 469 iterator->renderer_handle, score);
426 pid_to_oom_score_[iterator->renderer_handle] = score; 470 pid_to_oom_score_[iterator->renderer_handle] = score;
427 } 471 }
428 priority += priority_increment; 472 priority += priority_increment;
429 } 473 }
430 } 474 }
431 } 475 }
432 476
433 } // namespace browser 477 } // namespace browser
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698