Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
behdad | 5fb48ea2 | 2019-08-12 18:15:36 | [diff] [blame] | 5 | #include "cc/metrics/frame_sequence_tracker.h" |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 6 | |
Sadrul Habib Chowdhury | 66ff272 | 2020-06-24 17:47:01 | [diff] [blame] | 7 | #include <algorithm> |
| 8 | #include <memory> |
| 9 | #include <string> |
| 10 | #include <utility> |
| 11 | |
Xiyuan Xia | 728d1cf56 | 2020-04-20 23:10:33 | [diff] [blame] | 12 | #include "base/bind.h" |
Lei Zhang | 812c539 | 2021-05-18 04:44:32 | [diff] [blame] | 13 | #include "base/containers/contains.h" |
Lei Zhang | c34fd347 | 2021-06-30 19:37:55 | [diff] [blame] | 14 | #include "base/containers/cxx20_erase.h" |
Hans Wennborg | 66d784de | 2020-06-17 20:23:03 | [diff] [blame] | 15 | #include "base/logging.h" |
Sadrul Habib Chowdhury | db3d7be7 | 2019-07-13 03:27:32 | [diff] [blame] | 16 | #include "base/metrics/histogram.h" |
| 17 | #include "base/metrics/histogram_macros.h" |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 18 | #include "base/trace_event/trace_event.h" |
| 19 | #include "base/trace_event/traced_value.h" |
| 20 | #include "components/viz/common/frame_sinks/begin_frame_args.h" |
| 21 | #include "components/viz/common/quads/compositor_frame_metadata.h" |
| 22 | #include "ui/gfx/presentation_feedback.h" |
| 23 | |
Mingjing Zhang | 2879aa89 | 2019-11-01 02:54:54 | [diff] [blame] | 24 | // This macro is used with DCHECK to provide addition debug info. |
Mingjing Zhang | 9431496 | 2019-11-05 02:59:20 | [diff] [blame] | 25 | #if DCHECK_IS_ON() |
Mingjing Zhang | c0ce541 | 2019-11-07 22:00:07 | [diff] [blame] | 26 | #define TRACKER_TRACE_STREAM frame_sequence_trace_ |
Sadrul Habib Chowdhury | 1f26453 | 2020-01-14 21:00:18 | [diff] [blame] | 27 | #define TRACKER_DCHECK_MSG \ |
Xida Chen | 3114cbb | 2020-04-21 01:57:07 | [diff] [blame] | 28 | " in " << GetFrameSequenceTrackerTypeName(this->type()) \ |
Sadrul Habib Chowdhury | 1f26453 | 2020-01-14 21:00:18 | [diff] [blame] | 29 | << " tracker: " << frame_sequence_trace_.str() << " (" \ |
Mingjing Zhang | c0ce541 | 2019-11-07 22:00:07 | [diff] [blame] | 30 | << frame_sequence_trace_.str().size() << ")"; |
Mingjing Zhang | 9431496 | 2019-11-05 02:59:20 | [diff] [blame] | 31 | #else |
Mingjing Zhang | c0ce541 | 2019-11-07 22:00:07 | [diff] [blame] | 32 | #define TRACKER_TRACE_STREAM EAT_STREAM_PARAMETERS |
Mingjing Zhang | 9431496 | 2019-11-05 02:59:20 | [diff] [blame] | 33 | #define TRACKER_DCHECK_MSG "" |
| 34 | #endif |
Mingjing Zhang | 2879aa89 | 2019-11-01 02:54:54 | [diff] [blame] | 35 | |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 36 | namespace cc { |
| 37 | |
Sadrul Habib Chowdhury | b533566 | 2020-06-16 18:17:40 | [diff] [blame] | 38 | using ThreadType = FrameSequenceMetrics::ThreadType; |
| 39 | |
Xida Chen | 89e1921 | 2020-04-28 14:43:45 | [diff] [blame] | 40 | // In the |TRACKER_TRACE_STREAM|, we mod the numbers such as frame sequence |
| 41 | // number, or frame token, such that the debug string is not too long. |
| 42 | constexpr int kDebugStrMod = 1000; |
| 43 | |
behdad | a108d81 | 2019-11-20 17:22:39 | [diff] [blame] | 44 | const char* FrameSequenceTracker::GetFrameSequenceTrackerTypeName( |
Sadrul Habib Chowdhury | 1f26453 | 2020-01-14 21:00:18 | [diff] [blame] | 45 | FrameSequenceTrackerType type) { |
| 46 | switch (type) { |
| 47 | case FrameSequenceTrackerType::kCompositorAnimation: |
behdad | a108d81 | 2019-11-20 17:22:39 | [diff] [blame] | 48 | return "CompositorAnimation"; |
Sadrul Habib Chowdhury | 1f26453 | 2020-01-14 21:00:18 | [diff] [blame] | 49 | case FrameSequenceTrackerType::kMainThreadAnimation: |
behdad | a108d81 | 2019-11-20 17:22:39 | [diff] [blame] | 50 | return "MainThreadAnimation"; |
Sadrul Habib Chowdhury | 1f26453 | 2020-01-14 21:00:18 | [diff] [blame] | 51 | case FrameSequenceTrackerType::kPinchZoom: |
behdad | a108d81 | 2019-11-20 17:22:39 | [diff] [blame] | 52 | return "PinchZoom"; |
Sadrul Habib Chowdhury | 1f26453 | 2020-01-14 21:00:18 | [diff] [blame] | 53 | case FrameSequenceTrackerType::kRAF: |
behdad | a108d81 | 2019-11-20 17:22:39 | [diff] [blame] | 54 | return "RAF"; |
Sadrul Habib Chowdhury | 1f26453 | 2020-01-14 21:00:18 | [diff] [blame] | 55 | case FrameSequenceTrackerType::kTouchScroll: |
behdad | a108d81 | 2019-11-20 17:22:39 | [diff] [blame] | 56 | return "TouchScroll"; |
Sadrul Habib Chowdhury | 1f26453 | 2020-01-14 21:00:18 | [diff] [blame] | 57 | case FrameSequenceTrackerType::kVideo: |
behdad | a108d81 | 2019-11-20 17:22:39 | [diff] [blame] | 58 | return "Video"; |
Sadrul Habib Chowdhury | 1f26453 | 2020-01-14 21:00:18 | [diff] [blame] | 59 | case FrameSequenceTrackerType::kWheelScroll: |
behdad | a108d81 | 2019-11-20 17:22:39 | [diff] [blame] | 60 | return "WheelScroll"; |
Sadrul Habib Chowdhury | aa3dccfd | 2020-03-12 00:41:58 | [diff] [blame] | 61 | case FrameSequenceTrackerType::kScrollbarScroll: |
| 62 | return "ScrollbarScroll"; |
Xiyuan Xia | ab73cc0 | 2020-03-30 22:36:43 | [diff] [blame] | 63 | case FrameSequenceTrackerType::kCustom: |
| 64 | return "Custom"; |
Xida Chen | 9d689d8 | 2020-11-05 22:26:35 | [diff] [blame] | 65 | case FrameSequenceTrackerType::kCanvasAnimation: |
| 66 | return "CanvasAnimation"; |
Xida Chen | 3b1ae1d | 2020-09-24 14:48:39 | [diff] [blame] | 67 | case FrameSequenceTrackerType::kJSAnimation: |
| 68 | return "JSAnimation"; |
Sadrul Habib Chowdhury | aa3dccfd | 2020-03-12 00:41:58 | [diff] [blame] | 69 | case FrameSequenceTrackerType::kMaxType: |
behdad | a108d81 | 2019-11-20 17:22:39 | [diff] [blame] | 70 | return ""; |
| 71 | } |
| 72 | } |
Xida Chen | 78ba8b7 | 2019-08-30 14:49:25 | [diff] [blame] | 73 | |
Xida Chen | 4ede1d69 | 2019-11-22 18:00:48 | [diff] [blame] | 74 | FrameSequenceTracker::FrameSequenceTracker( |
| 75 | FrameSequenceTrackerType type, |
Xiyuan Xia | 728d1cf56 | 2020-04-20 23:10:33 | [diff] [blame] | 76 | ThroughputUkmReporter* throughput_ukm_reporter) |
Xida Chen | 3114cbb | 2020-04-21 01:57:07 | [diff] [blame] | 77 | : custom_sequence_id_(-1), |
Sadrul Habib Chowdhury | 6c901cd5 | 2020-06-10 00:51:00 | [diff] [blame] | 78 | metrics_( |
| 79 | std::make_unique<FrameSequenceMetrics>(type, |
| 80 | throughput_ukm_reporter)) { |
Xida Chen | 3114cbb | 2020-04-21 01:57:07 | [diff] [blame] | 81 | DCHECK_LT(type, FrameSequenceTrackerType::kMaxType); |
| 82 | DCHECK(type != FrameSequenceTrackerType::kCustom); |
Xida Chen | b75b31270 | 2020-12-17 23:37:45 | [diff] [blame] | 83 | // TODO(crbug.com/1158439): remove the trace event once the validation is |
| 84 | // completed. |
| 85 | TRACE_EVENT_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP1( |
| 86 | "cc,benchmark", "TrackerValidation", TRACE_ID_LOCAL(this), |
| 87 | base::TimeTicks::Now(), "name", GetFrameSequenceTrackerTypeName(type)); |
Xiyuan Xia | 728d1cf56 | 2020-04-20 23:10:33 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | FrameSequenceTracker::FrameSequenceTracker( |
| 91 | int custom_sequence_id, |
| 92 | FrameSequenceMetrics::CustomReporter custom_reporter) |
Xida Chen | 3114cbb | 2020-04-21 01:57:07 | [diff] [blame] | 93 | : custom_sequence_id_(custom_sequence_id), |
| 94 | metrics_(std::make_unique<FrameSequenceMetrics>( |
| 95 | FrameSequenceTrackerType::kCustom, |
Sadrul Habib Chowdhury | 6c901cd5 | 2020-06-10 00:51:00 | [diff] [blame] | 96 | /*ukm_reporter=*/nullptr)) { |
Xiyuan Xia | 728d1cf56 | 2020-04-20 23:10:33 | [diff] [blame] | 97 | DCHECK_GT(custom_sequence_id_, 0); |
| 98 | metrics_->SetCustomReporter(std::move(custom_reporter)); |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 99 | } |
| 100 | |
Xida Chen | c89c1c9 | 2020-07-26 00:42:04 | [diff] [blame] | 101 | FrameSequenceTracker::~FrameSequenceTracker() { |
Xida Chen | b75b31270 | 2020-12-17 23:37:45 | [diff] [blame] | 102 | TRACE_EVENT_NESTABLE_ASYNC_END_WITH_TIMESTAMP0( |
| 103 | "cc,benchmark", "TrackerValidation", TRACE_ID_LOCAL(this), |
| 104 | base::TimeTicks::Now()); |
Xida Chen | c89c1c9 | 2020-07-26 00:42:04 | [diff] [blame] | 105 | CleanUp(); |
| 106 | } |
Sadrul Habib Chowdhury | 40a4d8c | 2019-09-05 03:02:31 | [diff] [blame] | 107 | |
Xida Chen | 62007203 | 2020-01-10 17:21:35 | [diff] [blame] | 108 | void FrameSequenceTracker::ScheduleTerminate() { |
Xida Chen | 8f5fc49 | 2020-04-02 21:55:04 | [diff] [blame] | 109 | // If the last frame has ended and there is no frame awaiting presentation, |
| 110 | // then it is ready to terminate. |
| 111 | if (!is_inside_frame_ && last_submitted_frame_ == 0) |
| 112 | termination_status_ = TerminationStatus::kReadyForTermination; |
| 113 | else |
| 114 | termination_status_ = TerminationStatus::kScheduledForTermination; |
Xida Chen | 62007203 | 2020-01-10 17:21:35 | [diff] [blame] | 115 | } |
| 116 | |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 117 | void FrameSequenceTracker::ReportBeginImplFrame( |
| 118 | const viz::BeginFrameArgs& args) { |
| 119 | if (termination_status_ != TerminationStatus::kActive) |
| 120 | return; |
| 121 | |
behdad | 2adc423 | 2019-12-18 18:11:39 | [diff] [blame] | 122 | if (ShouldIgnoreBeginFrameSource(args.frame_id.source_id)) |
Sadrul Habib Chowdhury | 2391917 | 2019-07-22 23:58:50 | [diff] [blame] | 123 | return; |
Sadrul Habib Chowdhury | dc34c8b | 2019-12-16 18:39:13 | [diff] [blame] | 124 | |
Xida Chen | 89e1921 | 2020-04-28 14:43:45 | [diff] [blame] | 125 | TRACKER_TRACE_STREAM << "b(" << args.frame_id.sequence_number % kDebugStrMod |
| 126 | << ")"; |
Sadrul Habib Chowdhury | 2f848d2 | 2019-12-23 16:34:09 | [diff] [blame] | 127 | |
Sadrul Habib Chowdhury | 7fe10ea | 2019-12-11 01:59:29 | [diff] [blame] | 128 | DCHECK(!is_inside_frame_) << TRACKER_DCHECK_MSG; |
| 129 | is_inside_frame_ = true; |
Xida Chen | 8f5fc49 | 2020-04-02 21:55:04 | [diff] [blame] | 130 | #if DCHECK_IS_ON() |
Xida Chen | d56033c | 2019-12-05 13:31:41 | [diff] [blame] | 131 | if (args.type == viz::BeginFrameArgs::NORMAL) |
behdad | 2adc423 | 2019-12-18 18:11:39 | [diff] [blame] | 132 | impl_frames_.insert(args.frame_id); |
Xida Chen | d56033c | 2019-12-05 13:31:41 | [diff] [blame] | 133 | #endif |
Sadrul Habib Chowdhury | a962eb3 | 2019-12-23 02:21:47 | [diff] [blame] | 134 | |
Sadrul Habib Chowdhury | 1e28555 | 2020-01-22 02:46:57 | [diff] [blame] | 135 | DCHECK_EQ(last_started_impl_sequence_, 0u) << TRACKER_DCHECK_MSG; |
Xida Chen | 62007203 | 2020-01-10 17:21:35 | [diff] [blame] | 136 | last_started_impl_sequence_ = args.frame_id.sequence_number; |
Sadrul Habib Chowdhury | 634b8e01 | 2019-12-23 13:46:12 | [diff] [blame] | 137 | if (reset_all_state_) { |
| 138 | begin_impl_frame_data_ = {}; |
| 139 | begin_main_frame_data_ = {}; |
| 140 | reset_all_state_ = false; |
| 141 | } |
| 142 | |
Sadrul Habib Chowdhury | a962eb3 | 2019-12-23 02:21:47 | [diff] [blame] | 143 | DCHECK(!frame_had_no_compositor_damage_) << TRACKER_DCHECK_MSG; |
| 144 | DCHECK(!compositor_frame_submitted_) << TRACKER_DCHECK_MSG; |
| 145 | |
behdad | 2adc423 | 2019-12-18 18:11:39 | [diff] [blame] | 146 | UpdateTrackedFrameData(&begin_impl_frame_data_, args.frame_id.source_id, |
yjliu | 9d3df97 | 2021-04-08 17:03:49 | [diff] [blame] | 147 | args.frame_id.sequence_number, |
| 148 | args.frames_throttled_since_last); |
Sadrul Habib Chowdhury | c537f2f4 | 2019-12-05 19:52:28 | [diff] [blame] | 149 | impl_throughput().frames_expected += |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 150 | begin_impl_frame_data_.previous_sequence_delta; |
Xida Chen | 675c2d7 | 2020-01-16 13:06:48 | [diff] [blame] | 151 | #if DCHECK_IS_ON() |
| 152 | ++impl_throughput().frames_received; |
| 153 | #endif |
Xida Chen | 1102307b | 2019-10-11 17:03:15 | [diff] [blame] | 154 | |
| 155 | if (first_frame_timestamp_.is_null()) |
| 156 | first_frame_timestamp_ = args.frame_time; |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | void FrameSequenceTracker::ReportBeginMainFrame( |
| 160 | const viz::BeginFrameArgs& args) { |
| 161 | if (termination_status_ != TerminationStatus::kActive) |
| 162 | return; |
| 163 | |
behdad | 2adc423 | 2019-12-18 18:11:39 | [diff] [blame] | 164 | if (ShouldIgnoreBeginFrameSource(args.frame_id.source_id)) |
Sadrul Habib Chowdhury | 2391917 | 2019-07-22 23:58:50 | [diff] [blame] | 165 | return; |
| 166 | |
Xida Chen | 89e1921 | 2020-04-28 14:43:45 | [diff] [blame] | 167 | TRACKER_TRACE_STREAM << "B(" |
| 168 | << begin_main_frame_data_.previous_sequence % |
| 169 | kDebugStrMod |
| 170 | << "," << args.frame_id.sequence_number % kDebugStrMod |
| 171 | << ")"; |
Sadrul Habib Chowdhury | e49c0a6 | 2019-12-22 04:36:22 | [diff] [blame] | 172 | |
Sadrul Habib Chowdhury | 1e28555 | 2020-01-22 02:46:57 | [diff] [blame] | 173 | if (first_received_main_sequence_ && |
| 174 | first_received_main_sequence_ > args.frame_id.sequence_number) { |
Xida Chen | d56033c | 2019-12-05 13:31:41 | [diff] [blame] | 175 | return; |
Sadrul Habib Chowdhury | 1e28555 | 2020-01-22 02:46:57 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | if (!first_received_main_sequence_ && |
| 179 | ShouldIgnoreSequence(args.frame_id.sequence_number)) { |
| 180 | return; |
| 181 | } |
Xida Chen | d56033c | 2019-12-05 13:31:41 | [diff] [blame] | 182 | |
| 183 | #if DCHECK_IS_ON() |
| 184 | if (args.type == viz::BeginFrameArgs::NORMAL) { |
Sadrul Habib Chowdhury | 1e28555 | 2020-01-22 02:46:57 | [diff] [blame] | 185 | DCHECK(impl_frames_.contains(args.frame_id)) << TRACKER_DCHECK_MSG; |
Xida Chen | d56033c | 2019-12-05 13:31:41 | [diff] [blame] | 186 | } |
| 187 | #endif |
| 188 | |
Sadrul Habib Chowdhury | 1e28555 | 2020-01-22 02:46:57 | [diff] [blame] | 189 | DCHECK_EQ(awaiting_main_response_sequence_, 0u) << TRACKER_DCHECK_MSG; |
| 190 | last_processed_main_sequence_latency_ = 0; |
Sadrul Habib Chowdhury | c072db7 | 2020-01-16 02:52:34 | [diff] [blame] | 191 | awaiting_main_response_sequence_ = args.frame_id.sequence_number; |
| 192 | |
behdad | 2adc423 | 2019-12-18 18:11:39 | [diff] [blame] | 193 | UpdateTrackedFrameData(&begin_main_frame_data_, args.frame_id.source_id, |
yjliu | 9d3df97 | 2021-04-08 17:03:49 | [diff] [blame] | 194 | args.frame_id.sequence_number, |
| 195 | args.frames_throttled_since_last); |
Sadrul Habib Chowdhury | 1b9fea6a | 2019-12-18 02:26:02 | [diff] [blame] | 196 | if (!first_received_main_sequence_ || |
Sadrul Habib Chowdhury | c072db7 | 2020-01-16 02:52:34 | [diff] [blame] | 197 | first_received_main_sequence_ <= last_no_main_damage_sequence_) { |
behdad | 2adc423 | 2019-12-18 18:11:39 | [diff] [blame] | 198 | first_received_main_sequence_ = args.frame_id.sequence_number; |
Sadrul Habib Chowdhury | c072db7 | 2020-01-16 02:52:34 | [diff] [blame] | 199 | } |
Sadrul Habib Chowdhury | c537f2f4 | 2019-12-05 19:52:28 | [diff] [blame] | 200 | main_throughput().frames_expected += |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 201 | begin_main_frame_data_.previous_sequence_delta; |
Xida Chen | 8ee29c9a | 2020-01-30 18:59:23 | [diff] [blame] | 202 | previous_begin_main_sequence_ = current_begin_main_sequence_; |
| 203 | current_begin_main_sequence_ = args.frame_id.sequence_number; |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 204 | } |
| 205 | |
Sadrul Habib Chowdhury | c072db7 | 2020-01-16 02:52:34 | [diff] [blame] | 206 | void FrameSequenceTracker::ReportMainFrameProcessed( |
| 207 | const viz::BeginFrameArgs& args) { |
| 208 | if (termination_status_ != TerminationStatus::kActive) |
| 209 | return; |
| 210 | |
| 211 | if (ShouldIgnoreBeginFrameSource(args.frame_id.source_id)) |
| 212 | return; |
| 213 | |
Xida Chen | 89e1921 | 2020-04-28 14:43:45 | [diff] [blame] | 214 | TRACKER_TRACE_STREAM << "E(" << args.frame_id.sequence_number % kDebugStrMod |
| 215 | << ")"; |
Xida Chen | 8ee29c9a | 2020-01-30 18:59:23 | [diff] [blame] | 216 | |
| 217 | const bool previous_main_frame_submitted_or_no_damage = |
| 218 | previous_begin_main_sequence_ != 0 && |
| 219 | (last_submitted_main_sequence_ == previous_begin_main_sequence_ || |
| 220 | last_no_main_damage_sequence_ == previous_begin_main_sequence_); |
| 221 | if (last_processed_main_sequence_ != 0 && |
| 222 | !had_impl_frame_submitted_between_commits_ && |
| 223 | !previous_main_frame_submitted_or_no_damage) { |
| 224 | DCHECK_GE(main_throughput().frames_expected, |
| 225 | begin_main_frame_data_.previous_sequence_delta) |
| 226 | << TRACKER_DCHECK_MSG; |
| 227 | main_throughput().frames_expected -= |
| 228 | begin_main_frame_data_.previous_sequence_delta; |
| 229 | last_no_main_damage_sequence_ = previous_begin_main_sequence_; |
| 230 | } |
| 231 | had_impl_frame_submitted_between_commits_ = false; |
| 232 | |
Sadrul Habib Chowdhury | c072db7 | 2020-01-16 02:52:34 | [diff] [blame] | 233 | if (first_received_main_sequence_ && |
| 234 | args.frame_id.sequence_number >= first_received_main_sequence_) { |
Sadrul Habib Chowdhury | 1e28555 | 2020-01-22 02:46:57 | [diff] [blame] | 235 | if (awaiting_main_response_sequence_) { |
| 236 | DCHECK_EQ(awaiting_main_response_sequence_, args.frame_id.sequence_number) |
| 237 | << TRACKER_DCHECK_MSG; |
| 238 | } |
| 239 | DCHECK_EQ(last_processed_main_sequence_latency_, 0u) << TRACKER_DCHECK_MSG; |
| 240 | last_processed_main_sequence_ = args.frame_id.sequence_number; |
| 241 | last_processed_main_sequence_latency_ = |
| 242 | std::max(last_started_impl_sequence_, last_processed_impl_sequence_) - |
| 243 | args.frame_id.sequence_number; |
Sadrul Habib Chowdhury | c072db7 | 2020-01-16 02:52:34 | [diff] [blame] | 244 | awaiting_main_response_sequence_ = 0; |
| 245 | } |
| 246 | } |
| 247 | |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 248 | void FrameSequenceTracker::ReportSubmitFrame( |
| 249 | uint32_t frame_token, |
Sadrul Habib Chowdhury | 40a4d8c | 2019-09-05 03:02:31 | [diff] [blame] | 250 | bool has_missing_content, |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 251 | const viz::BeginFrameAck& ack, |
| 252 | const viz::BeginFrameArgs& origin_args) { |
Xida Chen | 8f5fc49 | 2020-04-02 21:55:04 | [diff] [blame] | 253 | DCHECK_NE(termination_status_, TerminationStatus::kReadyForTermination); |
Xida Chen | 139a8f98 | 2020-04-21 19:34:14 | [diff] [blame] | 254 | |
| 255 | // TODO(crbug.com/1072482): find a proper way to terminate a tracker. |
Xida Chen | 2c92ba9 | 2020-04-30 01:15:21 | [diff] [blame] | 256 | // Right now, we define a magical number |frames_to_terminate_tracker| = 3, |
| 257 | // which means that if this frame_token is more than 3 frames compared with |
Xida Chen | 139a8f98 | 2020-04-21 19:34:14 | [diff] [blame] | 258 | // the last submitted frame, then we assume that the last submitted frame is |
| 259 | // not going to be presented, and thus terminate this tracker. |
Xida Chen | 2c92ba9 | 2020-04-30 01:15:21 | [diff] [blame] | 260 | const uint32_t frames_to_terminate_tracker = 3; |
Xida Chen | 139a8f98 | 2020-04-21 19:34:14 | [diff] [blame] | 261 | if (termination_status_ == TerminationStatus::kScheduledForTermination && |
Xida Chen | 9d403eb | 2020-04-25 00:23:26 | [diff] [blame] | 262 | last_submitted_frame_ != 0 && |
Xida Chen | 139a8f98 | 2020-04-21 19:34:14 | [diff] [blame] | 263 | viz::FrameTokenGT(frame_token, |
| 264 | last_submitted_frame_ + frames_to_terminate_tracker)) { |
| 265 | termination_status_ = TerminationStatus::kReadyForTermination; |
| 266 | return; |
| 267 | } |
| 268 | |
Xida Chen | 8f5fc49 | 2020-04-02 21:55:04 | [diff] [blame] | 269 | if (ShouldIgnoreBeginFrameSource(ack.frame_id.source_id) || |
behdad | 2adc423 | 2019-12-18 18:11:39 | [diff] [blame] | 270 | ShouldIgnoreSequence(ack.frame_id.sequence_number)) { |
Xida Chen | d56033c | 2019-12-05 13:31:41 | [diff] [blame] | 271 | ignored_frame_tokens_.insert(frame_token); |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 272 | return; |
| 273 | } |
| 274 | |
Sadrul Habib Chowdhury | 7fe10ea | 2019-12-11 01:59:29 | [diff] [blame] | 275 | #if DCHECK_IS_ON() |
| 276 | DCHECK(is_inside_frame_) << TRACKER_DCHECK_MSG; |
Xida Chen | 675c2d7 | 2020-01-16 13:06:48 | [diff] [blame] | 277 | DCHECK_LT(impl_throughput().frames_processed, |
| 278 | impl_throughput().frames_received) |
| 279 | << TRACKER_DCHECK_MSG; |
| 280 | ++impl_throughput().frames_processed; |
Sadrul Habib Chowdhury | 7fe10ea | 2019-12-11 01:59:29 | [diff] [blame] | 281 | #endif |
Sadrul Habib Chowdhury | e49c0a6 | 2019-12-22 04:36:22 | [diff] [blame] | 282 | |
Xida Chen | 62007203 | 2020-01-10 17:21:35 | [diff] [blame] | 283 | last_processed_impl_sequence_ = ack.frame_id.sequence_number; |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 284 | if (first_submitted_frame_ == 0) |
| 285 | first_submitted_frame_ = frame_token; |
| 286 | last_submitted_frame_ = frame_token; |
Sadrul Habib Chowdhury | a962eb3 | 2019-12-23 02:21:47 | [diff] [blame] | 287 | compositor_frame_submitted_ = true; |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 288 | |
Xida Chen | 89e1921 | 2020-04-28 14:43:45 | [diff] [blame] | 289 | TRACKER_TRACE_STREAM << "s(" << frame_token % kDebugStrMod << ")"; |
Xida Chen | 8ee29c9a | 2020-01-30 18:59:23 | [diff] [blame] | 290 | had_impl_frame_submitted_between_commits_ = true; |
Mingjing Zhang | 0241cc42 | 2020-10-02 21:27:12 | [diff] [blame] | 291 | metrics()->NotifySubmitForJankReporter( |
| 292 | FrameSequenceMetrics::ThreadType::kCompositor, frame_token, |
| 293 | ack.frame_id.sequence_number); |
Xida Chen | be102af | 2020-03-10 00:52:34 | [diff] [blame] | 294 | |
Sadrul Habib Chowdhury | dc34c8b | 2019-12-16 18:39:13 | [diff] [blame] | 295 | const bool main_changes_after_sequence_started = |
| 296 | first_received_main_sequence_ && |
behdad | 2adc423 | 2019-12-18 18:11:39 | [diff] [blame] | 297 | origin_args.frame_id.sequence_number >= first_received_main_sequence_; |
Sadrul Habib Chowdhury | dc34c8b | 2019-12-16 18:39:13 | [diff] [blame] | 298 | const bool main_changes_include_new_changes = |
| 299 | last_submitted_main_sequence_ == 0 || |
behdad | 2adc423 | 2019-12-18 18:11:39 | [diff] [blame] | 300 | origin_args.frame_id.sequence_number > last_submitted_main_sequence_; |
Sadrul Habib Chowdhury | dc34c8b | 2019-12-16 18:39:13 | [diff] [blame] | 301 | const bool main_change_had_no_damage = |
| 302 | last_no_main_damage_sequence_ != 0 && |
behdad | 2adc423 | 2019-12-18 18:11:39 | [diff] [blame] | 303 | origin_args.frame_id.sequence_number == last_no_main_damage_sequence_; |
Xida Chen | 8f5fc49 | 2020-04-02 21:55:04 | [diff] [blame] | 304 | const bool origin_args_is_valid = origin_args.frame_id.sequence_number <= |
| 305 | begin_main_frame_data_.previous_sequence; |
Mingjing Zhang | 9431496 | 2019-11-05 02:59:20 | [diff] [blame] | 306 | |
Xida Chen | 8f5fc49 | 2020-04-02 21:55:04 | [diff] [blame] | 307 | if (!ShouldIgnoreBeginFrameSource(origin_args.frame_id.source_id) && |
| 308 | origin_args_is_valid) { |
Xida Chen | bc14a11 | 2020-03-30 18:22:58 | [diff] [blame] | 309 | if (main_changes_after_sequence_started && |
| 310 | main_changes_include_new_changes && !main_change_had_no_damage) { |
| 311 | submitted_frame_had_new_main_content_ = true; |
Xida Chen | 89e1921 | 2020-04-28 14:43:45 | [diff] [blame] | 312 | TRACKER_TRACE_STREAM << "S(" |
| 313 | << origin_args.frame_id.sequence_number % |
| 314 | kDebugStrMod |
Xida Chen | bc14a11 | 2020-03-30 18:22:58 | [diff] [blame] | 315 | << ")"; |
Mingjing Zhang | 0241cc42 | 2020-10-02 21:27:12 | [diff] [blame] | 316 | metrics()->NotifySubmitForJankReporter( |
| 317 | FrameSequenceMetrics::ThreadType::kMain, frame_token, |
| 318 | origin_args.frame_id.sequence_number); |
Sadrul Habib Chowdhury | dc34c8b | 2019-12-16 18:39:13 | [diff] [blame] | 319 | |
Xida Chen | bc14a11 | 2020-03-30 18:22:58 | [diff] [blame] | 320 | last_submitted_main_sequence_ = origin_args.frame_id.sequence_number; |
| 321 | main_frames_.push_back(frame_token); |
| 322 | DCHECK_GE(main_throughput().frames_expected, main_frames_.size()) |
| 323 | << TRACKER_DCHECK_MSG; |
Xida Chen | bc14a11 | 2020-03-30 18:22:58 | [diff] [blame] | 324 | } |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 325 | } |
Sadrul Habib Chowdhury | 40a4d8c | 2019-09-05 03:02:31 | [diff] [blame] | 326 | |
| 327 | if (has_missing_content) { |
| 328 | checkerboarding_.frames.push_back(frame_token); |
| 329 | } |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 330 | } |
| 331 | |
Sadrul Habib Chowdhury | 61e0266 | 2020-01-31 20:55:33 | [diff] [blame] | 332 | void FrameSequenceTracker::ReportFrameEnd( |
| 333 | const viz::BeginFrameArgs& args, |
| 334 | const viz::BeginFrameArgs& main_args) { |
Xida Chen | 8f5fc49 | 2020-04-02 21:55:04 | [diff] [blame] | 335 | DCHECK_NE(termination_status_, TerminationStatus::kReadyForTermination); |
Sadrul Habib Chowdhury | 7fe10ea | 2019-12-11 01:59:29 | [diff] [blame] | 336 | |
behdad | 2adc423 | 2019-12-18 18:11:39 | [diff] [blame] | 337 | if (ShouldIgnoreBeginFrameSource(args.frame_id.source_id)) |
Sadrul Habib Chowdhury | 7fe10ea | 2019-12-11 01:59:29 | [diff] [blame] | 338 | return; |
| 339 | |
Xida Chen | 89e1921 | 2020-04-28 14:43:45 | [diff] [blame] | 340 | TRACKER_TRACE_STREAM << "e(" << args.frame_id.sequence_number % kDebugStrMod |
| 341 | << "," |
| 342 | << main_args.frame_id.sequence_number % kDebugStrMod |
| 343 | << ")"; |
Sadrul Habib Chowdhury | a962eb3 | 2019-12-23 02:21:47 | [diff] [blame] | 344 | |
Sadrul Habib Chowdhury | 634b8e01 | 2019-12-23 13:46:12 | [diff] [blame] | 345 | bool should_ignore_sequence = |
| 346 | ShouldIgnoreSequence(args.frame_id.sequence_number); |
| 347 | if (reset_all_state_) { |
| 348 | begin_impl_frame_data_ = {}; |
| 349 | begin_main_frame_data_ = {}; |
| 350 | reset_all_state_ = false; |
| 351 | } |
| 352 | |
| 353 | if (should_ignore_sequence) { |
Sadrul Habib Chowdhury | 634b8e01 | 2019-12-23 13:46:12 | [diff] [blame] | 354 | is_inside_frame_ = false; |
Sadrul Habib Chowdhury | 634b8e01 | 2019-12-23 13:46:12 | [diff] [blame] | 355 | return; |
| 356 | } |
| 357 | |
Sadrul Habib Chowdhury | 1e28555 | 2020-01-22 02:46:57 | [diff] [blame] | 358 | if (compositor_frame_submitted_ && submitted_frame_had_new_main_content_ && |
| 359 | last_processed_main_sequence_latency_) { |
| 360 | // If a compositor frame was submitted with new content from the |
| 361 | // main-thread, then make sure the latency gets accounted for. |
| 362 | main_throughput().frames_expected += last_processed_main_sequence_latency_; |
| 363 | } |
| 364 | |
Sadrul Habib Chowdhury | a962eb3 | 2019-12-23 02:21:47 | [diff] [blame] | 365 | // It is possible that the compositor claims there was no damage from the |
| 366 | // compositor, but before the frame ends, it submits a compositor frame (e.g. |
| 367 | // with some damage from main). In such cases, the compositor is still |
| 368 | // responsible for processing the update, and therefore the 'no damage' claim |
| 369 | // is ignored. |
| 370 | if (frame_had_no_compositor_damage_ && !compositor_frame_submitted_) { |
| 371 | DCHECK_GT(impl_throughput().frames_expected, 0u) << TRACKER_DCHECK_MSG; |
| 372 | DCHECK_GT(impl_throughput().frames_expected, |
| 373 | impl_throughput().frames_produced) |
| 374 | << TRACKER_DCHECK_MSG; |
Matthew Crabill | 79be85f | 2020-09-16 19:02:58 | [diff] [blame] | 375 | DCHECK_GE(impl_throughput().frames_produced, |
| 376 | impl_throughput().frames_ontime) |
| 377 | << TRACKER_DCHECK_MSG; |
Sadrul Habib Chowdhury | a962eb3 | 2019-12-23 02:21:47 | [diff] [blame] | 378 | --impl_throughput().frames_expected; |
Mingjing Zhang | 0241cc42 | 2020-10-02 21:27:12 | [diff] [blame] | 379 | metrics()->NotifyNoUpdateForJankReporter( |
| 380 | FrameSequenceMetrics::ThreadType::kCompositor, |
| 381 | args.frame_id.sequence_number, args.interval); |
Xida Chen | 675c2d7 | 2020-01-16 13:06:48 | [diff] [blame] | 382 | #if DCHECK_IS_ON() |
Xida Chen | 675c2d7 | 2020-01-16 13:06:48 | [diff] [blame] | 383 | ++impl_throughput().frames_processed; |
Xida Chen | 4bde850d | 2020-01-22 20:25:40 | [diff] [blame] | 384 | // If these two are the same, it means that each impl frame is either |
| 385 | // no-damage or submitted. That's expected, so we don't need those in the |
| 386 | // output of DCHECK. |
| 387 | if (impl_throughput().frames_processed == impl_throughput().frames_received) |
| 388 | ignored_trace_char_count_ = frame_sequence_trace_.str().size(); |
| 389 | else |
| 390 | NOTREACHED() << TRACKER_DCHECK_MSG; |
Xida Chen | 675c2d7 | 2020-01-16 13:06:48 | [diff] [blame] | 391 | #endif |
Sadrul Habib Chowdhury | a962eb3 | 2019-12-23 02:21:47 | [diff] [blame] | 392 | begin_impl_frame_data_.previous_sequence = 0; |
| 393 | } |
Xida Chen | 8f5fc49 | 2020-04-02 21:55:04 | [diff] [blame] | 394 | // last_submitted_frame_ == 0 means the last impl frame has been presented. |
| 395 | if (termination_status_ == TerminationStatus::kScheduledForTermination && |
| 396 | last_submitted_frame_ == 0) |
| 397 | termination_status_ = TerminationStatus::kReadyForTermination; |
| 398 | |
Sadrul Habib Chowdhury | a962eb3 | 2019-12-23 02:21:47 | [diff] [blame] | 399 | frame_had_no_compositor_damage_ = false; |
| 400 | compositor_frame_submitted_ = false; |
Sadrul Habib Chowdhury | 1e28555 | 2020-01-22 02:46:57 | [diff] [blame] | 401 | submitted_frame_had_new_main_content_ = false; |
| 402 | last_processed_main_sequence_latency_ = 0; |
Sadrul Habib Chowdhury | a962eb3 | 2019-12-23 02:21:47 | [diff] [blame] | 403 | |
Sadrul Habib Chowdhury | 7fe10ea | 2019-12-11 01:59:29 | [diff] [blame] | 404 | DCHECK(is_inside_frame_) << TRACKER_DCHECK_MSG; |
| 405 | is_inside_frame_ = false; |
Xida Chen | 62007203 | 2020-01-10 17:21:35 | [diff] [blame] | 406 | |
Sadrul Habib Chowdhury | 1e28555 | 2020-01-22 02:46:57 | [diff] [blame] | 407 | DCHECK_EQ(last_started_impl_sequence_, last_processed_impl_sequence_) |
| 408 | << TRACKER_DCHECK_MSG; |
| 409 | last_started_impl_sequence_ = 0; |
Sadrul Habib Chowdhury | 7fe10ea | 2019-12-11 01:59:29 | [diff] [blame] | 410 | } |
| 411 | |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 412 | void FrameSequenceTracker::ReportFramePresented( |
| 413 | uint32_t frame_token, |
| 414 | const gfx::PresentationFeedback& feedback) { |
Xida Chen | c9e3b62 | 2020-04-17 17:29:11 | [diff] [blame] | 415 | // TODO(xidachen): We should early exit if |last_submitted_frame_| = 0, as it |
| 416 | // means that we are presenting the same frame_token again. |
| 417 | const bool submitted_frame_since_last_presentation = !!last_submitted_frame_; |
Xida Chen | 8f5fc49 | 2020-04-02 21:55:04 | [diff] [blame] | 418 | // !viz::FrameTokenGT(a, b) is equivalent to b >= a. |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 419 | const bool frame_token_acks_last_frame = |
Xida Chen | 8f5fc49 | 2020-04-02 21:55:04 | [diff] [blame] | 420 | !viz::FrameTokenGT(last_submitted_frame_, frame_token); |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 421 | |
Xida Chen | c9e3b62 | 2020-04-17 17:29:11 | [diff] [blame] | 422 | // Even if the presentation timestamp is null, we set last_submitted_frame_ to |
| 423 | // 0 such that the tracker can be terminated. |
| 424 | if (last_submitted_frame_ && frame_token_acks_last_frame) |
| 425 | last_submitted_frame_ = 0; |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 426 | // Update termination status if this is scheduled for termination, and it is |
| 427 | // not waiting for any frames, or it has received the presentation-feedback |
| 428 | // for the latest frame it is tracking. |
Xida Chen | 8f5fc49 | 2020-04-02 21:55:04 | [diff] [blame] | 429 | // |
| 430 | // We should always wait for an impl frame to end, that is, ReportFrameEnd. |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 431 | if (termination_status_ == TerminationStatus::kScheduledForTermination && |
Xida Chen | c9e3b62 | 2020-04-17 17:29:11 | [diff] [blame] | 432 | last_submitted_frame_ == 0 && !is_inside_frame_) { |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 433 | termination_status_ = TerminationStatus::kReadyForTermination; |
| 434 | } |
| 435 | |
| 436 | if (first_submitted_frame_ == 0 || |
| 437 | viz::FrameTokenGT(first_submitted_frame_, frame_token)) { |
| 438 | // We are getting presentation feedback for frames that were submitted |
| 439 | // before this sequence started. So ignore these. |
| 440 | return; |
| 441 | } |
| 442 | |
Xida Chen | 89e1921 | 2020-04-28 14:43:45 | [diff] [blame] | 443 | TRACKER_TRACE_STREAM << "P(" << frame_token % kDebugStrMod << ")"; |
Sadrul Habib Chowdhury | 2f848d2 | 2019-12-23 16:34:09 | [diff] [blame] | 444 | |
Xida Chen | 8f5fc49 | 2020-04-02 21:55:04 | [diff] [blame] | 445 | base::EraseIf(ignored_frame_tokens_, [frame_token](const uint32_t& token) { |
| 446 | return viz::FrameTokenGT(frame_token, token); |
| 447 | }); |
Xida Chen | c9e3b62 | 2020-04-17 17:29:11 | [diff] [blame] | 448 | if (ignored_frame_tokens_.contains(frame_token)) |
| 449 | return; |
Xida Chen | d56033c | 2019-12-05 13:31:41 | [diff] [blame] | 450 | |
Xida Chen | bc14a11 | 2020-03-30 18:22:58 | [diff] [blame] | 451 | uint32_t impl_frames_produced = 0; |
| 452 | uint32_t main_frames_produced = 0; |
Matthew Crabill | 79be85f | 2020-09-16 19:02:58 | [diff] [blame] | 453 | uint32_t impl_frames_ontime = 0; |
| 454 | uint32_t main_frames_ontime = 0; |
| 455 | |
Mingjing Zhang | 45ebbbe5 | 2021-01-07 17:42:35 | [diff] [blame] | 456 | const auto vsync_interval = |
Matthew Crabill | 79be85f | 2020-09-16 19:02:58 | [diff] [blame] | 457 | (feedback.interval.is_zero() ? viz::BeginFrameArgs::DefaultInterval() |
Mingjing Zhang | 45ebbbe5 | 2021-01-07 17:42:35 | [diff] [blame] | 458 | : feedback.interval); |
Matthew Crabill | 79be85f | 2020-09-16 19:02:58 | [diff] [blame] | 459 | DCHECK(!vsync_interval.is_zero()) << TRACKER_DCHECK_MSG; |
| 460 | base::TimeTicks safe_deadline_for_frame = |
Mingjing Zhang | 45ebbbe5 | 2021-01-07 17:42:35 | [diff] [blame] | 461 | last_frame_presentation_timestamp_ + vsync_interval * 1.5; |
Sadrul Habib Chowdhury | 6d7b07d76 | 2020-03-13 15:42:08 | [diff] [blame] | 462 | |
Sadrul Habib Chowdhury | d5f5881 | 2020-06-11 21:30:52 | [diff] [blame] | 463 | const bool was_presented = !feedback.failed(); |
Xida Chen | c9e3b62 | 2020-04-17 17:29:11 | [diff] [blame] | 464 | if (was_presented && submitted_frame_since_last_presentation) { |
Matthew Crabill | 79be85f | 2020-09-16 19:02:58 | [diff] [blame] | 465 | if (!last_frame_presentation_timestamp_.is_null() && |
| 466 | (safe_deadline_for_frame < feedback.timestamp)) { |
| 467 | DCHECK_LE(impl_throughput().frames_ontime, |
| 468 | impl_throughput().frames_produced) |
| 469 | << TRACKER_DCHECK_MSG; |
| 470 | ++impl_throughput().frames_ontime; |
| 471 | ++impl_frames_ontime; |
| 472 | } |
| 473 | |
Sadrul Habib Chowdhury | c537f2f4 | 2019-12-05 19:52:28 | [diff] [blame] | 474 | DCHECK_LT(impl_throughput().frames_produced, |
| 475 | impl_throughput().frames_expected) |
Mingjing Zhang | 2879aa89 | 2019-11-01 02:54:54 | [diff] [blame] | 476 | << TRACKER_DCHECK_MSG; |
Sadrul Habib Chowdhury | c537f2f4 | 2019-12-05 19:52:28 | [diff] [blame] | 477 | ++impl_throughput().frames_produced; |
Xida Chen | bc14a11 | 2020-03-30 18:22:58 | [diff] [blame] | 478 | ++impl_frames_produced; |
Sadrul Habib Chowdhury | b533566 | 2020-06-16 18:17:40 | [diff] [blame] | 479 | if (metrics()->GetEffectiveThread() == ThreadType::kCompositor) { |
| 480 | metrics()->AdvanceTrace(feedback.timestamp); |
| 481 | } |
Mingjing Zhang | 45946b2 | 2020-08-14 23:18:18 | [diff] [blame] | 482 | |
| 483 | metrics()->ComputeJank(FrameSequenceMetrics::ThreadType::kCompositor, |
Mingjing Zhang | 45ebbbe5 | 2021-01-07 17:42:35 | [diff] [blame] | 484 | frame_token, feedback.timestamp, vsync_interval); |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 485 | } |
| 486 | |
Xida Chen | be102af | 2020-03-10 00:52:34 | [diff] [blame] | 487 | if (was_presented) { |
| 488 | // This presentation includes the visual update from all main frame tokens |
| 489 | // <= |frame_token|. |
| 490 | const unsigned size_before_erase = main_frames_.size(); |
| 491 | while (!main_frames_.empty() && |
| 492 | !viz::FrameTokenGT(main_frames_.front(), frame_token)) { |
| 493 | main_frames_.pop_front(); |
| 494 | } |
| 495 | if (main_frames_.size() < size_before_erase) { |
Sadrul Habib Chowdhury | c537f2f4 | 2019-12-05 19:52:28 | [diff] [blame] | 496 | DCHECK_LT(main_throughput().frames_produced, |
| 497 | main_throughput().frames_expected) |
Mingjing Zhang | 9431496 | 2019-11-05 02:59:20 | [diff] [blame] | 498 | << TRACKER_DCHECK_MSG; |
Sadrul Habib Chowdhury | c537f2f4 | 2019-12-05 19:52:28 | [diff] [blame] | 499 | ++main_throughput().frames_produced; |
Xida Chen | bc14a11 | 2020-03-30 18:22:58 | [diff] [blame] | 500 | ++main_frames_produced; |
Sadrul Habib Chowdhury | b533566 | 2020-06-16 18:17:40 | [diff] [blame] | 501 | if (metrics()->GetEffectiveThread() == ThreadType::kMain) { |
| 502 | metrics()->AdvanceTrace(feedback.timestamp); |
| 503 | } |
Mingjing Zhang | 45946b2 | 2020-08-14 23:18:18 | [diff] [blame] | 504 | |
| 505 | metrics()->ComputeJank(FrameSequenceMetrics::ThreadType::kMain, |
Mingjing Zhang | 45ebbbe5 | 2021-01-07 17:42:35 | [diff] [blame] | 506 | frame_token, feedback.timestamp, vsync_interval); |
Xida Chen | bc14a11 | 2020-03-30 18:22:58 | [diff] [blame] | 507 | } |
Matthew Crabill | 79be85f | 2020-09-16 19:02:58 | [diff] [blame] | 508 | if (main_frames_.size() < size_before_erase) { |
| 509 | if (!last_frame_presentation_timestamp_.is_null() && |
| 510 | (safe_deadline_for_frame < feedback.timestamp)) { |
| 511 | DCHECK_LE(main_throughput().frames_ontime, |
| 512 | main_throughput().frames_produced) |
| 513 | << TRACKER_DCHECK_MSG; |
| 514 | ++main_throughput().frames_ontime; |
| 515 | ++main_frames_ontime; |
| 516 | } |
| 517 | } |
Matthew Crabill | 79be85f | 2020-09-16 19:02:58 | [diff] [blame] | 518 | last_frame_presentation_timestamp_ = feedback.timestamp; |
| 519 | |
Sadrul Habib Chowdhury | 40a4d8c | 2019-09-05 03:02:31 | [diff] [blame] | 520 | if (checkerboarding_.last_frame_had_checkerboarding) { |
Mingjing Zhang | 2879aa89 | 2019-11-01 02:54:54 | [diff] [blame] | 521 | DCHECK(!checkerboarding_.last_frame_timestamp.is_null()) |
| 522 | << TRACKER_DCHECK_MSG; |
| 523 | DCHECK(!feedback.timestamp.is_null()) << TRACKER_DCHECK_MSG; |
Sadrul Habib Chowdhury | 40a4d8c | 2019-09-05 03:02:31 | [diff] [blame] | 524 | |
| 525 | // |feedback.timestamp| is the timestamp when the latest frame was |
| 526 | // presented. |checkerboarding_.last_frame_timestamp| is the timestamp |
| 527 | // when the previous frame (which had checkerboarding) was presented. Use |
| 528 | // |feedback.interval| to compute the number of vsyncs that have passed |
| 529 | // between the two frames (since that is how many times the user saw that |
| 530 | // checkerboarded frame). |
| 531 | base::TimeDelta difference = |
| 532 | feedback.timestamp - checkerboarding_.last_frame_timestamp; |
| 533 | const auto& interval = feedback.interval.is_zero() |
| 534 | ? viz::BeginFrameArgs::DefaultInterval() |
| 535 | : feedback.interval; |
Mingjing Zhang | 2879aa89 | 2019-11-01 02:54:54 | [diff] [blame] | 536 | DCHECK(!interval.is_zero()) << TRACKER_DCHECK_MSG; |
Sadrul Habib Chowdhury | 40a4d8c | 2019-09-05 03:02:31 | [diff] [blame] | 537 | constexpr base::TimeDelta kEpsilon = base::TimeDelta::FromMilliseconds(1); |
Peter Kasting | d0bcff9 | 2020-08-01 21:50:58 | [diff] [blame] | 538 | int64_t frames = (difference + kEpsilon).IntDiv(interval); |
Sadrul Habib Chowdhury | 590a32f | 2019-12-06 20:08:45 | [diff] [blame] | 539 | metrics_->add_checkerboarded_frames(frames); |
Sadrul Habib Chowdhury | 40a4d8c | 2019-09-05 03:02:31 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | const bool frame_had_checkerboarding = |
| 543 | base::Contains(checkerboarding_.frames, frame_token); |
| 544 | checkerboarding_.last_frame_had_checkerboarding = frame_had_checkerboarding; |
| 545 | checkerboarding_.last_frame_timestamp = feedback.timestamp; |
| 546 | } |
| 547 | |
| 548 | while (!checkerboarding_.frames.empty() && |
| 549 | !viz::FrameTokenGT(checkerboarding_.frames.front(), frame_token)) { |
| 550 | checkerboarding_.frames.pop_front(); |
| 551 | } |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | void FrameSequenceTracker::ReportImplFrameCausedNoDamage( |
| 555 | const viz::BeginFrameAck& ack) { |
Xida Chen | 8f5fc49 | 2020-04-02 21:55:04 | [diff] [blame] | 556 | DCHECK_NE(termination_status_, TerminationStatus::kReadyForTermination); |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 557 | |
behdad | 2adc423 | 2019-12-18 18:11:39 | [diff] [blame] | 558 | if (ShouldIgnoreBeginFrameSource(ack.frame_id.source_id)) |
Sadrul Habib Chowdhury | 2391917 | 2019-07-22 23:58:50 | [diff] [blame] | 559 | return; |
| 560 | |
Xida Chen | 89e1921 | 2020-04-28 14:43:45 | [diff] [blame] | 561 | TRACKER_TRACE_STREAM << "n(" << ack.frame_id.sequence_number % kDebugStrMod |
| 562 | << ")"; |
Sadrul Habib Chowdhury | e49c0a6 | 2019-12-22 04:36:22 | [diff] [blame] | 563 | |
Xida Chen | 8f5fc49 | 2020-04-02 21:55:04 | [diff] [blame] | 564 | // This tracker would be scheduled to terminate, and this frame doesn't belong |
| 565 | // to that tracker. |
behdad | 2adc423 | 2019-12-18 18:11:39 | [diff] [blame] | 566 | if (ShouldIgnoreSequence(ack.frame_id.sequence_number)) |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 567 | return; |
Sadrul Habib Chowdhury | e49c0a6 | 2019-12-22 04:36:22 | [diff] [blame] | 568 | |
Sadrul Habib Chowdhury | 1c1af9f | 2019-12-20 03:52:46 | [diff] [blame] | 569 | last_processed_impl_sequence_ = ack.frame_id.sequence_number; |
Sadrul Habib Chowdhury | a962eb3 | 2019-12-23 02:21:47 | [diff] [blame] | 570 | // If there is no damage for this frame (and no frame is submitted), then the |
| 571 | // impl-sequence needs to be reset. However, this should be done after the |
| 572 | // processing the frame is complete (i.e. in ReportFrameEnd()), so that other |
| 573 | // notifications (e.g. 'no main damage' etc.) can be handled correctly. |
| 574 | DCHECK_EQ(begin_impl_frame_data_.previous_sequence, |
| 575 | ack.frame_id.sequence_number); |
| 576 | frame_had_no_compositor_damage_ = true; |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | void FrameSequenceTracker::ReportMainFrameCausedNoDamage( |
| 580 | const viz::BeginFrameArgs& args) { |
| 581 | if (termination_status_ != TerminationStatus::kActive) |
| 582 | return; |
| 583 | |
behdad | 2adc423 | 2019-12-18 18:11:39 | [diff] [blame] | 584 | if (ShouldIgnoreBeginFrameSource(args.frame_id.source_id)) |
Sadrul Habib Chowdhury | 2391917 | 2019-07-22 23:58:50 | [diff] [blame] | 585 | return; |
| 586 | |
Xida Chen | 89e1921 | 2020-04-28 14:43:45 | [diff] [blame] | 587 | TRACKER_TRACE_STREAM << "N(" |
| 588 | << begin_main_frame_data_.previous_sequence % |
| 589 | kDebugStrMod |
| 590 | << "," << args.frame_id.sequence_number % kDebugStrMod |
| 591 | << ")"; |
Sadrul Habib Chowdhury | 2f848d2 | 2019-12-23 16:34:09 | [diff] [blame] | 592 | |
Sadrul Habib Chowdhury | 90aa1fd | 2020-01-13 16:36:17 | [diff] [blame] | 593 | if (!first_received_main_sequence_ || |
| 594 | first_received_main_sequence_ > args.frame_id.sequence_number) { |
Xida Chen | d56033c | 2019-12-05 13:31:41 | [diff] [blame] | 595 | return; |
Sadrul Habib Chowdhury | 90aa1fd | 2020-01-13 16:36:17 | [diff] [blame] | 596 | } |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 597 | |
Sadrul Habib Chowdhury | a962eb3 | 2019-12-23 02:21:47 | [diff] [blame] | 598 | if (last_no_main_damage_sequence_ == args.frame_id.sequence_number) |
| 599 | return; |
Sadrul Habib Chowdhury | e49c0a6 | 2019-12-22 04:36:22 | [diff] [blame] | 600 | |
Sadrul Habib Chowdhury | 1e28555 | 2020-01-22 02:46:57 | [diff] [blame] | 601 | // It is possible for |awaiting_main_response_sequence_| to be zero here if a |
| 602 | // commit had already happened before (e.g. B(x)E(x)N(x)). So check that case |
| 603 | // here. |
Sadrul Habib Chowdhury | 1e28555 | 2020-01-22 02:46:57 | [diff] [blame] | 604 | if (awaiting_main_response_sequence_) { |
| 605 | DCHECK_EQ(awaiting_main_response_sequence_, args.frame_id.sequence_number) |
| 606 | << TRACKER_DCHECK_MSG; |
| 607 | } else { |
| 608 | DCHECK_EQ(last_processed_main_sequence_, args.frame_id.sequence_number) |
| 609 | << TRACKER_DCHECK_MSG; |
| 610 | } |
Sadrul Habib Chowdhury | c072db7 | 2020-01-16 02:52:34 | [diff] [blame] | 611 | awaiting_main_response_sequence_ = 0; |
| 612 | |
Sadrul Habib Chowdhury | c537f2f4 | 2019-12-05 19:52:28 | [diff] [blame] | 613 | DCHECK_GT(main_throughput().frames_expected, 0u) << TRACKER_DCHECK_MSG; |
| 614 | DCHECK_GT(main_throughput().frames_expected, |
| 615 | main_throughput().frames_produced) |
Mingjing Zhang | 2879aa89 | 2019-11-01 02:54:54 | [diff] [blame] | 616 | << TRACKER_DCHECK_MSG; |
Matthew Crabill | 79be85f | 2020-09-16 19:02:58 | [diff] [blame] | 617 | DCHECK_GE(main_throughput().frames_produced, main_throughput().frames_ontime) |
| 618 | << TRACKER_DCHECK_MSG; |
behdad | 2adc423 | 2019-12-18 18:11:39 | [diff] [blame] | 619 | last_no_main_damage_sequence_ = args.frame_id.sequence_number; |
Sadrul Habib Chowdhury | c537f2f4 | 2019-12-05 19:52:28 | [diff] [blame] | 620 | --main_throughput().frames_expected; |
Mingjing Zhang | 0241cc42 | 2020-10-02 21:27:12 | [diff] [blame] | 621 | metrics()->NotifyNoUpdateForJankReporter( |
| 622 | FrameSequenceMetrics::ThreadType::kMain, args.frame_id.sequence_number, |
| 623 | args.interval); |
| 624 | |
Sadrul Habib Chowdhury | c537f2f4 | 2019-12-05 19:52:28 | [diff] [blame] | 625 | DCHECK_GE(main_throughput().frames_expected, main_frames_.size()) |
Mingjing Zhang | 2879aa89 | 2019-11-01 02:54:54 | [diff] [blame] | 626 | << TRACKER_DCHECK_MSG; |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 627 | |
Xida Chen | 432fefd5 | 2020-03-17 23:20:03 | [diff] [blame] | 628 | // Could be 0 if there were a pause frame production. |
| 629 | if (begin_main_frame_data_.previous_sequence != 0) { |
| 630 | DCHECK_EQ(begin_main_frame_data_.previous_sequence, |
| 631 | args.frame_id.sequence_number) |
| 632 | << TRACKER_DCHECK_MSG; |
| 633 | } |
| 634 | begin_main_frame_data_.previous_sequence = 0; |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | void FrameSequenceTracker::PauseFrameProduction() { |
Sadrul Habib Chowdhury | 634b8e01 | 2019-12-23 13:46:12 | [diff] [blame] | 638 | // The states need to be reset, so that the tracker ignores the vsyncs until |
| 639 | // the next received begin-frame. However, defer doing that until the frame |
| 640 | // ends (or a new frame starts), so that in case a frame is in-progress, |
| 641 | // subsequent notifications for that frame can be handled correctly. |
Sadrul Habib Chowdhury | 1c1af9f | 2019-12-20 03:52:46 | [diff] [blame] | 642 | TRACKER_TRACE_STREAM << 'R'; |
Sadrul Habib Chowdhury | 634b8e01 | 2019-12-23 13:46:12 | [diff] [blame] | 643 | reset_all_state_ = true; |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 644 | } |
| 645 | |
yjliu | 9d3df97 | 2021-04-08 17:03:49 | [diff] [blame] | 646 | void FrameSequenceTracker::UpdateTrackedFrameData( |
| 647 | TrackedFrameData* frame_data, |
| 648 | uint64_t source_id, |
| 649 | uint64_t sequence_number, |
| 650 | uint64_t throttled_frame_count) { |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 651 | if (frame_data->previous_sequence && |
| 652 | frame_data->previous_source == source_id) { |
yjliu | 9d3df97 | 2021-04-08 17:03:49 | [diff] [blame] | 653 | uint32_t current_latency = |
| 654 | sequence_number - frame_data->previous_sequence - throttled_frame_count; |
Sadrul Habib Chowdhury | 1e28555 | 2020-01-22 02:46:57 | [diff] [blame] | 655 | DCHECK_GT(current_latency, 0u) << TRACKER_DCHECK_MSG; |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 656 | frame_data->previous_sequence_delta = current_latency; |
| 657 | } else { |
| 658 | frame_data->previous_sequence_delta = 1; |
| 659 | } |
| 660 | frame_data->previous_source = source_id; |
| 661 | frame_data->previous_sequence = sequence_number; |
| 662 | } |
| 663 | |
Sadrul Habib Chowdhury | 2391917 | 2019-07-22 23:58:50 | [diff] [blame] | 664 | bool FrameSequenceTracker::ShouldIgnoreBeginFrameSource( |
| 665 | uint64_t source_id) const { |
| 666 | if (begin_impl_frame_data_.previous_source == 0) |
Sadrul Habib Chowdhury | 1c1af9f | 2019-12-20 03:52:46 | [diff] [blame] | 667 | return source_id == viz::BeginFrameArgs::kManualSourceId; |
Sadrul Habib Chowdhury | 2391917 | 2019-07-22 23:58:50 | [diff] [blame] | 668 | return source_id != begin_impl_frame_data_.previous_source; |
| 669 | } |
| 670 | |
Xida Chen | 8f5fc49 | 2020-04-02 21:55:04 | [diff] [blame] | 671 | // This check handles two cases: |
| 672 | // 1. When there is a call to ReportBeginMainFrame, or ReportSubmitFrame, or |
| 673 | // ReportFramePresented, there must be a ReportBeginImplFrame for that sequence. |
| 674 | // Otherwise, the begin_impl_frame_data_.previous_sequence would be 0. |
| 675 | // 2. A tracker is scheduled to terminate, then any new request to handle a new |
| 676 | // impl frame whose sequence_number > begin_impl_frame_data_.previous_sequence |
| 677 | // should be ignored. |
| 678 | // Note that sequence_number < begin_impl_frame_data_.previous_sequence cannot |
| 679 | // happen. |
Xida Chen | d56033c | 2019-12-05 13:31:41 | [diff] [blame] | 680 | bool FrameSequenceTracker::ShouldIgnoreSequence( |
| 681 | uint64_t sequence_number) const { |
Xida Chen | 8f5fc49 | 2020-04-02 21:55:04 | [diff] [blame] | 682 | return sequence_number != begin_impl_frame_data_.previous_sequence; |
Xida Chen | d56033c | 2019-12-05 13:31:41 | [diff] [blame] | 683 | } |
| 684 | |
Xida Chen | 1102307b | 2019-10-11 17:03:15 | [diff] [blame] | 685 | bool FrameSequenceTracker::ShouldReportMetricsNow( |
| 686 | const viz::BeginFrameArgs& args) const { |
Sadrul Habib Chowdhury | 590a32f | 2019-12-06 20:08:45 | [diff] [blame] | 687 | return metrics_->HasEnoughDataForReporting() && |
| 688 | !first_frame_timestamp_.is_null() && |
| 689 | args.frame_time - first_frame_timestamp_ >= time_delta_to_report_; |
| 690 | } |
| 691 | |
| 692 | std::unique_ptr<FrameSequenceMetrics> FrameSequenceTracker::TakeMetrics() { |
Xida Chen | 8f5fc49 | 2020-04-02 21:55:04 | [diff] [blame] | 693 | #if DCHECK_IS_ON() |
| 694 | DCHECK_EQ(impl_throughput().frames_received, |
| 695 | impl_throughput().frames_processed) |
| 696 | << frame_sequence_trace_.str().substr(ignored_trace_char_count_); |
| 697 | #endif |
Sadrul Habib Chowdhury | 590a32f | 2019-12-06 20:08:45 | [diff] [blame] | 698 | return std::move(metrics_); |
Xida Chen | 1102307b | 2019-10-11 17:03:15 | [diff] [blame] | 699 | } |
| 700 | |
Xida Chen | c89c1c9 | 2020-07-26 00:42:04 | [diff] [blame] | 701 | void FrameSequenceTracker::CleanUp() { |
| 702 | if (metrics_) |
| 703 | metrics_->ReportLeftoverData(); |
| 704 | } |
| 705 | |
Sadrul Habib Chowdhury | 40a4d8c | 2019-09-05 03:02:31 | [diff] [blame] | 706 | FrameSequenceTracker::CheckerboardingData::CheckerboardingData() = default; |
| 707 | FrameSequenceTracker::CheckerboardingData::~CheckerboardingData() = default; |
| 708 | |
Sadrul Habib Chowdhury | ab4d350f | 2019-07-13 00:17:37 | [diff] [blame] | 709 | } // namespace cc |