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

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

Issue 462027: Use factory to create histograms, and refcounts to track lifetimes... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years 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
« no previous file with comments | « chrome/browser/diagnostics/sqlite_diagnostics.cc ('k') | chrome/browser/net/dns_host_info.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 <limits> 5 #include <limits>
6 6
7 #include "chrome/browser/jankometer.h" 7 #include "chrome/browser/jankometer.h"
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 //------------------------------------------------------------------------------ 84 //------------------------------------------------------------------------------
85 class JankObserver : public base::RefCountedThreadSafe<JankObserver>, 85 class JankObserver : public base::RefCountedThreadSafe<JankObserver>,
86 public MessageLoopForUI::Observer { 86 public MessageLoopForUI::Observer {
87 public: 87 public:
88 JankObserver(const char* thread_name, 88 JankObserver(const char* thread_name,
89 const TimeDelta& excessive_duration, 89 const TimeDelta& excessive_duration,
90 bool watchdog_enable) 90 bool watchdog_enable)
91 : MaxMessageDelay_(excessive_duration), 91 : MaxMessageDelay_(excessive_duration),
92 slow_processing_counter_(std::string("Chrome.SlowMsg") + thread_name), 92 slow_processing_counter_(std::string("Chrome.SlowMsg") + thread_name),
93 queueing_delay_counter_(std::string("Chrome.DelayMsg") + thread_name), 93 queueing_delay_counter_(std::string("Chrome.DelayMsg") + thread_name),
94 process_times_((std::string("Chrome.ProcMsgL ") +
95 thread_name).c_str(), 1, 3600000, 50),
96 total_times_((std::string("Chrome.TotalMsgL ") +
97 thread_name).c_str(), 1, 3600000, 50),
98 total_time_watchdog_(excessive_duration, thread_name, watchdog_enable) { 94 total_time_watchdog_(excessive_duration, thread_name, watchdog_enable) {
99 process_times_.SetFlags(kUmaTargetedHistogramFlag); 95 process_times_ = Histogram::HistogramFactoryGet(
100 total_times_.SetFlags(kUmaTargetedHistogramFlag); 96 (std::string("Chrome.ProcMsgL ") + thread_name),
97 1, 3600000, 50);
98 total_times_ = Histogram::HistogramFactoryGet(
99 (std::string("Chrome.TotalMsgL ") + thread_name),
100 1, 3600000, 50);
101 process_times_->SetFlags(kUmaTargetedHistogramFlag);
102 total_times_->SetFlags(kUmaTargetedHistogramFlag);
101 } 103 }
102 104
103 // Attaches the observer to the current thread's message loop. You can only 105 // Attaches the observer to the current thread's message loop. You can only
104 // attach to the current thread, so this function can be invoked on another 106 // attach to the current thread, so this function can be invoked on another
105 // thread to attach it. 107 // thread to attach it.
106 void AttachToCurrentThread() { 108 void AttachToCurrentThread() {
107 // TODO(darin): support monitoring jankiness on non-UI threads! 109 // TODO(darin): support monitoring jankiness on non-UI threads!
108 if (MessageLoop::current()->type() == MessageLoop::TYPE_UI) 110 if (MessageLoop::current()->type() == MessageLoop::TYPE_UI)
109 MessageLoopForUI::current()->AddObserver(this); 111 MessageLoopForUI::current()->AddObserver(this);
110 } 112 }
(...skipping 19 matching lines...) Expand all
130 } 132 }
131 } 133 }
132 134
133 // Called when a message has just finished processing, finalizes 135 // Called when a message has just finished processing, finalizes
134 // per-message variables and timers. 136 // per-message variables and timers.
135 void EndProcessingTimers() { 137 void EndProcessingTimers() {
136 total_time_watchdog_.Disarm(); 138 total_time_watchdog_.Disarm();
137 TimeTicks now = TimeTicks::Now(); 139 TimeTicks now = TimeTicks::Now();
138 if (begin_process_message_ != TimeTicks()) { 140 if (begin_process_message_ != TimeTicks()) {
139 TimeDelta processing_time = now - begin_process_message_; 141 TimeDelta processing_time = now - begin_process_message_;
140 process_times_.AddTime(processing_time); 142 process_times_->AddTime(processing_time);
141 total_times_.AddTime(queueing_time_ + processing_time); 143 total_times_->AddTime(queueing_time_ + processing_time);
142 } 144 }
143 if (now - begin_process_message_ > 145 if (now - begin_process_message_ >
144 TimeDelta::FromMilliseconds(kMaxMessageProcessingMs)) { 146 TimeDelta::FromMilliseconds(kMaxMessageProcessingMs)) {
145 // Message took too long to process. 147 // Message took too long to process.
146 slow_processing_counter_.Increment(); 148 slow_processing_counter_.Increment();
147 #if defined(OS_WIN) 149 #if defined(OS_WIN)
148 if (kPlaySounds) 150 if (kPlaySounds)
149 MessageBeep(MB_ICONHAND); 151 MessageBeep(MB_ICONHAND);
150 #endif 152 #endif
151 } 153 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 // Time at which the current message processing began. 203 // Time at which the current message processing began.
202 TimeTicks begin_process_message_; 204 TimeTicks begin_process_message_;
203 205
204 // Time the current message spent in the queue -- delta between message 206 // Time the current message spent in the queue -- delta between message
205 // construction time and message processing time. 207 // construction time and message processing time.
206 TimeDelta queueing_time_; 208 TimeDelta queueing_time_;
207 209
208 // Counters for the two types of jank we measure. 210 // Counters for the two types of jank we measure.
209 StatsCounter slow_processing_counter_; // Messages with long processing time. 211 StatsCounter slow_processing_counter_; // Messages with long processing time.
210 StatsCounter queueing_delay_counter_; // Messages with long queueing delay. 212 StatsCounter queueing_delay_counter_; // Messages with long queueing delay.
211 Histogram process_times_; // Time spent processing task. 213 scoped_refptr<Histogram> process_times_; // Time spent processing task.
212 Histogram total_times_; // Total of queueing plus processing time. 214 scoped_refptr<Histogram> total_times_; // Total queueing plus processing.
213 JankWatchdog total_time_watchdog_; // Watching for excessive total_time. 215 JankWatchdog total_time_watchdog_; // Watching for excessive total_time.
214 216
215 DISALLOW_EVIL_CONSTRUCTORS(JankObserver); 217 DISALLOW_EVIL_CONSTRUCTORS(JankObserver);
216 }; 218 };
217 219
218 // These objects are created by InstallJankometer and leaked. 220 // These objects are created by InstallJankometer and leaked.
219 JankObserver* ui_observer = NULL; 221 JankObserver* ui_observer = NULL;
220 JankObserver* io_observer = NULL; 222 JankObserver* io_observer = NULL;
221 223
222 } // namespace 224 } // namespace
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 ui_observer->Release(); 267 ui_observer->Release();
266 ui_observer = NULL; 268 ui_observer = NULL;
267 } 269 }
268 if (io_observer) { 270 if (io_observer) {
269 // IO thread can't be running when we remove observers. 271 // IO thread can't be running when we remove observers.
270 DCHECK((!g_browser_process) || !(g_browser_process->io_thread())); 272 DCHECK((!g_browser_process) || !(g_browser_process->io_thread()));
271 io_observer->Release(); 273 io_observer->Release();
272 io_observer = NULL; 274 io_observer = NULL;
273 } 275 }
274 } 276 }
OLDNEW
« no previous file with comments | « chrome/browser/diagnostics/sqlite_diagnostics.cc ('k') | chrome/browser/net/dns_host_info.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698