OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/compositor_timing_history.h" | 5 #include "cc/scheduler/compositor_timing_history.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/trace_event/trace_event.h" | 8 #include "base/trace_event/trace_event.h" |
9 #include "cc/debug/rendering_stats_instrumentation.h" | 9 #include "cc/debug/rendering_stats_instrumentation.h" |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... |
31 bool affects_estimate) = 0; | 31 bool affects_estimate) = 0; |
32 }; | 32 }; |
33 | 33 |
34 namespace { | 34 namespace { |
35 | 35 |
36 // Using the 90th percentile will disable latency recovery | 36 // Using the 90th percentile will disable latency recovery |
37 // if we are missing the deadline approximately ~6 times per | 37 // if we are missing the deadline approximately ~6 times per |
38 // second. | 38 // second. |
39 // TODO(brianderson): Fine tune the percentiles below. | 39 // TODO(brianderson): Fine tune the percentiles below. |
40 const size_t kDurationHistorySize = 60; | 40 const size_t kDurationHistorySize = 60; |
41 const size_t kDrawsBeforeEstimatesAffected = 2; | |
42 const double kBeginMainFrameToCommitEstimationPercentile = 90.0; | 41 const double kBeginMainFrameToCommitEstimationPercentile = 90.0; |
43 const double kCommitToReadyToActivateEstimationPercentile = 90.0; | 42 const double kCommitToReadyToActivateEstimationPercentile = 90.0; |
44 const double kPrepareTilesEstimationPercentile = 90.0; | 43 const double kPrepareTilesEstimationPercentile = 90.0; |
45 const double kActivateEstimationPercentile = 90.0; | 44 const double kActivateEstimationPercentile = 90.0; |
46 const double kDrawEstimationPercentile = 90.0; | 45 const double kDrawEstimationPercentile = 90.0; |
47 | 46 |
48 const int kUmaDurationMinMicros = 1; | 47 const int kUmaDurationMinMicros = 1; |
49 const int64 kUmaDurationMaxMicros = 1 * base::Time::kMicrosecondsPerSecond; | 48 const int64 kUmaDurationMaxMicros = 1 * base::Time::kMicrosecondsPerSecond; |
50 const size_t kUmaDurationBucketCount = 100; | 49 const size_t kUmaDurationBucketCount = 100; |
51 | 50 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 base::TimeDelta estimate, | 191 base::TimeDelta estimate, |
193 bool affects_estimate) override {} | 192 bool affects_estimate) override {} |
194 }; | 193 }; |
195 | 194 |
196 } // namespace | 195 } // namespace |
197 | 196 |
198 CompositorTimingHistory::CompositorTimingHistory( | 197 CompositorTimingHistory::CompositorTimingHistory( |
199 UMACategory uma_category, | 198 UMACategory uma_category, |
200 RenderingStatsInstrumentation* rendering_stats_instrumentation) | 199 RenderingStatsInstrumentation* rendering_stats_instrumentation) |
201 : enabled_(false), | 200 : enabled_(false), |
202 draws_left_before_estimates_affected_(0), | |
203 begin_main_frame_to_commit_duration_history_(kDurationHistorySize), | 201 begin_main_frame_to_commit_duration_history_(kDurationHistorySize), |
204 commit_to_ready_to_activate_duration_history_(kDurationHistorySize), | 202 commit_to_ready_to_activate_duration_history_(kDurationHistorySize), |
205 prepare_tiles_duration_history_(kDurationHistorySize), | 203 prepare_tiles_duration_history_(kDurationHistorySize), |
206 activate_duration_history_(kDurationHistorySize), | 204 activate_duration_history_(kDurationHistorySize), |
207 draw_duration_history_(kDurationHistorySize), | 205 draw_duration_history_(kDurationHistorySize), |
208 uma_reporter_(CreateUMAReporter(uma_category)), | 206 uma_reporter_(CreateUMAReporter(uma_category)), |
209 rendering_stats_instrumentation_(rendering_stats_instrumentation) {} | 207 rendering_stats_instrumentation_(rendering_stats_instrumentation) {} |
210 | 208 |
211 CompositorTimingHistory::~CompositorTimingHistory() { | 209 CompositorTimingHistory::~CompositorTimingHistory() { |
212 } | 210 } |
(...skipping 26 matching lines...) Expand all Loading... |
239 state->SetDouble("activate_estimate_ms", | 237 state->SetDouble("activate_estimate_ms", |
240 ActivateDurationEstimate().InMillisecondsF()); | 238 ActivateDurationEstimate().InMillisecondsF()); |
241 state->SetDouble("draw_estimate_ms", | 239 state->SetDouble("draw_estimate_ms", |
242 DrawDurationEstimate().InMillisecondsF()); | 240 DrawDurationEstimate().InMillisecondsF()); |
243 } | 241 } |
244 | 242 |
245 base::TimeTicks CompositorTimingHistory::Now() const { | 243 base::TimeTicks CompositorTimingHistory::Now() const { |
246 return base::TimeTicks::Now(); | 244 return base::TimeTicks::Now(); |
247 } | 245 } |
248 | 246 |
249 bool CompositorTimingHistory::AffectsEstimate() const { | |
250 return enabled_ && (draws_left_before_estimates_affected_ == 0); | |
251 } | |
252 | |
253 void CompositorTimingHistory::SetRecordingEnabled(bool enabled) { | 247 void CompositorTimingHistory::SetRecordingEnabled(bool enabled) { |
254 if (enabled == enabled_) | |
255 return; | |
256 | |
257 enabled_ = enabled; | 248 enabled_ = enabled; |
258 | |
259 if (enabled_) | |
260 draws_left_before_estimates_affected_ = kDrawsBeforeEstimatesAffected; | |
261 } | 249 } |
262 | 250 |
263 base::TimeDelta | 251 base::TimeDelta |
264 CompositorTimingHistory::BeginMainFrameToCommitDurationEstimate() const { | 252 CompositorTimingHistory::BeginMainFrameToCommitDurationEstimate() const { |
265 return begin_main_frame_to_commit_duration_history_.Percentile( | 253 return begin_main_frame_to_commit_duration_history_.Percentile( |
266 kBeginMainFrameToCommitEstimationPercentile); | 254 kBeginMainFrameToCommitEstimationPercentile); |
267 } | 255 } |
268 | 256 |
269 base::TimeDelta | 257 base::TimeDelta |
270 CompositorTimingHistory::CommitToReadyToActivateDurationEstimate() const { | 258 CompositorTimingHistory::CommitToReadyToActivateDurationEstimate() const { |
(...skipping 29 matching lines...) Expand all Loading... |
300 commit_time_ = Now(); | 288 commit_time_ = Now(); |
301 | 289 |
302 base::TimeDelta begin_main_frame_to_commit_duration = | 290 base::TimeDelta begin_main_frame_to_commit_duration = |
303 commit_time_ - begin_main_frame_sent_time_; | 291 commit_time_ - begin_main_frame_sent_time_; |
304 | 292 |
305 // Before adding the new data point to the timing history, see what we would | 293 // Before adding the new data point to the timing history, see what we would |
306 // have predicted for this frame. This allows us to keep track of the accuracy | 294 // have predicted for this frame. This allows us to keep track of the accuracy |
307 // of our predictions. | 295 // of our predictions. |
308 base::TimeDelta begin_main_frame_to_commit_estimate = | 296 base::TimeDelta begin_main_frame_to_commit_estimate = |
309 BeginMainFrameToCommitDurationEstimate(); | 297 BeginMainFrameToCommitDurationEstimate(); |
310 | 298 uma_reporter_->AddBeginMainFrameToCommitDuration( |
| 299 begin_main_frame_to_commit_duration, begin_main_frame_to_commit_estimate, |
| 300 enabled_); |
311 rendering_stats_instrumentation_->AddBeginMainFrameToCommitDuration( | 301 rendering_stats_instrumentation_->AddBeginMainFrameToCommitDuration( |
312 begin_main_frame_to_commit_duration, begin_main_frame_to_commit_estimate); | 302 begin_main_frame_to_commit_duration, begin_main_frame_to_commit_estimate); |
313 | 303 |
314 bool affects_estimate = AffectsEstimate(); | 304 if (enabled_) { |
315 uma_reporter_->AddBeginMainFrameToCommitDuration( | |
316 begin_main_frame_to_commit_duration, begin_main_frame_to_commit_estimate, | |
317 affects_estimate); | |
318 if (affects_estimate) { | |
319 begin_main_frame_to_commit_duration_history_.InsertSample( | 305 begin_main_frame_to_commit_duration_history_.InsertSample( |
320 begin_main_frame_to_commit_duration); | 306 begin_main_frame_to_commit_duration); |
321 } | 307 } |
322 | 308 |
323 begin_main_frame_sent_time_ = base::TimeTicks(); | 309 begin_main_frame_sent_time_ = base::TimeTicks(); |
324 } | 310 } |
325 | 311 |
326 void CompositorTimingHistory::WillPrepareTiles() { | 312 void CompositorTimingHistory::WillPrepareTiles() { |
327 DCHECK_EQ(base::TimeTicks(), start_prepare_tiles_time_); | 313 DCHECK_EQ(base::TimeTicks(), start_prepare_tiles_time_); |
328 start_prepare_tiles_time_ = Now(); | 314 start_prepare_tiles_time_ = Now(); |
329 } | 315 } |
330 | 316 |
331 void CompositorTimingHistory::DidPrepareTiles() { | 317 void CompositorTimingHistory::DidPrepareTiles() { |
332 DCHECK_NE(base::TimeTicks(), start_prepare_tiles_time_); | 318 DCHECK_NE(base::TimeTicks(), start_prepare_tiles_time_); |
333 | 319 |
334 base::TimeDelta prepare_tiles_duration = Now() - start_prepare_tiles_time_; | 320 base::TimeDelta prepare_tiles_duration = Now() - start_prepare_tiles_time_; |
335 | |
336 bool affects_estimate = AffectsEstimate(); | |
337 uma_reporter_->AddPrepareTilesDuration( | 321 uma_reporter_->AddPrepareTilesDuration( |
338 prepare_tiles_duration, PrepareTilesDurationEstimate(), affects_estimate); | 322 prepare_tiles_duration, PrepareTilesDurationEstimate(), enabled_); |
339 if (affects_estimate) | 323 if (enabled_) |
340 prepare_tiles_duration_history_.InsertSample(prepare_tiles_duration); | 324 prepare_tiles_duration_history_.InsertSample(prepare_tiles_duration); |
341 | 325 |
342 start_prepare_tiles_time_ = base::TimeTicks(); | 326 start_prepare_tiles_time_ = base::TimeTicks(); |
343 } | 327 } |
344 | 328 |
345 void CompositorTimingHistory::ReadyToActivate() { | 329 void CompositorTimingHistory::ReadyToActivate() { |
346 // We only care about the first ready to activate signal | 330 // We only care about the first ready to activate signal |
347 // after a commit. | 331 // after a commit. |
348 if (commit_time_ == base::TimeTicks()) | 332 if (commit_time_ == base::TimeTicks()) |
349 return; | 333 return; |
350 | 334 |
351 base::TimeDelta time_since_commit = Now() - commit_time_; | 335 base::TimeDelta time_since_commit = Now() - commit_time_; |
352 | 336 |
353 // Before adding the new data point to the timing history, see what we would | 337 // Before adding the new data point to the timing history, see what we would |
354 // have predicted for this frame. This allows us to keep track of the accuracy | 338 // have predicted for this frame. This allows us to keep track of the accuracy |
355 // of our predictions. | 339 // of our predictions. |
356 | 340 |
357 base::TimeDelta commit_to_ready_to_activate_estimate = | 341 base::TimeDelta commit_to_ready_to_activate_estimate = |
358 CommitToReadyToActivateDurationEstimate(); | 342 CommitToReadyToActivateDurationEstimate(); |
| 343 uma_reporter_->AddCommitToReadyToActivateDuration( |
| 344 time_since_commit, commit_to_ready_to_activate_estimate, enabled_); |
359 rendering_stats_instrumentation_->AddCommitToActivateDuration( | 345 rendering_stats_instrumentation_->AddCommitToActivateDuration( |
360 time_since_commit, commit_to_ready_to_activate_estimate); | 346 time_since_commit, commit_to_ready_to_activate_estimate); |
361 | 347 |
362 bool affects_estimate = AffectsEstimate(); | 348 if (enabled_) { |
363 uma_reporter_->AddCommitToReadyToActivateDuration( | |
364 time_since_commit, commit_to_ready_to_activate_estimate, | |
365 affects_estimate); | |
366 if (affects_estimate) { | |
367 commit_to_ready_to_activate_duration_history_.InsertSample( | 349 commit_to_ready_to_activate_duration_history_.InsertSample( |
368 time_since_commit); | 350 time_since_commit); |
369 } | 351 } |
370 | 352 |
371 commit_time_ = base::TimeTicks(); | 353 commit_time_ = base::TimeTicks(); |
372 } | 354 } |
373 | 355 |
374 void CompositorTimingHistory::WillActivate() { | 356 void CompositorTimingHistory::WillActivate() { |
375 DCHECK_EQ(base::TimeTicks(), start_activate_time_); | 357 DCHECK_EQ(base::TimeTicks(), start_activate_time_); |
376 start_activate_time_ = Now(); | 358 start_activate_time_ = Now(); |
377 } | 359 } |
378 | 360 |
379 void CompositorTimingHistory::DidActivate() { | 361 void CompositorTimingHistory::DidActivate() { |
380 DCHECK_NE(base::TimeTicks(), start_activate_time_); | 362 DCHECK_NE(base::TimeTicks(), start_activate_time_); |
381 base::TimeDelta activate_duration = Now() - start_activate_time_; | 363 base::TimeDelta activate_duration = Now() - start_activate_time_; |
382 | 364 |
383 bool affects_estimate = AffectsEstimate(); | 365 uma_reporter_->AddActivateDuration(activate_duration, |
384 uma_reporter_->AddActivateDuration( | 366 ActivateDurationEstimate(), enabled_); |
385 activate_duration, ActivateDurationEstimate(), affects_estimate); | 367 if (enabled_) |
386 if (affects_estimate) | |
387 activate_duration_history_.InsertSample(activate_duration); | 368 activate_duration_history_.InsertSample(activate_duration); |
388 | 369 |
389 start_activate_time_ = base::TimeTicks(); | 370 start_activate_time_ = base::TimeTicks(); |
390 } | 371 } |
391 | 372 |
392 void CompositorTimingHistory::WillDraw() { | 373 void CompositorTimingHistory::WillDraw() { |
393 DCHECK_EQ(base::TimeTicks(), start_draw_time_); | 374 DCHECK_EQ(base::TimeTicks(), start_draw_time_); |
394 start_draw_time_ = Now(); | 375 start_draw_time_ = Now(); |
395 } | 376 } |
396 | 377 |
397 void CompositorTimingHistory::DidDraw() { | 378 void CompositorTimingHistory::DidDraw() { |
398 DCHECK_NE(base::TimeTicks(), start_draw_time_); | 379 DCHECK_NE(base::TimeTicks(), start_draw_time_); |
399 base::TimeDelta draw_duration = Now() - start_draw_time_; | 380 base::TimeDelta draw_duration = Now() - start_draw_time_; |
400 | 381 |
401 // Before adding the new data point to the timing history, see what we would | 382 // Before adding the new data point to the timing history, see what we would |
402 // have predicted for this frame. This allows us to keep track of the accuracy | 383 // have predicted for this frame. This allows us to keep track of the accuracy |
403 // of our predictions. | 384 // of our predictions. |
404 base::TimeDelta draw_estimate = DrawDurationEstimate(); | 385 base::TimeDelta draw_estimate = DrawDurationEstimate(); |
405 rendering_stats_instrumentation_->AddDrawDuration(draw_duration, | 386 rendering_stats_instrumentation_->AddDrawDuration(draw_duration, |
406 draw_estimate); | 387 draw_estimate); |
407 | 388 |
408 bool affects_estimate = AffectsEstimate(); | 389 uma_reporter_->AddDrawDuration(draw_duration, draw_estimate, enabled_); |
409 uma_reporter_->AddDrawDuration(draw_duration, draw_estimate, | 390 |
410 affects_estimate); | 391 if (enabled_) { |
411 if (affects_estimate) | |
412 draw_duration_history_.InsertSample(draw_duration); | 392 draw_duration_history_.InsertSample(draw_duration); |
413 | 393 } |
414 if (draws_left_before_estimates_affected_ > 0) | |
415 draws_left_before_estimates_affected_--; | |
416 | 394 |
417 start_draw_time_ = base::TimeTicks(); | 395 start_draw_time_ = base::TimeTicks(); |
418 } | 396 } |
419 | 397 |
420 } // namespace cc | 398 } // namespace cc |
OLD | NEW |