Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: cc/scheduler/scheduler.cc

Issue 1184863004: cc: Move timing history to the Scheduler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase, add include Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/scheduler/scheduler.h" 5 #include "cc/scheduler/scheduler.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 BackToBackBeginFrameSource::Create(scheduler->task_runner_.get()); 57 BackToBackBeginFrameSource::Create(scheduler->task_runner_.get());
58 return scheduler->unthrottled_frame_source_internal_.get(); 58 return scheduler->unthrottled_frame_source_internal_.get();
59 } 59 }
60 60
61 Scheduler::Scheduler( 61 Scheduler::Scheduler(
62 SchedulerClient* client, 62 SchedulerClient* client,
63 const SchedulerSettings& scheduler_settings, 63 const SchedulerSettings& scheduler_settings,
64 int layer_tree_host_id, 64 int layer_tree_host_id,
65 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 65 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
66 scoped_ptr<BeginFrameSource> external_begin_frame_source, 66 scoped_ptr<BeginFrameSource> external_begin_frame_source,
67 RenderingStatsInstrumentation* rendering_stats_instrumentation,
sunnyps 2015/06/23 18:11:02 The Scheduler could take in a CompositorTimingHist
brianderson 2015/06/23 20:23:27 I kept this constructor and Scheduler::Create the
67 SchedulerFrameSourcesConstructor* frame_sources_constructor) 68 SchedulerFrameSourcesConstructor* frame_sources_constructor)
68 : frame_source_(), 69 : frame_source_(),
69 primary_frame_source_(NULL), 70 primary_frame_source_(NULL),
70 primary_frame_source_internal_(external_begin_frame_source.Pass()), 71 primary_frame_source_internal_(external_begin_frame_source.Pass()),
71 vsync_observer_(NULL), 72 vsync_observer_(NULL),
72 authoritative_vsync_interval_(base::TimeDelta()), 73 authoritative_vsync_interval_(base::TimeDelta()),
73 last_vsync_timebase_(base::TimeTicks()), 74 last_vsync_timebase_(base::TimeTicks()),
74 throttle_frame_production_(false), 75 throttle_frame_production_(false),
75 settings_(scheduler_settings), 76 settings_(scheduler_settings),
76 client_(client), 77 client_(client),
77 layer_tree_host_id_(layer_tree_host_id), 78 layer_tree_host_id_(layer_tree_host_id),
78 task_runner_(task_runner), 79 task_runner_(task_runner),
80 compositor_timing_history_(rendering_stats_instrumentation),
79 begin_impl_frame_deadline_mode_( 81 begin_impl_frame_deadline_mode_(
80 SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE), 82 SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE),
81 begin_impl_frame_tracker_(BEGINFRAMETRACKER_FROM_HERE), 83 begin_impl_frame_tracker_(BEGINFRAMETRACKER_FROM_HERE),
82 state_machine_(scheduler_settings), 84 state_machine_(scheduler_settings),
83 inside_process_scheduled_actions_(false), 85 inside_process_scheduled_actions_(false),
84 inside_action_(SchedulerStateMachine::ACTION_NONE), 86 inside_action_(SchedulerStateMachine::ACTION_NONE),
85 weak_factory_(this) { 87 weak_factory_(this) {
86 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), 88 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"),
87 "Scheduler::Scheduler", 89 "Scheduler::Scheduler",
88 "settings", 90 "settings",
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 124
123 base::TimeTicks Scheduler::Now() const { 125 base::TimeTicks Scheduler::Now() const {
124 base::TimeTicks now = base::TimeTicks::Now(); 126 base::TimeTicks now = base::TimeTicks::Now();
125 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.now"), 127 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.now"),
126 "Scheduler::Now", 128 "Scheduler::Now",
127 "now", 129 "now",
128 now); 130 now);
129 return now; 131 return now;
130 } 132 }
131 133
134 base::TimeDelta Scheduler::DrawDurationEstimate() const {
135 return compositor_timing_history_.DrawDurationEstimate();
136 }
137
138 base::TimeDelta Scheduler::BeginMainFrameToCommitDurationEstimate() const {
139 return compositor_timing_history_.BeginMainFrameToCommitDurationEstimate();
140 }
141
142 base::TimeDelta Scheduler::CommitToActivateDurationEstimate() const {
143 return compositor_timing_history_.CommitToActivateDurationEstimate();
144 }
145
132 void Scheduler::CommitVSyncParameters(base::TimeTicks timebase, 146 void Scheduler::CommitVSyncParameters(base::TimeTicks timebase,
133 base::TimeDelta interval) { 147 base::TimeDelta interval) {
134 if (authoritative_vsync_interval_ != base::TimeDelta()) { 148 if (authoritative_vsync_interval_ != base::TimeDelta()) {
135 interval = authoritative_vsync_interval_; 149 interval = authoritative_vsync_interval_;
136 } else if (interval == base::TimeDelta()) { 150 } else if (interval == base::TimeDelta()) {
137 // TODO(brianderson): We should not be receiving 0 intervals. 151 // TODO(brianderson): We should not be receiving 0 intervals.
138 interval = BeginFrameArgs::DefaultInterval(); 152 interval = BeginFrameArgs::DefaultInterval();
139 } 153 }
140 154
141 last_vsync_timebase_ = timebase; 155 last_vsync_timebase_ = timebase;
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 state_machine_.MainThreadIsInHighLatencyMode(); 502 state_machine_.MainThreadIsInHighLatencyMode();
489 TRACE_EVENT2("cc,benchmark", "Scheduler::BeginImplFrame", "args", 503 TRACE_EVENT2("cc,benchmark", "Scheduler::BeginImplFrame", "args",
490 args.AsValue(), "main_thread_is_high_latency", 504 args.AsValue(), "main_thread_is_high_latency",
491 main_thread_is_in_high_latency_mode); 505 main_thread_is_in_high_latency_mode);
492 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), 506 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"),
493 "MainThreadLatency", main_thread_is_in_high_latency_mode); 507 "MainThreadLatency", main_thread_is_in_high_latency_mode);
494 508
495 advance_commit_state_task_.Cancel(); 509 advance_commit_state_task_.Cancel();
496 510
497 BeginFrameArgs adjusted_args = args; 511 BeginFrameArgs adjusted_args = args;
498 adjusted_args.deadline -= client_->DrawDurationEstimate(); 512 adjusted_args.deadline -= DrawDurationEstimate();
499 513
500 if (!state_machine_.impl_latency_takes_priority() && 514 if (!state_machine_.impl_latency_takes_priority() &&
501 main_thread_is_in_high_latency_mode && 515 main_thread_is_in_high_latency_mode &&
502 CanCommitAndActivateBeforeDeadline()) { 516 CanCommitAndActivateBeforeDeadline()) {
503 state_machine_.SetSkipNextBeginMainFrameToReduceLatency(); 517 state_machine_.SetSkipNextBeginMainFrameToReduceLatency();
504 } 518 }
505 519
506 BeginImplFrame(adjusted_args); 520 BeginImplFrame(adjusted_args);
507 521
508 // The deadline will be scheduled in ProcessScheduledActions. 522 // The deadline will be scheduled in ProcessScheduledActions.
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 } 645 }
632 646
633 647
634 void Scheduler::PollToAdvanceCommitState() { 648 void Scheduler::PollToAdvanceCommitState() {
635 TRACE_EVENT0("cc", "Scheduler::PollToAdvanceCommitState"); 649 TRACE_EVENT0("cc", "Scheduler::PollToAdvanceCommitState");
636 advance_commit_state_task_.Cancel(); 650 advance_commit_state_task_.Cancel();
637 ProcessScheduledActions(); 651 ProcessScheduledActions();
638 } 652 }
639 653
640 void Scheduler::DrawAndSwapIfPossible() { 654 void Scheduler::DrawAndSwapIfPossible() {
655 compositor_timing_history_.DidStartDrawing();
641 DrawResult result = client_->ScheduledActionDrawAndSwapIfPossible(); 656 DrawResult result = client_->ScheduledActionDrawAndSwapIfPossible();
642 state_machine_.DidDrawIfPossibleCompleted(result); 657 state_machine_.DidDrawIfPossibleCompleted(result);
658 compositor_timing_history_.DidFinishDrawing();
659 }
660
661 void Scheduler::DrawAndSwapForced() {
662 compositor_timing_history_.DidStartDrawing();
663 client_->ScheduledActionDrawAndSwapForced();
664 compositor_timing_history_.DidFinishDrawing();
643 } 665 }
644 666
645 void Scheduler::SetDeferCommits(bool defer_commits) { 667 void Scheduler::SetDeferCommits(bool defer_commits) {
646 TRACE_EVENT1("cc", "Scheduler::SetDeferCommits", 668 TRACE_EVENT1("cc", "Scheduler::SetDeferCommits",
647 "defer_commits", 669 "defer_commits",
648 defer_commits); 670 defer_commits);
649 state_machine_.SetDeferCommits(defer_commits); 671 state_machine_.SetDeferCommits(defer_commits);
650 ProcessScheduledActions(); 672 ProcessScheduledActions();
651 } 673 }
652 674
(...skipping 18 matching lines...) Expand all
671 state_machine_.UpdateState(action); 693 state_machine_.UpdateState(action);
672 base::AutoReset<SchedulerStateMachine::Action> 694 base::AutoReset<SchedulerStateMachine::Action>
673 mark_inside_action(&inside_action_, action); 695 mark_inside_action(&inside_action_, action);
674 switch (action) { 696 switch (action) {
675 case SchedulerStateMachine::ACTION_NONE: 697 case SchedulerStateMachine::ACTION_NONE:
676 break; 698 break;
677 case SchedulerStateMachine::ACTION_ANIMATE: 699 case SchedulerStateMachine::ACTION_ANIMATE:
678 client_->ScheduledActionAnimate(); 700 client_->ScheduledActionAnimate();
679 break; 701 break;
680 case SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME: 702 case SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME:
703 compositor_timing_history_.WillBeginMainFrame();
681 client_->ScheduledActionSendBeginMainFrame(); 704 client_->ScheduledActionSendBeginMainFrame();
682 break; 705 break;
683 case SchedulerStateMachine::ACTION_COMMIT: { 706 case SchedulerStateMachine::ACTION_COMMIT: {
684 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is 707 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is
685 // fixed. 708 // fixed.
686 tracked_objects::ScopedTracker tracking_profile4( 709 tracked_objects::ScopedTracker tracking_profile4(
687 FROM_HERE_WITH_EXPLICIT_FUNCTION( 710 FROM_HERE_WITH_EXPLICIT_FUNCTION(
688 "461509 Scheduler::ProcessScheduledActions4")); 711 "461509 Scheduler::ProcessScheduledActions4"));
689 client_->ScheduledActionCommit(); 712 client_->ScheduledActionCommit();
713 compositor_timing_history_.DidCommit();
690 break; 714 break;
691 } 715 }
692 case SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE: 716 case SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE:
693 client_->ScheduledActionActivateSyncTree(); 717 client_->ScheduledActionActivateSyncTree();
718 compositor_timing_history_.DidActivateSyncTree();
694 break; 719 break;
695 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE: { 720 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE: {
696 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is 721 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is
697 // fixed. 722 // fixed.
698 tracked_objects::ScopedTracker tracking_profile6( 723 tracked_objects::ScopedTracker tracking_profile6(
699 FROM_HERE_WITH_EXPLICIT_FUNCTION( 724 FROM_HERE_WITH_EXPLICIT_FUNCTION(
700 "461509 Scheduler::ProcessScheduledActions6")); 725 "461509 Scheduler::ProcessScheduledActions6"));
701 DrawAndSwapIfPossible(); 726 DrawAndSwapIfPossible();
702 break; 727 break;
703 } 728 }
704 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED: 729 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED:
705 client_->ScheduledActionDrawAndSwapForced(); 730 DrawAndSwapForced();
706 break; 731 break;
707 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT: 732 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT:
708 // No action is actually performed, but this allows the state machine to 733 // No action is actually performed, but this allows the state machine to
709 // advance out of its waiting to draw state without actually drawing. 734 // advance out of its waiting to draw state without actually drawing.
710 break; 735 break;
711 case SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION: 736 case SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION:
712 client_->ScheduledActionBeginOutputSurfaceCreation(); 737 client_->ScheduledActionBeginOutputSurfaceCreation();
713 break; 738 break;
714 case SchedulerStateMachine::ACTION_PREPARE_TILES: 739 case SchedulerStateMachine::ACTION_PREPARE_TILES:
715 client_->ScheduledActionPrepareTiles(); 740 client_->ScheduledActionPrepareTiles();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 !begin_impl_frame_deadline_task_.IsCancelled()); 790 !begin_impl_frame_deadline_task_.IsCancelled());
766 state->SetBoolean("advance_commit_state_task", 791 state->SetBoolean("advance_commit_state_task",
767 !advance_commit_state_task_.IsCancelled()); 792 !advance_commit_state_task_.IsCancelled());
768 state->SetString("inside_action", 793 state->SetString("inside_action",
769 SchedulerStateMachine::ActionToString(inside_action_)); 794 SchedulerStateMachine::ActionToString(inside_action_));
770 state->BeginDictionary("begin_impl_frame_args"); 795 state->BeginDictionary("begin_impl_frame_args");
771 begin_impl_frame_tracker_.AsValueInto(Now(), state); 796 begin_impl_frame_tracker_.AsValueInto(Now(), state);
772 state->EndDictionary(); 797 state->EndDictionary();
773 state->EndDictionary(); 798 state->EndDictionary();
774 799
775 state->BeginDictionary("client_state"); 800 state->BeginDictionary("compositor_timing_history");
776 state->SetDouble("draw_duration_estimate_ms", 801 state->SetDouble("draw_duration_estimate_ms",
777 client_->DrawDurationEstimate().InMillisecondsF()); 802 DrawDurationEstimate().InMillisecondsF());
778 state->SetDouble( 803 state->SetDouble("begin_main_frame_to_commit_duration_estimate_ms",
779 "begin_main_frame_to_commit_duration_estimate_ms", 804 BeginMainFrameToCommitDurationEstimate().InMillisecondsF());
780 client_->BeginMainFrameToCommitDurationEstimate().InMillisecondsF()); 805 state->SetDouble("commit_to_activate_duration_estimate_ms",
781 state->SetDouble( 806 CommitToActivateDurationEstimate().InMillisecondsF());
782 "commit_to_activate_duration_estimate_ms",
783 client_->CommitToActivateDurationEstimate().InMillisecondsF());
784 state->EndDictionary(); 807 state->EndDictionary();
785 } 808 }
786 809
787 bool Scheduler::CanCommitAndActivateBeforeDeadline() const { 810 bool Scheduler::CanCommitAndActivateBeforeDeadline() const {
788 BeginFrameArgs args = 811 BeginFrameArgs args =
789 begin_impl_frame_tracker_.DangerousMethodCurrentOrLast(); 812 begin_impl_frame_tracker_.DangerousMethodCurrentOrLast();
790 813
791 // Check if the main thread computation and commit can be finished before the 814 // Check if the main thread computation and commit can be finished before the
792 // impl thread's deadline. 815 // impl thread's deadline.
793 base::TimeTicks estimated_draw_time = 816 base::TimeTicks estimated_draw_time =
794 args.frame_time + client_->BeginMainFrameToCommitDurationEstimate() + 817 args.frame_time + BeginMainFrameToCommitDurationEstimate() +
795 client_->CommitToActivateDurationEstimate(); 818 CommitToActivateDurationEstimate();
796 819
797 TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), 820 TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"),
798 "CanCommitAndActivateBeforeDeadline", 821 "CanCommitAndActivateBeforeDeadline",
799 "time_left_after_drawing_ms", 822 "time_left_after_drawing_ms",
800 (args.deadline - estimated_draw_time).InMillisecondsF(), "state", 823 (args.deadline - estimated_draw_time).InMillisecondsF(), "state",
801 AsValue()); 824 AsValue());
802 825
803 return estimated_draw_time < args.deadline; 826 return estimated_draw_time < args.deadline;
804 } 827 }
805 828
806 bool Scheduler::IsBeginMainFrameSentOrStarted() const { 829 bool Scheduler::IsBeginMainFrameSentOrStarted() const {
807 return (state_machine_.commit_state() == 830 return (state_machine_.commit_state() ==
808 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || 831 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT ||
809 state_machine_.commit_state() == 832 state_machine_.commit_state() ==
810 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); 833 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED);
811 } 834 }
812 835
813 } // namespace cc 836 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698