diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-08 03:58:29 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-08 03:58:29 +0000 |
commit | 16e0efd89b890932ff32fb612228b48dea4371fa (patch) | |
tree | e8de88cf77fbc568fae0d377392ded1df0cb33f7 /chrome/browser/jankometer.cc | |
parent | 8351861274bcfad6e2c3580f7256d8d863ac4f17 (diff) | |
download | chromium_src-16e0efd89b890932ff32fb612228b48dea4371fa.zip chromium_src-16e0efd89b890932ff32fb612228b48dea4371fa.tar.gz chromium_src-16e0efd89b890932ff32fb612228b48dea4371fa.tar.bz2 |
linux: port Jankometer
Originally I had split it into multiple files, but I think it's
cleaner to just use one.
(I want to use this for measuring plugin jank.)
BUG=8077
Review URL: http://codereview.chromium.org/155194
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20130 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/jankometer.cc')
-rw-r--r-- | chrome/browser/jankometer.cc | 81 |
1 files changed, 62 insertions, 19 deletions
diff --git a/chrome/browser/jankometer.cc b/chrome/browser/jankometer.cc index c7bb0a5..1c73d72 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,24 @@ 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); + // Called when a message has just begun processing, initializes + // per-message variables and timers. + 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) { + // Called when a message has just finished processing, finalizes + // per-message variables and timers. + void EndProcessingTimers() { total_time_watchdog_.Disarm(); TimeTicks now = TimeTicks::Now(); if (begin_process_message_ != TimeTicks()) { @@ -147,14 +143,61 @@ 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) + virtual 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(); + } + + virtual void DidProcessMessage(const MSG& msg) { + EndProcessingTimers(); + } +#elif defined(OS_LINUX) + virtual void WillProcessEvent(GdkEvent* event) { + begin_process_message_ = TimeTicks::Now(); + // TODO(evanm): we want to set queueing_time_ using + // event_utils::GetGdkEventTime, but how do you convert that info + // into a delta? + // guint event_time = event_utils::GetGdkEventTime(event); + queueing_time_ = base::TimeDelta::FromMilliseconds(0); + StartProcessingTimers(); + } + + virtual 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 +216,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; |