Commit 9e9999d8 authored by jar@chromium.org's avatar jar@chromium.org

Support profiling of tasks run as sequenced_tasks

Mimic code seen in message_loop.cc (since these tasks are run on named
threads) to support tracking of sequenced worker pool runs of tasks.
We surround the *.Run() method with a call to get the time before we
start, and then call to tally the time it took to run after task.Run()
returns.


r=brettw
BUG=139035

Review URL: https://chromiumcodereview.appspot.com/10825022

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148986 0039d316-1c4b-4281-b951-d872f2087c98
parent da4ce91a
...@@ -35,16 +35,21 @@ namespace base { ...@@ -35,16 +35,21 @@ namespace base {
namespace { namespace {
struct SequencedTask { struct SequencedTask : public TrackingInfo {
SequencedTask() SequencedTask()
: sequence_token_id(0), : sequence_token_id(0),
shutdown_behavior(SequencedWorkerPool::BLOCK_SHUTDOWN) {} shutdown_behavior(SequencedWorkerPool::BLOCK_SHUTDOWN) {}
explicit SequencedTask(const tracked_objects::Location& from_here)
: base::TrackingInfo(from_here, TimeTicks()),
sequence_token_id(0),
shutdown_behavior(SequencedWorkerPool::BLOCK_SHUTDOWN) {}
~SequencedTask() {} ~SequencedTask() {}
int sequence_token_id; int sequence_token_id;
SequencedWorkerPool::WorkerShutdown shutdown_behavior; SequencedWorkerPool::WorkerShutdown shutdown_behavior;
tracked_objects::Location location; tracked_objects::Location posted_from;
Closure task; Closure task;
}; };
...@@ -481,10 +486,10 @@ bool SequencedWorkerPool::Inner::PostTask( ...@@ -481,10 +486,10 @@ bool SequencedWorkerPool::Inner::PostTask(
WorkerShutdown shutdown_behavior, WorkerShutdown shutdown_behavior,
const tracked_objects::Location& from_here, const tracked_objects::Location& from_here,
const Closure& task) { const Closure& task) {
SequencedTask sequenced; SequencedTask sequenced(from_here);
sequenced.sequence_token_id = sequence_token.id_; sequenced.sequence_token_id = sequence_token.id_;
sequenced.shutdown_behavior = shutdown_behavior; sequenced.shutdown_behavior = shutdown_behavior;
sequenced.location = from_here; sequenced.posted_from = from_here;
sequenced.task = task; sequenced.task = task;
int create_thread_id = 0; int create_thread_id = 0;
...@@ -614,8 +619,14 @@ void SequencedWorkerPool::Inner::ThreadLoop(Worker* this_worker) { ...@@ -614,8 +619,14 @@ void SequencedWorkerPool::Inner::ThreadLoop(Worker* this_worker) {
this_worker->set_running_sequence( this_worker->set_running_sequence(
SequenceToken(task.sequence_token_id)); SequenceToken(task.sequence_token_id));
tracked_objects::TrackedTime start_time =
tracked_objects::ThreadData::NowForStartOfRun(task.birth_tally);
task.task.Run(); task.task.Run();
tracked_objects::ThreadData::TallyRunOnNamedThreadIfTracking(task,
start_time, tracked_objects::ThreadData::NowForEndOfRun());
this_worker->set_running_sequence(SequenceToken()); this_worker->set_running_sequence(SequenceToken());
// Make sure our task is erased outside the lock for the same reason // Make sure our task is erased outside the lock for the same reason
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "base/tracking_info.h" #include "base/tracking_info.h"
#include <stddef.h>
#include "base/tracked_objects.h" #include "base/tracked_objects.h"
namespace base { namespace base {
TrackingInfo::TrackingInfo()
: birth_tally(NULL) {
}
TrackingInfo::TrackingInfo( TrackingInfo::TrackingInfo(
const tracked_objects::Location& posted_from, const tracked_objects::Location& posted_from,
base::TimeTicks delayed_run_time) base::TimeTicks delayed_run_time)
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -22,6 +22,7 @@ namespace base { ...@@ -22,6 +22,7 @@ namespace base {
// This structure is copied around by value. // This structure is copied around by value.
struct BASE_EXPORT TrackingInfo { struct BASE_EXPORT TrackingInfo {
TrackingInfo();
TrackingInfo(const tracked_objects::Location& posted_from, TrackingInfo(const tracked_objects::Location& posted_from,
base::TimeTicks delayed_run_time); base::TimeTicks delayed_run_time);
~TrackingInfo(); ~TrackingInfo();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment