| 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/jankometer.h" | 5 #include "chrome/browser/jankometer.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 else | 203 else |
| 204 events_till_measurement_ = discard_count_; | 204 events_till_measurement_ = discard_count_; |
| 205 return measure_current_message_; | 205 return measure_current_message_; |
| 206 } | 206 } |
| 207 | 207 |
| 208 // static | 208 // static |
| 209 int JankObserverHelper::discard_count_ = 99; // Measure only 1 in 100. | 209 int JankObserverHelper::discard_count_ = 99; // Measure only 1 in 100. |
| 210 | 210 |
| 211 //------------------------------------------------------------------------------ | 211 //------------------------------------------------------------------------------ |
| 212 class IOJankObserver : public base::RefCountedThreadSafe<IOJankObserver>, | 212 class IOJankObserver : public base::RefCountedThreadSafe<IOJankObserver>, |
| 213 public MessageLoopForIO::IOObserver, | 213 public base::MessageLoopForIO::IOObserver, |
| 214 public MessageLoop::TaskObserver { | 214 public base::MessageLoop::TaskObserver { |
| 215 public: | 215 public: |
| 216 IOJankObserver(const char* thread_name, | 216 IOJankObserver(const char* thread_name, |
| 217 TimeDelta excessive_duration, | 217 TimeDelta excessive_duration, |
| 218 bool watchdog_enable) | 218 bool watchdog_enable) |
| 219 : helper_(thread_name, excessive_duration, watchdog_enable) {} | 219 : helper_(thread_name, excessive_duration, watchdog_enable) {} |
| 220 | 220 |
| 221 // Attaches the observer to the current thread's message loop. You can only | 221 // Attaches the observer to the current thread's message loop. You can only |
| 222 // attach to the current thread, so this function can be invoked on another | 222 // attach to the current thread, so this function can be invoked on another |
| 223 // thread to attach it. | 223 // thread to attach it. |
| 224 void AttachToCurrentThread() { | 224 void AttachToCurrentThread() { |
| 225 MessageLoop::current()->AddTaskObserver(this); | 225 base::MessageLoop::current()->AddTaskObserver(this); |
| 226 MessageLoopForIO::current()->AddIOObserver(this); | 226 base::MessageLoopForIO::current()->AddIOObserver(this); |
| 227 } | 227 } |
| 228 | 228 |
| 229 // Detaches the observer to the current thread's message loop. | 229 // Detaches the observer to the current thread's message loop. |
| 230 void DetachFromCurrentThread() { | 230 void DetachFromCurrentThread() { |
| 231 MessageLoopForIO::current()->RemoveIOObserver(this); | 231 base::MessageLoopForIO::current()->RemoveIOObserver(this); |
| 232 MessageLoop::current()->RemoveTaskObserver(this); | 232 base::MessageLoop::current()->RemoveTaskObserver(this); |
| 233 } | 233 } |
| 234 | 234 |
| 235 virtual void WillProcessIOEvent() OVERRIDE { | 235 virtual void WillProcessIOEvent() OVERRIDE { |
| 236 if (!helper_.MessageWillBeMeasured()) | 236 if (!helper_.MessageWillBeMeasured()) |
| 237 return; | 237 return; |
| 238 helper_.StartProcessingTimers(base::TimeDelta()); | 238 helper_.StartProcessingTimers(base::TimeDelta()); |
| 239 } | 239 } |
| 240 | 240 |
| 241 virtual void DidProcessIOEvent() OVERRIDE { | 241 virtual void DidProcessIOEvent() OVERRIDE { |
| 242 helper_.EndProcessingTimers(); | 242 helper_.EndProcessingTimers(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 259 | 259 |
| 260 virtual ~IOJankObserver() {} | 260 virtual ~IOJankObserver() {} |
| 261 | 261 |
| 262 JankObserverHelper helper_; | 262 JankObserverHelper helper_; |
| 263 | 263 |
| 264 DISALLOW_COPY_AND_ASSIGN(IOJankObserver); | 264 DISALLOW_COPY_AND_ASSIGN(IOJankObserver); |
| 265 }; | 265 }; |
| 266 | 266 |
| 267 //------------------------------------------------------------------------------ | 267 //------------------------------------------------------------------------------ |
| 268 class UIJankObserver : public base::RefCountedThreadSafe<UIJankObserver>, | 268 class UIJankObserver : public base::RefCountedThreadSafe<UIJankObserver>, |
| 269 public MessageLoop::TaskObserver, | 269 public base::MessageLoop::TaskObserver, |
| 270 public MessageLoopForUI::Observer { | 270 public base::MessageLoopForUI::Observer { |
| 271 public: | 271 public: |
| 272 UIJankObserver(const char* thread_name, | 272 UIJankObserver(const char* thread_name, |
| 273 TimeDelta excessive_duration, | 273 TimeDelta excessive_duration, |
| 274 bool watchdog_enable) | 274 bool watchdog_enable) |
| 275 : helper_(thread_name, excessive_duration, watchdog_enable) {} | 275 : helper_(thread_name, excessive_duration, watchdog_enable) {} |
| 276 | 276 |
| 277 // Attaches the observer to the current thread's message loop. You can only | 277 // Attaches the observer to the current thread's message loop. You can only |
| 278 // attach to the current thread, so this function can be invoked on another | 278 // attach to the current thread, so this function can be invoked on another |
| 279 // thread to attach it. | 279 // thread to attach it. |
| 280 void AttachToCurrentThread() { | 280 void AttachToCurrentThread() { |
| 281 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); | 281 DCHECK_EQ(base::MessageLoop::current()->type(), base::MessageLoop::TYPE_UI); |
| 282 MessageLoopForUI::current()->AddObserver(this); | 282 base::MessageLoopForUI::current()->AddObserver(this); |
| 283 MessageLoop::current()->AddTaskObserver(this); | 283 base::MessageLoop::current()->AddTaskObserver(this); |
| 284 } | 284 } |
| 285 | 285 |
| 286 // Detaches the observer to the current thread's message loop. | 286 // Detaches the observer to the current thread's message loop. |
| 287 void DetachFromCurrentThread() { | 287 void DetachFromCurrentThread() { |
| 288 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); | 288 DCHECK_EQ(base::MessageLoop::current()->type(), base::MessageLoop::TYPE_UI); |
| 289 MessageLoop::current()->RemoveTaskObserver(this); | 289 base::MessageLoop::current()->RemoveTaskObserver(this); |
| 290 MessageLoopForUI::current()->RemoveObserver(this); | 290 base::MessageLoopForUI::current()->RemoveObserver(this); |
| 291 } | 291 } |
| 292 | 292 |
| 293 virtual void WillProcessTask(const base::PendingTask& pending_task) OVERRIDE { | 293 virtual void WillProcessTask(const base::PendingTask& pending_task) OVERRIDE { |
| 294 if (!helper_.MessageWillBeMeasured()) | 294 if (!helper_.MessageWillBeMeasured()) |
| 295 return; | 295 return; |
| 296 base::TimeTicks now = base::TimeTicks::Now(); | 296 base::TimeTicks now = base::TimeTicks::Now(); |
| 297 const base::TimeDelta queueing_time = now - pending_task.time_posted; | 297 const base::TimeDelta queueing_time = now - pending_task.time_posted; |
| 298 helper_.StartProcessingTimers(queueing_time); | 298 helper_.StartProcessingTimers(queueing_time); |
| 299 } | 299 } |
| 300 | 300 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 delete ui_observer; | 416 delete ui_observer; |
| 417 ui_observer = NULL; | 417 ui_observer = NULL; |
| 418 } | 418 } |
| 419 if (io_observer) { | 419 if (io_observer) { |
| 420 // IO thread can't be running when we remove observers. | 420 // IO thread can't be running when we remove observers. |
| 421 DCHECK((!g_browser_process) || !(g_browser_process->io_thread())); | 421 DCHECK((!g_browser_process) || !(g_browser_process->io_thread())); |
| 422 delete io_observer; | 422 delete io_observer; |
| 423 io_observer = NULL; | 423 io_observer = NULL; |
| 424 } | 424 } |
| 425 } | 425 } |
| OLD | NEW |