summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-26 23:40:48 +0000
committerdavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-26 23:40:48 +0000
commit02468668f05673052602812d9a9b1846f97bfad3 (patch)
treea0b1596402ece05bb7a23d6053c6543ec6b30438
parent88424e6e8ed416c21e92bc8efc4b2658f89b7329 (diff)
downloadchromium_src-02468668f05673052602812d9a9b1846f97bfad3.zip
chromium_src-02468668f05673052602812d9a9b1846f97bfad3.tar.gz
chromium_src-02468668f05673052602812d9a9b1846f97bfad3.tar.bz2
Added task to Observer methods
By adding the task to the observer methods and GetBirthPlace() to Tracked it makes it possible to register an observer that can print more information about the tasks as they are being processed. BUG=NONE TEST=MessageLoopTest.* Review URL: http://codereview.chromium.org/4081003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63983 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/message_loop.cc4
-rw-r--r--base/message_loop.h4
-rw-r--r--base/message_loop_unittest.cc6
-rw-r--r--base/tracked.cc8
-rw-r--r--base/tracked.h1
-rw-r--r--chrome/browser/jankometer.cc12
6 files changed, 23 insertions, 12 deletions
diff --git a/base/message_loop.cc b/base/message_loop.cc
index f335ca1..b926c79 100644
--- a/base/message_loop.cc
+++ b/base/message_loop.cc
@@ -412,9 +412,9 @@ void MessageLoop::RunTask(Task* task) {
HistogramEvent(kTaskRunEvent);
FOR_EACH_OBSERVER(TaskObserver, task_observers_,
- WillProcessTask(task->tracked_birth_time()));
+ WillProcessTask(task));
task->Run();
- FOR_EACH_OBSERVER(TaskObserver, task_observers_, DidProcessTask());
+ FOR_EACH_OBSERVER(TaskObserver, task_observers_, DidProcessTask(task));
delete task;
nestable_tasks_allowed_ = true;
diff --git a/base/message_loop.h b/base/message_loop.h
index f4b1a4d..b182ace 100644
--- a/base/message_loop.h
+++ b/base/message_loop.h
@@ -75,10 +75,10 @@ class MessageLoop : public base::MessagePump::Delegate {
TaskObserver();
// This method is called before processing a task.
- virtual void WillProcessTask(base::TimeTicks birth_time) = 0;
+ virtual void WillProcessTask(const Task* task) = 0;
// This method is called after processing a task.
- virtual void DidProcessTask() = 0;
+ virtual void DidProcessTask(const Task* task) = 0;
protected:
virtual ~TaskObserver();
diff --git a/base/message_loop_unittest.cc b/base/message_loop_unittest.cc
index 741eb71..8cce8ea 100644
--- a/base/message_loop_unittest.cc
+++ b/base/message_loop_unittest.cc
@@ -1488,14 +1488,16 @@ class DummyTaskObserver : public MessageLoop::TaskObserver {
virtual ~DummyTaskObserver() {}
- virtual void WillProcessTask(base::TimeTicks /* birth_time */) {
+ virtual void WillProcessTask(const Task* task) {
num_tasks_started_++;
+ EXPECT_TRUE(task != NULL);
EXPECT_LE(num_tasks_started_, num_tasks_);
EXPECT_EQ(num_tasks_started_, num_tasks_processed_ + 1);
}
- virtual void DidProcessTask() {
+ virtual void DidProcessTask(const Task* task) {
num_tasks_processed_++;
+ EXPECT_TRUE(task != NULL);
EXPECT_LE(num_tasks_started_, num_tasks_);
EXPECT_EQ(num_tasks_started_, num_tasks_processed_);
}
diff --git a/base/tracked.cc b/base/tracked.cc
index 8ae7447..767f072 100644
--- a/base/tracked.cc
+++ b/base/tracked.cc
@@ -65,6 +65,10 @@ void Location::WriteFunctionName(std::string* output) const {
Tracked::Tracked() {}
Tracked::~Tracked() {}
void Tracked::SetBirthPlace(const Location& from_here) {}
+const Location Tracked::GetBirthPlace() const {
+ static Location kNone("NoFunctionName", "NeedToSetBirthPlace", -1);
+ return kNone;
+}
bool Tracked::MissingBirthplace() const { return false; }
void Tracked::ResetBirthTime() {}
@@ -96,6 +100,10 @@ void Tracked::SetBirthPlace(const Location& from_here) {
tracked_births_ = current_thread_data->TallyABirth(from_here);
}
+const Location Tracked::GetBirthPlace() const {
+ return tracked_births_->location();
+}
+
void Tracked::ResetBirthTime() {
tracked_birth_time_ = TimeTicks::Now();
}
diff --git a/base/tracked.h b/base/tracked.h
index 7af05ff..b4f6e36 100644
--- a/base/tracked.h
+++ b/base/tracked.h
@@ -94,6 +94,7 @@ class Tracked {
// Used to record the FROM_HERE location of a caller.
void SetBirthPlace(const Location& from_here);
+ const Location GetBirthPlace() const;
// When a task sits around a long time, such as in a timer, or object watcher,
// this method should be called when the task becomes active, and its
diff --git a/chrome/browser/jankometer.cc b/chrome/browser/jankometer.cc
index a9a99b0..e58b71a 100644
--- a/chrome/browser/jankometer.cc
+++ b/chrome/browser/jankometer.cc
@@ -206,13 +206,13 @@ class IOJankObserver : public base::RefCountedThreadSafe<IOJankObserver>,
helper_.EndProcessingTimers();
}
- virtual void WillProcessTask(base::TimeTicks birth_time) {
+ virtual void WillProcessTask(const Task* task) {
base::TimeTicks now = base::TimeTicks::Now();
- const base::TimeDelta queueing_time = now - birth_time;
+ const base::TimeDelta queueing_time = now - task->tracked_birth_time();
helper_.StartProcessingTimers(queueing_time);
}
- virtual void DidProcessTask() {
+ virtual void DidProcessTask(const Task* task) {
helper_.EndProcessingTimers();
}
@@ -250,13 +250,13 @@ class UIJankObserver : public base::RefCountedThreadSafe<UIJankObserver>,
MessageLoopForUI::current()->RemoveObserver(this);
}
- virtual void WillProcessTask(base::TimeTicks birth_time) {
+ virtual void WillProcessTask(const Task* task) {
base::TimeTicks now = base::TimeTicks::Now();
- const base::TimeDelta queueing_time = now - birth_time;
+ const base::TimeDelta queueing_time = now - task->tracked_birth_time();
helper_.StartProcessingTimers(queueing_time);
}
- virtual void DidProcessTask() {
+ virtual void DidProcessTask(const Task* task) {
helper_.EndProcessingTimers();
}