Skip to content

Commit

Permalink
Making BeginFrameArgs work with TRACE_EVENT system.
Browse files Browse the repository at this point in the history
 * Added ToValue() method on BeginFrameArgs.
 * Added a ToTrace method inside cc/traced_value.h for easy conversion, just do a ToTrace(XXX) of anything which has a ToValue() method.
 * Rename Scheduler::StateAsValue to AsValue so it works with above.

BUG=371223

Review URL: https://codereview.chromium.org/270703004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269487 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
mithro@mithis.com committed May 10, 2014
1 parent 9d70de1 commit fc441c6
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 31 deletions.
11 changes: 11 additions & 0 deletions cc/debug/traced_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ class TracedValue : public base::debug::ConvertableToTraceFormat {
DISALLOW_COPY_AND_ASSIGN(TracedValue);
};

template <class T>
static scoped_refptr<base::debug::ConvertableToTraceFormat> ToTrace(T* t) {
return TracedValue::FromValue(t->AsValue().release());
}

template <class T>
static scoped_refptr<base::debug::ConvertableToTraceFormat> ToTrace(
const T& t) {
return ToTrace(&t);
}

} // namespace cc

#endif // CC_DEBUG_TRACED_VALUE_H_
10 changes: 10 additions & 0 deletions cc/output/begin_frame_args.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/json/json_writer.h"
#include "cc/output/begin_frame_args.h"
#include "ui/gfx/frame_time.h"

Expand All @@ -27,6 +28,15 @@ BeginFrameArgs BeginFrameArgs::Create(base::TimeTicks frame_time,
return BeginFrameArgs(frame_time, deadline, interval);
}

scoped_ptr<base::Value> BeginFrameArgs::AsValue() const {
scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue);
state->SetString("type", "BeginFrameArgs");
state->SetDouble("frame_time_us", frame_time.ToInternalValue());
state->SetDouble("deadline_us", deadline.ToInternalValue());
state->SetDouble("interval_us", interval.InMicroseconds());
return state.PassAs<base::Value>();
}

BeginFrameArgs BeginFrameArgs::CreateForSynchronousCompositor() {
// For WebView/SynchronousCompositor, we always want to draw immediately,
// so we set the deadline to 0 and guess that the interval is 16 milliseconds.
Expand Down
3 changes: 3 additions & 0 deletions cc/output/begin_frame_args.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define CC_OUTPUT_BEGIN_FRAME_ARGS_H_

#include "base/time/time.h"
#include "base/values.h"
#include "cc/base/cc_export.h"

namespace cc {
Expand Down Expand Up @@ -37,6 +38,8 @@ struct CC_EXPORT BeginFrameArgs {

bool IsValid() const { return interval >= base::TimeDelta(); }

scoped_ptr<base::Value> AsValue() const;

base::TimeTicks frame_time;
base::TimeTicks deadline;
base::TimeDelta interval;
Expand Down
14 changes: 8 additions & 6 deletions cc/scheduler/scheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ void Scheduler::SetupPollingMechanisms(bool needs_begin_frame) {
// If the scheduler is busy, we queue the BeginFrame to be handled later as
// a BeginRetroFrame.
void Scheduler::BeginFrame(const BeginFrameArgs& args) {
TRACE_EVENT1("cc", "Scheduler::BeginFrame", "frame_time", args.frame_time);
TRACE_EVENT1("cc", "Scheduler::BeginFrame", "args", ToTrace(args));
DCHECK(settings_.throttle_frame_production);

bool should_defer_begin_frame;
Expand Down Expand Up @@ -488,8 +488,7 @@ void Scheduler::PostBeginRetroFrameIfNeeded() {
// for a BeginMainFrame+activation to complete before it times out and draws
// any asynchronous animation and scroll/pinch updates.
void Scheduler::BeginImplFrame(const BeginFrameArgs& args) {
TRACE_EVENT1(
"cc", "Scheduler::BeginImplFrame", "frame_time", args.frame_time);
TRACE_EVENT1("cc", "Scheduler::BeginImplFrame", "args", ToTrace(args));
DCHECK(state_machine_.begin_impl_frame_state() ==
SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
DCHECK(state_machine_.HasInitializedOutputSurface());
Expand Down Expand Up @@ -630,7 +629,7 @@ void Scheduler::ProcessScheduledActions() {
TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"),
"SchedulerStateMachine",
"state",
TracedValue::FromValue(StateAsValue().release()));
ToTrace(this));
state_machine_.UpdateState(action);
base::AutoReset<SchedulerStateMachine::Action>
mark_inside_action(&inside_action_, action);
Expand Down Expand Up @@ -687,7 +686,7 @@ bool Scheduler::WillDrawIfNeeded() const {
return !state_machine_.PendingDrawsShouldBeAborted();
}

scoped_ptr<base::Value> Scheduler::StateAsValue() const {
scoped_ptr<base::Value> Scheduler::AsValue() const {
scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue);
state->Set("state_machine", state_machine_.AsValue().release());

Expand All @@ -713,6 +712,9 @@ scoped_ptr<base::Value> Scheduler::StateAsValue() const {
!poll_for_draw_triggers_task_.IsCancelled());
scheduler_state->SetBoolean("advance_commit_state_task_",
!advance_commit_state_task_.IsCancelled());
scheduler_state->Set("begin_impl_frame_args",
begin_impl_frame_args_.AsValue().release());

state->Set("scheduler_state", scheduler_state.release());

scoped_ptr<base::DictionaryValue> client_state(new base::DictionaryValue);
Expand Down Expand Up @@ -742,7 +744,7 @@ bool Scheduler::CanCommitAndActivateBeforeDeadline() const {
"time_left_after_drawing_ms",
(begin_impl_frame_args_.deadline - estimated_draw_time).InMillisecondsF(),
"state",
TracedValue::FromValue(StateAsValue().release()));
ToTrace(this));

return estimated_draw_time < begin_impl_frame_args_.deadline;
}
Expand Down
2 changes: 1 addition & 1 deletion cc/scheduler/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class CC_EXPORT Scheduler {
void PollForAnticipatedDrawTriggers();
void PollToAdvanceCommitState();

scoped_ptr<base::Value> StateAsValue() const;
scoped_ptr<base::Value> AsValue() const;

bool IsInsideAction(SchedulerStateMachine::Action action) {
return inside_action_ == action;
Expand Down
28 changes: 14 additions & 14 deletions cc/scheduler/scheduler_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,25 +99,25 @@ class FakeSchedulerClient : public SchedulerClient {
// SchedulerClient implementation.
virtual void SetNeedsBeginFrame(bool enable) OVERRIDE {
actions_.push_back("SetNeedsBeginFrame");
states_.push_back(scheduler_->StateAsValue().release());
states_.push_back(scheduler_->AsValue().release());
needs_begin_frame_ = enable;
}
virtual void WillBeginImplFrame(const BeginFrameArgs& args) OVERRIDE {
actions_.push_back("WillBeginImplFrame");
states_.push_back(scheduler_->StateAsValue().release());
states_.push_back(scheduler_->AsValue().release());
}
virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {
actions_.push_back("ScheduledActionSendBeginMainFrame");
states_.push_back(scheduler_->StateAsValue().release());
states_.push_back(scheduler_->AsValue().release());
}
virtual void ScheduledActionAnimate() OVERRIDE {
actions_.push_back("ScheduledActionAnimate");
states_.push_back(scheduler_->StateAsValue().release());
states_.push_back(scheduler_->AsValue().release());
}
virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible()
OVERRIDE {
actions_.push_back("ScheduledActionDrawAndSwapIfPossible");
states_.push_back(scheduler_->StateAsValue().release());
states_.push_back(scheduler_->AsValue().release());
num_draws_++;
bool did_readback = false;
DrawSwapReadbackResult::DrawResult result =
Expand All @@ -138,39 +138,39 @@ class FakeSchedulerClient : public SchedulerClient {
}
virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapForced() OVERRIDE {
actions_.push_back("ScheduledActionDrawAndSwapForced");
states_.push_back(scheduler_->StateAsValue().release());
states_.push_back(scheduler_->AsValue().release());
bool did_request_swap = swap_will_happen_if_draw_happens_;
bool did_readback = false;
return DrawSwapReadbackResult(
DrawSwapReadbackResult::DRAW_SUCCESS, did_request_swap, did_readback);
}
virtual DrawSwapReadbackResult ScheduledActionDrawAndReadback() OVERRIDE {
actions_.push_back("ScheduledActionDrawAndReadback");
states_.push_back(scheduler_->StateAsValue().release());
states_.push_back(scheduler_->AsValue().release());
bool did_request_swap = false;
bool did_readback = true;
return DrawSwapReadbackResult(
DrawSwapReadbackResult::DRAW_SUCCESS, did_request_swap, did_readback);
}
virtual void ScheduledActionCommit() OVERRIDE {
actions_.push_back("ScheduledActionCommit");
states_.push_back(scheduler_->StateAsValue().release());
states_.push_back(scheduler_->AsValue().release());
}
virtual void ScheduledActionUpdateVisibleTiles() OVERRIDE {
actions_.push_back("ScheduledActionUpdateVisibleTiles");
states_.push_back(scheduler_->StateAsValue().release());
states_.push_back(scheduler_->AsValue().release());
}
virtual void ScheduledActionActivatePendingTree() OVERRIDE {
actions_.push_back("ScheduledActionActivatePendingTree");
states_.push_back(scheduler_->StateAsValue().release());
states_.push_back(scheduler_->AsValue().release());
}
virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE {
actions_.push_back("ScheduledActionBeginOutputSurfaceCreation");
states_.push_back(scheduler_->StateAsValue().release());
states_.push_back(scheduler_->AsValue().release());
}
virtual void ScheduledActionManageTiles() OVERRIDE {
actions_.push_back("ScheduledActionManageTiles");
states_.push_back(scheduler_->StateAsValue().release());
states_.push_back(scheduler_->AsValue().release());
}
virtual void DidAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE {
if (log_anticipated_draw_time_change_)
Expand Down Expand Up @@ -1115,7 +1115,7 @@ TEST(SchedulerTest, PollForCommitCompletion) {
for (int i = 0; i < 3; ++i) {
EXPECT_EQ((frame_args.interval * 2).InMicroseconds(),
client.task_runner().NextPendingTaskDelay().InMicroseconds())
<< *scheduler->StateAsValue();
<< *scheduler->AsValue();
client.task_runner().RunPendingTasks();
EXPECT_GT(client.num_actions_(), actions_so_far);
EXPECT_STREQ(client.Action(client.num_actions_() - 1),
Expand All @@ -1128,7 +1128,7 @@ TEST(SchedulerTest, PollForCommitCompletion) {
for (int i = 0; i < 3; ++i) {
EXPECT_EQ((frame_args.interval * 2).InMicroseconds(),
client.task_runner().NextPendingTaskDelay().InMicroseconds())
<< *scheduler->StateAsValue();
<< *scheduler->AsValue();
client.task_runner().RunPendingTasks();
EXPECT_GT(client.num_actions_(), actions_so_far);
EXPECT_STREQ(client.Action(client.num_actions_() - 1),
Expand Down
2 changes: 1 addition & 1 deletion cc/trees/proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Proxy::~Proxy() {
DCHECK(IsMainThread());
}

scoped_ptr<base::Value> Proxy::SchedulerStateAsValueForTesting() {
scoped_ptr<base::Value> Proxy::SchedulerAsValueForTesting() {
return make_scoped_ptr(base::Value::CreateNullValue());
}

Expand Down
2 changes: 1 addition & 1 deletion cc/trees/proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class CC_EXPORT Proxy {

// Testing hooks
virtual bool CommitPendingForTesting() = 0;
virtual scoped_ptr<base::Value> SchedulerStateAsValueForTesting();
virtual scoped_ptr<base::Value> SchedulerAsValueForTesting();

protected:
explicit Proxy(
Expand Down
10 changes: 5 additions & 5 deletions cc/trees/thread_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1530,27 +1530,27 @@ void ThreadProxy::CommitPendingOnImplThreadForTesting(
request->completion.Signal();
}

scoped_ptr<base::Value> ThreadProxy::SchedulerStateAsValueForTesting() {
scoped_ptr<base::Value> ThreadProxy::SchedulerAsValueForTesting() {
if (IsImplThread())
return impl().scheduler->StateAsValue().Pass();
return impl().scheduler->AsValue().Pass();

SchedulerStateRequest scheduler_state_request;
{
DebugScopedSetMainThreadBlocked main_thread_blocked(this);
Proxy::ImplThreadTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&ThreadProxy::SchedulerStateAsValueOnImplThreadForTesting,
base::Bind(&ThreadProxy::SchedulerAsValueOnImplThreadForTesting,
impl_thread_weak_ptr_,
&scheduler_state_request));
scheduler_state_request.completion.Wait();
}
return scheduler_state_request.state.Pass();
}

void ThreadProxy::SchedulerStateAsValueOnImplThreadForTesting(
void ThreadProxy::SchedulerAsValueOnImplThreadForTesting(
SchedulerStateRequest* request) {
DCHECK(IsImplThread());
request->state = impl().scheduler->StateAsValue();
request->state = impl().scheduler->AsValue();
request->completion.Signal();
}

Expand Down
5 changes: 2 additions & 3 deletions cc/trees/thread_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ThreadProxy : public Proxy,
virtual void SetDebugState(const LayerTreeDebugState& debug_state) OVERRIDE;
virtual scoped_ptr<base::Value> AsValue() const OVERRIDE;
virtual bool CommitPendingForTesting() OVERRIDE;
virtual scoped_ptr<base::Value> SchedulerStateAsValueForTesting() OVERRIDE;
virtual scoped_ptr<base::Value> SchedulerAsValueForTesting() OVERRIDE;

// LayerTreeHostImplClient implementation
virtual void UpdateRendererCapabilitiesOnImplThread() OVERRIDE;
Expand Down Expand Up @@ -188,8 +188,7 @@ class ThreadProxy : public Proxy,
void ForceSerializeOnSwapBuffersOnImplThread(CompletionEvent* completion);
void CheckOutputSurfaceStatusOnImplThread();
void CommitPendingOnImplThreadForTesting(CommitPendingRequest* request);
void SchedulerStateAsValueOnImplThreadForTesting(
SchedulerStateRequest* request);
void SchedulerAsValueOnImplThreadForTesting(SchedulerStateRequest* request);
void AsValueOnImplThread(CompletionEvent* completion,
base::DictionaryValue* state) const;
void RenewTreePriorityOnImplThread();
Expand Down

0 comments on commit fc441c6

Please sign in to comment.