| Index: cc/debug/worker_thread_cost_tracker.cc
|
| diff --git a/cc/debug/worker_thread_cost_tracker.cc b/cc/debug/worker_thread_cost_tracker.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..780dc71ad631b854fc4e2fa8cab14a98cbf5bea3
|
| --- /dev/null
|
| +++ b/cc/debug/worker_thread_cost_tracker.cc
|
| @@ -0,0 +1,59 @@
|
| +// Copyright 2014 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.
|
| +
|
| +#include "cc/debug/worker_thread_cost_tracker.h"
|
| +
|
| +#include "base/logging.h"
|
| +
|
| +namespace cc {
|
| +
|
| +WorkerThreadCostTracker::WorkerThreadCostTracker() : source_frame_number_(0) {
|
| +}
|
| +
|
| +WorkerThreadCostTracker::~WorkerThreadCostTracker() {
|
| +}
|
| +
|
| +scoped_ptr<WorkerThreadCostTracker::Probe>
|
| +WorkerThreadCostTracker::CreateProbe() {
|
| + return make_scoped_ptr(new Probe(this, source_frame_number_));
|
| +}
|
| +
|
| +WorkerThreadCostTracker::Probe::Probe(WorkerThreadCostTracker* tracker,
|
| + int tracked_source_frame_number)
|
| + : tracker_(tracker),
|
| + tracked_source_frame_number_(tracked_source_frame_number),
|
| + tracker_thread_id_(base::PlatformThread::CurrentId()),
|
| + started_(false) {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| +}
|
| +
|
| +WorkerThreadCostTracker::Probe::~Probe() {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| + DCHECK(!started_);
|
| + if (tracker_->source_frame_number_ == tracked_source_frame_number_)
|
| + tracker_->add_cost(cost_);
|
| +}
|
| +
|
| +void WorkerThreadCostTracker::Probe::Start(int source_frame_number) {
|
| + DCHECK(!started_);
|
| + // If this start request is for a wrong frame number, abort.
|
| + if (source_frame_number != tracked_source_frame_number_)
|
| + return;
|
| + // If this is being run on the same thread as the main tracker (i.e. this is
|
| + // not a worker thread), abort.
|
| + if (tracker_thread_id_ == base::PlatformThread::CurrentId())
|
| + return;
|
| +
|
| + start_ = base::TimeTicks::HighResNow();
|
| + started_ = true;
|
| +}
|
| +
|
| +void WorkerThreadCostTracker::Probe::Stop() {
|
| + if (!started_)
|
| + return;
|
| + cost_ = base::TimeTicks::HighResNow() - start_;
|
| + started_ = false;
|
| +}
|
| +
|
| +} // namespace cc
|
|
|