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" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/metrics/stats_counters.h" | 15 #include "base/metrics/stats_counters.h" |
| 16 #include "base/pending_task.h" |
16 #include "base/string_util.h" | 17 #include "base/string_util.h" |
17 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
18 #include "base/threading/watchdog.h" | 19 #include "base/threading/watchdog.h" |
19 #include "base/time.h" | 20 #include "base/time.h" |
20 #include "build/build_config.h" | 21 #include "build/build_config.h" |
21 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
22 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
23 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
24 | 25 |
25 using base::TimeDelta; | 26 using base::TimeDelta; |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 virtual void WillProcessIOEvent() OVERRIDE { | 235 virtual void WillProcessIOEvent() OVERRIDE { |
235 if (!helper_.MessageWillBeMeasured()) | 236 if (!helper_.MessageWillBeMeasured()) |
236 return; | 237 return; |
237 helper_.StartProcessingTimers(base::TimeDelta()); | 238 helper_.StartProcessingTimers(base::TimeDelta()); |
238 } | 239 } |
239 | 240 |
240 virtual void DidProcessIOEvent() OVERRIDE { | 241 virtual void DidProcessIOEvent() OVERRIDE { |
241 helper_.EndProcessingTimers(); | 242 helper_.EndProcessingTimers(); |
242 } | 243 } |
243 | 244 |
244 virtual void WillProcessTask(base::TimeTicks time_posted) OVERRIDE { | 245 virtual void WillProcessTask(const base::PendingTask& pending_task) OVERRIDE { |
245 if (!helper_.MessageWillBeMeasured()) | 246 if (!helper_.MessageWillBeMeasured()) |
246 return; | 247 return; |
247 base::TimeTicks now = base::TimeTicks::Now(); | 248 base::TimeTicks now = base::TimeTicks::Now(); |
248 const base::TimeDelta queueing_time = now - time_posted; | 249 const base::TimeDelta queueing_time = now - pending_task.time_posted; |
249 helper_.StartProcessingTimers(queueing_time); | 250 helper_.StartProcessingTimers(queueing_time); |
250 } | 251 } |
251 | 252 |
252 virtual void DidProcessTask(base::TimeTicks time_posted) OVERRIDE { | 253 virtual void DidProcessTask(const base::PendingTask& pending_task) OVERRIDE { |
253 helper_.EndProcessingTimers(); | 254 helper_.EndProcessingTimers(); |
254 } | 255 } |
255 | 256 |
256 private: | 257 private: |
257 friend class base::RefCountedThreadSafe<IOJankObserver>; | 258 friend class base::RefCountedThreadSafe<IOJankObserver>; |
258 | 259 |
259 ~IOJankObserver() {} | 260 ~IOJankObserver() {} |
260 | 261 |
261 JankObserverHelper helper_; | 262 JankObserverHelper helper_; |
262 | 263 |
(...skipping 19 matching lines...) Expand all Loading... |
282 MessageLoop::current()->AddTaskObserver(this); | 283 MessageLoop::current()->AddTaskObserver(this); |
283 } | 284 } |
284 | 285 |
285 // Detaches the observer to the current thread's message loop. | 286 // Detaches the observer to the current thread's message loop. |
286 void DetachFromCurrentThread() { | 287 void DetachFromCurrentThread() { |
287 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); | 288 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); |
288 MessageLoop::current()->RemoveTaskObserver(this); | 289 MessageLoop::current()->RemoveTaskObserver(this); |
289 MessageLoopForUI::current()->RemoveObserver(this); | 290 MessageLoopForUI::current()->RemoveObserver(this); |
290 } | 291 } |
291 | 292 |
292 virtual void WillProcessTask(base::TimeTicks time_posted) OVERRIDE { | 293 virtual void WillProcessTask(const base::PendingTask& pending_task) OVERRIDE { |
293 if (!helper_.MessageWillBeMeasured()) | 294 if (!helper_.MessageWillBeMeasured()) |
294 return; | 295 return; |
295 base::TimeTicks now = base::TimeTicks::Now(); | 296 base::TimeTicks now = base::TimeTicks::Now(); |
296 const base::TimeDelta queueing_time = now - time_posted; | 297 const base::TimeDelta queueing_time = now - pending_task.time_posted; |
297 helper_.StartProcessingTimers(queueing_time); | 298 helper_.StartProcessingTimers(queueing_time); |
298 } | 299 } |
299 | 300 |
300 virtual void DidProcessTask(base::TimeTicks time_posted) OVERRIDE { | 301 virtual void DidProcessTask(const base::PendingTask& pending_task) OVERRIDE { |
301 helper_.EndProcessingTimers(); | 302 helper_.EndProcessingTimers(); |
302 } | 303 } |
303 | 304 |
304 #if defined(OS_WIN) | 305 #if defined(OS_WIN) |
305 virtual base::EventStatus WillProcessEvent( | 306 virtual base::EventStatus WillProcessEvent( |
306 const base::NativeEvent& event) OVERRIDE { | 307 const base::NativeEvent& event) OVERRIDE { |
307 if (!helper_.MessageWillBeMeasured()) | 308 if (!helper_.MessageWillBeMeasured()) |
308 return base::EVENT_CONTINUE; | 309 return base::EVENT_CONTINUE; |
309 // GetMessageTime returns a LONG (signed 32-bit) and GetTickCount returns | 310 // GetMessageTime returns a LONG (signed 32-bit) and GetTickCount returns |
310 // a DWORD (unsigned 32-bit). They both wrap around when the time is longer | 311 // a DWORD (unsigned 32-bit). They both wrap around when the time is longer |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 delete ui_observer; | 416 delete ui_observer; |
416 ui_observer = NULL; | 417 ui_observer = NULL; |
417 } | 418 } |
418 if (io_observer) { | 419 if (io_observer) { |
419 // IO thread can't be running when we remove observers. | 420 // IO thread can't be running when we remove observers. |
420 DCHECK((!g_browser_process) || !(g_browser_process->io_thread())); | 421 DCHECK((!g_browser_process) || !(g_browser_process->io_thread())); |
421 delete io_observer; | 422 delete io_observer; |
422 io_observer = NULL; | 423 io_observer = NULL; |
423 } | 424 } |
424 } | 425 } |
OLD | NEW |