| Index: chrome/browser/jankometer.cc
|
| diff --git a/chrome/browser/jankometer.cc b/chrome/browser/jankometer.cc
|
| index c7bb0a5acafb2da953fe926a361726bccc7a690a..14028c73e5d21abc7d02b25a8af08fdbe1683c1a 100644
|
| --- a/chrome/browser/jankometer.cc
|
| +++ b/chrome/browser/jankometer.cc
|
| @@ -1,4 +1,4 @@
|
| -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
| +// Copyright (c) 2009 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| @@ -16,9 +16,14 @@
|
| #include "base/thread.h"
|
| #include "base/time.h"
|
| #include "base/watchdog.h"
|
| +#include "build/build_config.h"
|
| #include "chrome/browser/browser_process.h"
|
| #include "chrome/common/chrome_switches.h"
|
|
|
| +#if defined(OS_LINUX)
|
| +#include "chrome/common/gtk_util.h"
|
| +#endif
|
| +
|
| using base::TimeDelta;
|
| using base::TimeTicks;
|
|
|
| @@ -109,33 +114,20 @@ class JankObserver : public base::RefCountedThreadSafe<JankObserver>,
|
| MessageLoopForUI::current()->RemoveObserver(this);
|
| }
|
|
|
| - void WillProcessMessage(const MSG& msg) {
|
| - begin_process_message_ = TimeTicks::Now();
|
| -
|
| - // GetMessageTime returns a LONG (signed 32-bit) and GetTickCount returns
|
| - // a DWORD (unsigned 32-bit). They both wrap around when the time is longer
|
| - // than they can hold. I'm not sure if GetMessageTime wraps around to 0,
|
| - // or if the original time comes from GetTickCount, it might wrap around
|
| - // to -1.
|
| - //
|
| - // Therefore, I cast to DWORD so if it wraps to -1 we will correct it. If
|
| - // it doesn't, then our time delta will be negative if a message happens
|
| - // to straddle the wraparound point, it will still be OK.
|
| - DWORD cur_message_issue_time = static_cast<DWORD>(msg.time);
|
| - DWORD cur_time = GetTickCount();
|
| - queueing_time_ = TimeDelta::FromMilliseconds(cur_time
|
| - - cur_message_issue_time);
|
| + void StartProcessingTimers() {
|
| // Simulate arming when the message entered the queue.
|
| total_time_watchdog_.ArmSomeTimeDeltaAgo(queueing_time_);
|
| if (queueing_time_ > MaxMessageDelay_) {
|
| // Message is too delayed.
|
| queueing_delay_counter_.Increment();
|
| +#if defined(OS_WIN)
|
| if (kPlaySounds)
|
| MessageBeep(MB_ICONASTERISK);
|
| +#endif
|
| }
|
| }
|
|
|
| - void DidProcessMessage(const MSG& msg) {
|
| + void EndProcessingTimers() {
|
| total_time_watchdog_.Disarm();
|
| TimeTicks now = TimeTicks::Now();
|
| if (begin_process_message_ != TimeTicks()) {
|
| @@ -147,14 +139,62 @@ class JankObserver : public base::RefCountedThreadSafe<JankObserver>,
|
| TimeDelta::FromMilliseconds(kMaxMessageProcessingMs)) {
|
| // Message took too long to process.
|
| slow_processing_counter_.Increment();
|
| +#if defined(OS_WIN)
|
| if (kPlaySounds)
|
| MessageBeep(MB_ICONHAND);
|
| +#endif
|
| }
|
| }
|
|
|
| +#if defined(OS_WIN)
|
| + void WillProcessMessage(const MSG& msg) {
|
| + begin_process_message_ = TimeTicks::Now();
|
| +
|
| + // GetMessageTime returns a LONG (signed 32-bit) and GetTickCount returns
|
| + // a DWORD (unsigned 32-bit). They both wrap around when the time is longer
|
| + // than they can hold. I'm not sure if GetMessageTime wraps around to 0,
|
| + // or if the original time comes from GetTickCount, it might wrap around
|
| + // to -1.
|
| + //
|
| + // Therefore, I cast to DWORD so if it wraps to -1 we will correct it. If
|
| + // it doesn't, then our time delta will be negative if a message happens
|
| + // to straddle the wraparound point, it will still be OK.
|
| + DWORD cur_message_issue_time = static_cast<DWORD>(msg.time);
|
| + DWORD cur_time = GetTickCount();
|
| + queueing_time_ =
|
| + base::TimeDelta::FromMilliseconds(cur_time - cur_message_issue_time);
|
| +
|
| + StartProcessingTimers();
|
| + }
|
| +
|
| + void DidProcessMessage(const MSG& msg) {
|
| + EndProcessingTimers();
|
| + }
|
| +
|
| +#elif defined(OS_LINUX)
|
| + void WillProcessEvent(GdkEvent* event) {
|
| + begin_process_message_ = TimeTicks::Now();
|
| + guint event_time = event_utils::GetGdkEventTime(event);
|
| + // TODO(evanm): it is not clear what that event_time is relative to!
|
| + queueing_time_ = false // TODO: We ignore event_time for now.
|
| + ? base::TimeDelta::FromMilliseconds(event_time)
|
| + : base::TimeDelta::FromMilliseconds(0);
|
| + StartProcessingTimers();
|
| + }
|
| +
|
| + void DidProcessEvent(GdkEvent* event) {
|
| + EndProcessingTimers();
|
| + }
|
| +#endif
|
| +
|
| private:
|
| const TimeDelta MaxMessageDelay_;
|
| +
|
| + // Time at which the current message processing began.
|
| TimeTicks begin_process_message_;
|
| +
|
| + // Time the current message spent in the queue -- delta between message
|
| + // construction time and message processing time.
|
| TimeDelta queueing_time_;
|
|
|
| // Counters for the two types of jank we measure.
|
| @@ -173,7 +213,7 @@ JankObserver* io_observer = NULL;
|
|
|
| } // namespace
|
|
|
| -void InstallJankometer(const CommandLine &parsed_command_line) {
|
| +void InstallJankometer(const CommandLine& parsed_command_line) {
|
| if (ui_observer || io_observer) {
|
| NOTREACHED() << "Initializing jank-o-meter twice";
|
| return;
|
|
|