diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-08 20:53:41 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-08 20:53:41 +0000 |
commit | e81ed0577b287a1346c06fc5bbd565e429f3059e (patch) | |
tree | 23fabc108bbdea823d45de860ed48f077e2a9436 /base/message_pump_libevent.h | |
parent | 5849ebff0fb2bd52d9f5667fc7dd15453c11be0a (diff) | |
download | chromium_src-e81ed0577b287a1346c06fc5bbd565e429f3059e.zip chromium_src-e81ed0577b287a1346c06fc5bbd565e429f3059e.tar.gz chromium_src-e81ed0577b287a1346c06fc5bbd565e429f3059e.tar.bz2 |
Jankometer: Generalize the code more. Add better support for monitoring IO thread.
Previously, the Jankometer only monitored windows messages on the UI thread (or gtk events).
I've added observers for tasks and IO events. This lets us monitor all events on UI & IO threads (UI messages, all Tasks, and IO events).
Replaces the JankObserver with a UIJankObserver and an IOJankObserver.
Shares common code in JankObserverHelper. The JankObserverHelper and JankWatchdog are generic enough that they can probably move out to chrome/common and be reused by the renderer.
Review URL: http://codereview.chromium.org/2098020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49188 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/message_pump_libevent.h')
-rw-r--r-- | base/message_pump_libevent.h | 86 |
1 files changed, 60 insertions, 26 deletions
diff --git a/base/message_pump_libevent.h b/base/message_pump_libevent.h index 8e2f77c..6516128 100644 --- a/base/message_pump_libevent.h +++ b/base/message_pump_libevent.h @@ -5,7 +5,9 @@ #ifndef BASE_MESSAGE_PUMP_LIBEVENT_H_ #define BASE_MESSAGE_PUMP_LIBEVENT_H_ +#include "base/basictypes.h" #include "base/message_pump.h" +#include "base/observer_list.h" #include "base/time.h" // Declare structs we need from libevent.h rather than including it @@ -18,33 +20,19 @@ namespace base { // TODO(dkegel): add support for background file IO somehow class MessagePumpLibevent : public MessagePump { public: + class IOObserver { + public: + IOObserver() {} - // Object returned by WatchFileDescriptor to manage further watching. - class FileDescriptorWatcher { - public: - FileDescriptorWatcher(); - ~FileDescriptorWatcher(); // Implicitly calls StopWatchingFileDescriptor. - - // NOTE: These methods aren't called StartWatching()/StopWatching() to - // avoid confusion with the win32 ObjectWatcher class. - - // Stop watching the FD, always safe to call. No-op if there's nothing - // to do. - bool StopWatchingFileDescriptor(); - - private: - // Called by MessagePumpLibevent, ownership of |e| is transferred to this - // object. - void Init(event* e, bool is_persistent); - - // Used by MessagePumpLibevent to take ownership of event_. - event *ReleaseEvent(); - friend class MessagePumpLibevent; - - private: - bool is_persistent_; // false if this event is one-shot. - event* event_; - DISALLOW_COPY_AND_ASSIGN(FileDescriptorWatcher); + // An IOObserver is an object that receives IO notifications from the + // MessagePump. + // + // NOTE: An IOObserver implementation should be extremely fast! + virtual void WillProcessIOEvent() = 0; + virtual void DidProcessIOEvent() = 0; + + protected: + virtual ~IOObserver() {} }; // Used with WatchFileDescptor to asynchronously monitor the I/O readiness of @@ -58,6 +46,45 @@ class MessagePumpLibevent : public MessagePump { virtual void OnFileCanWriteWithoutBlocking(int fd) = 0; }; + // Object returned by WatchFileDescriptor to manage further watching. + class FileDescriptorWatcher { + public: + FileDescriptorWatcher(); + ~FileDescriptorWatcher(); // Implicitly calls StopWatchingFileDescriptor. + + // NOTE: These methods aren't called StartWatching()/StopWatching() to + // avoid confusion with the win32 ObjectWatcher class. + + // Stop watching the FD, always safe to call. No-op if there's nothing + // to do. + bool StopWatchingFileDescriptor(); + + private: + friend class MessagePumpLibevent; + + // Called by MessagePumpLibevent, ownership of |e| is transferred to this + // object. + void Init(event* e, bool is_persistent); + + // Used by MessagePumpLibevent to take ownership of event_. + event *ReleaseEvent(); + + void set_pump(MessagePumpLibevent* pump) { pump_ = pump; } + MessagePumpLibevent* pump() { return pump_; } + + void set_watcher(Watcher* watcher) { watcher_ = watcher; } + + void OnFileCanReadWithoutBlocking(int fd, MessagePumpLibevent* pump); + void OnFileCanWriteWithoutBlocking(int fd, MessagePumpLibevent* pump); + + bool is_persistent_; // false if this event is one-shot. + event* event_; + MessagePumpLibevent* pump_; + Watcher* watcher_; + + DISALLOW_COPY_AND_ASSIGN(FileDescriptorWatcher); + }; + MessagePumpLibevent(); virtual ~MessagePumpLibevent(); @@ -84,6 +111,9 @@ class MessagePumpLibevent : public MessagePump { FileDescriptorWatcher *controller, Watcher *delegate); + void AddIOObserver(IOObserver* obs); + void RemoveIOObserver(IOObserver* obs); + // MessagePump methods: virtual void Run(Delegate* delegate); virtual void Quit(); @@ -91,6 +121,8 @@ class MessagePumpLibevent : public MessagePump { virtual void ScheduleDelayedWork(const Time& delayed_work_time); private: + void WillProcessIOEvent(); + void DidProcessIOEvent(); // Risky part of constructor. Returns true on success. bool Init(); @@ -122,6 +154,8 @@ class MessagePumpLibevent : public MessagePump { // ... libevent wrapper for read end event* wakeup_event_; + ObserverList<IOObserver> io_observers_; + DISALLOW_COPY_AND_ASSIGN(MessagePumpLibevent); }; |