forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompositor_timing_history.cc
885 lines (774 loc) · 29.7 KB
/
compositor_timing_history.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/metrics/compositor_timing_history.h"
#include <stddef.h>
#include <stdint.h>
#include <algorithm>
#include <utility>
#include <vector>
#include "base/memory/ptr_util.h"
#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_macros.h"
#include "base/notreached.h"
#include "base/trace_event/trace_event.h"
#include "cc/base/features.h"
#include "cc/debug/rendering_stats_instrumentation.h"
namespace cc {
class CompositorTimingHistory::UMAReporter {
public:
virtual ~UMAReporter() = default;
// Throughput measurements
virtual void AddDrawInterval(base::TimeDelta interval) = 0;
// Latency measurements
virtual void AddBeginImplFrameLatency(base::TimeDelta delta) = 0;
virtual void AddCommitToReadyToActivateDuration(base::TimeDelta duration,
TreePriority priority) = 0;
virtual void AddInvalidationToReadyToActivateDuration(
base::TimeDelta duration,
TreePriority priority) = 0;
virtual void AddDrawDuration(base::TimeDelta duration) = 0;
// crbug.com/758439: the following functions are used to report timing in
// certain conditions targeting blink / compositor animations.
// Only the renderer would get the meaningful data.
virtual void AddDrawIntervalWithCustomPropertyAnimations(
base::TimeDelta duration) = 0;
virtual void AddImplFrameDeadlineType(
CompositorTimingHistory::DeadlineMode deadline_mode) = 0;
};
namespace {
// Used to generate a unique id when emitting the "Long Draw Interval" trace
// event.
int g_num_long_draw_intervals = 0;
// The threshold to emit a trace event is the 99th percentile
// of the histogram on Windows Stable as of Feb 26th, 2020.
constexpr base::TimeDelta kDrawIntervalTraceThreshold =
base::Microseconds(34478);
// Using the 90th percentile will disable latency recovery
// if we are missing the deadline approximately ~6 times per
// second.
// TODO(brianderson): Fine tune the percentiles below.
const size_t kDurationHistorySize = 60;
const double kBeginMainFrameQueueDurationEstimationPercentile = 90.0;
const double kBeginMainFrameQueueDurationCriticalEstimationPercentile = 90.0;
const double kBeginMainFrameQueueDurationNotCriticalEstimationPercentile = 90.0;
const double kBeginMainFrameStartToReadyToCommitEstimationPercentile = 90.0;
const double kCommitEstimatePercentile = 90.0;
const double kCommitToReadyToActivateEstimationPercentile = 90.0;
const double kPrepareTilesEstimationPercentile = 90.0;
const double kActivateEstimationPercentile = 90.0;
const double kDrawEstimationPercentile = 90.0;
double BeginMainFrameStartToReadyToCommitCriticalPercentile() {
if (base::FeatureList::IsEnabled(
features::kDurationEstimatesInCompositorTimingHistory)) {
double result = base::GetFieldTrialParamByFeatureAsDouble(
features::kDurationEstimatesInCompositorTimingHistory,
"BMFStartCritialPercentile", -1.0);
if (result > 0)
return result;
}
return 90.0;
}
double BeginMainFrameStartToReadyToCommitNonCriticalPercentile() {
if (base::FeatureList::IsEnabled(
features::kDurationEstimatesInCompositorTimingHistory)) {
double result = base::GetFieldTrialParamByFeatureAsDouble(
features::kDurationEstimatesInCompositorTimingHistory,
"BMFStartNonCritialPercentile", -1.0);
if (result > 0)
return result;
}
return 90.0;
}
double BeginMainFrameQueueToActivateCriticalPercentile() {
if (base::FeatureList::IsEnabled(
features::kDurationEstimatesInCompositorTimingHistory)) {
double result = base::GetFieldTrialParamByFeatureAsDouble(
features::kDurationEstimatesInCompositorTimingHistory,
"BMFQueueCritialPercentile", -1.0);
if (result > 0)
return result;
}
return 90.0;
}
// This macro is deprecated since its bucket count uses too much bandwidth.
// It also has sub-optimal range and bucket distribution.
// TODO(brianderson): Delete this macro and associated UMAs once there is
// sufficient overlap with the re-bucketed UMAs.
#define UMA_HISTOGRAM_CUSTOM_TIMES_MICROS(name, sample) \
UMA_HISTOGRAM_CUSTOM_COUNTS(name, sample.InMicroseconds(), \
kUmaDurationMinMicros, kUmaDurationMaxMicros, \
kUmaDurationBucketCount);
// ~90 VSync aligned UMA buckets.
const int kUMAVSyncBuckets[] = {
// Powers of two from 0 to 2048 us @ 50% precision
1,
2,
4,
8,
16,
32,
64,
128,
256,
512,
1024,
2048,
// Every 8 Hz from 256 Hz to 128 Hz @ 3-6% precision
3906,
4032,
4167,
4310,
4464,
4630,
4808,
5000,
5208,
5435,
5682,
5952,
6250,
6579,
6944,
7353,
// Every 4 Hz from 128 Hz to 64 Hz @ 3-6% precision
7813,
8065,
8333,
8621,
8929,
9259,
9615,
10000,
10417,
10870,
11364,
11905,
12500,
13158,
13889,
14706,
// Every 2 Hz from 64 Hz to 32 Hz @ 3-6% precision
15625,
16129,
16667,
17241,
17857,
18519,
19231,
20000,
20833,
21739,
22727,
23810,
25000,
26316,
27778,
29412,
// Every 1 Hz from 32 Hz to 1 Hz @ 3-33% precision
31250,
32258,
33333,
34483,
35714,
37037,
38462,
40000,
41667,
43478,
45455,
47619,
50000,
52632,
55556,
58824,
62500,
66667,
71429,
76923,
83333,
90909,
100000,
111111,
125000,
142857,
166667,
200000,
250000,
333333,
500000,
// Powers of two from 1s to 32s @ 50% precision
1000000,
2000000,
4000000,
8000000,
16000000,
32000000,
};
// ~50 UMA buckets with high precision from ~100 us to 1s.
const int kUMADurationBuckets[] = {
// Powers of 2 from 1 us to 64 us @ 50% precision.
1,
2,
4,
8,
16,
32,
64,
// 1.25^20, 1.25^21, ..., 1.25^62 @ 20% precision.
87,
108,
136,
169,
212,
265,
331,
414,
517,
646,
808,
1010,
1262,
1578,
1972,
2465,
3081,
3852,
4815,
6019,
7523,
9404,
11755,
14694,
18367,
22959,
28699,
35873,
44842,
56052,
70065,
87581,
109476,
136846,
171057,
213821,
267276,
334096,
417619,
522024,
652530,
815663,
1019579,
// Powers of 2 from 2s to 32s @ 50% precision.
2000000,
4000000,
8000000,
16000000,
32000000,
};
#define UMA_HISTOGRAM_CUSTOM_TIMES_VSYNC_ALIGNED(name, sample) \
do { \
UMA_HISTOGRAM_CUSTOM_ENUMERATION( \
name "2", sample.InMicroseconds(), \
std::vector<int>(kUMAVSyncBuckets, \
kUMAVSyncBuckets + std::size(kUMAVSyncBuckets))); \
} while (false)
#define UMA_HISTOGRAM_CUSTOM_TIMES_DURATION_SUFFIX(name, suffix, sample) \
do { \
UMA_HISTOGRAM_CUSTOM_ENUMERATION( \
name "2" suffix, sample.InMicroseconds(), \
std::vector<int>( \
kUMADurationBuckets, \
kUMADurationBuckets + std::size(kUMADurationBuckets))); \
} while (false)
#define UMA_HISTOGRAM_CUSTOM_TIMES_DURATION(name, sample) \
UMA_HISTOGRAM_CUSTOM_TIMES_DURATION_SUFFIX(name, "", sample)
#define UMA_HISTOGRAM_READY_TO_ACTIVATE(name, sample, priority) \
do { \
UMA_HISTOGRAM_CUSTOM_TIMES_DURATION(name, sample); \
switch (priority) { \
case SAME_PRIORITY_FOR_BOTH_TREES: \
UMA_HISTOGRAM_CUSTOM_TIMES_DURATION_SUFFIX(name, ".Same", sample); \
break; \
case SMOOTHNESS_TAKES_PRIORITY: \
UMA_HISTOGRAM_CUSTOM_TIMES_DURATION_SUFFIX(name, ".Smoothness", \
sample); \
break; \
case NEW_CONTENT_TAKES_PRIORITY: \
UMA_HISTOGRAM_CUSTOM_TIMES_DURATION_SUFFIX(name, ".NewContent", \
sample); \
break; \
} \
} while (false)
class RendererUMAReporter : public CompositorTimingHistory::UMAReporter {
public:
~RendererUMAReporter() override = default;
void AddDrawInterval(base::TimeDelta interval) override {
UMA_HISTOGRAM_CUSTOM_TIMES_VSYNC_ALIGNED("Scheduling.Renderer.DrawInterval",
interval);
}
void AddDrawIntervalWithCustomPropertyAnimations(
base::TimeDelta interval) override {
UMA_HISTOGRAM_CUSTOM_TIMES_VSYNC_ALIGNED(
"Scheduling.Renderer.DrawIntervalWithCustomPropertyAnimations",
interval);
}
void AddBeginImplFrameLatency(base::TimeDelta delta) override {
UMA_HISTOGRAM_CUSTOM_TIMES_DURATION(
"Scheduling.Renderer.BeginImplFrameLatency", delta);
}
void AddCommitToReadyToActivateDuration(base::TimeDelta duration,
TreePriority priority) override {
UMA_HISTOGRAM_READY_TO_ACTIVATE(
"Scheduling.Renderer.CommitToReadyToActivateDuration", duration,
priority);
}
void AddInvalidationToReadyToActivateDuration(
base::TimeDelta duration,
TreePriority priority) override {
UMA_HISTOGRAM_READY_TO_ACTIVATE(
"Scheduling.Renderer.InvalidationToReadyToActivateDuration", duration,
priority);
}
void AddDrawDuration(base::TimeDelta duration) override {
UMA_HISTOGRAM_CUSTOM_TIMES_DURATION("Scheduling.Renderer.DrawDuration",
duration);
}
void AddImplFrameDeadlineType(
CompositorTimingHistory::DeadlineMode deadline_mode) override {
UMA_HISTOGRAM_ENUMERATION("Scheduling.Renderer.DeadlineMode",
deadline_mode);
}
};
class BrowserUMAReporter : public CompositorTimingHistory::UMAReporter {
public:
~BrowserUMAReporter() override = default;
// DrawInterval is not meaningful to measure on browser side because
// browser rendering fps is not at 60.
void AddDrawInterval(base::TimeDelta interval) override {}
void AddDrawIntervalWithCustomPropertyAnimations(
base::TimeDelta interval) override {}
void AddBeginImplFrameLatency(base::TimeDelta delta) override {
UMA_HISTOGRAM_CUSTOM_TIMES_DURATION(
"Scheduling.Browser.BeginImplFrameLatency", delta);
}
void AddCommitToReadyToActivateDuration(base::TimeDelta duration,
TreePriority priority) override {
UMA_HISTOGRAM_READY_TO_ACTIVATE(
"Scheduling.Browser.CommitToReadyToActivateDuration", duration,
priority);
}
void AddInvalidationToReadyToActivateDuration(
base::TimeDelta duration,
TreePriority priority) override {
UMA_HISTOGRAM_READY_TO_ACTIVATE(
"Scheduling.Browser.InvalidationToReadyToActivateDuration", duration,
priority);
}
void AddDrawDuration(base::TimeDelta duration) override {
UMA_HISTOGRAM_CUSTOM_TIMES_DURATION("Scheduling.Browser.DrawDuration",
duration);
}
void AddImplFrameDeadlineType(
CompositorTimingHistory::DeadlineMode deadline_mode) override {
// The browser compositor scheduler is synchronous and only has None (or
// Blocked as edges cases) for deadline mode.
}
};
class NullUMAReporter : public CompositorTimingHistory::UMAReporter {
public:
~NullUMAReporter() override = default;
void AddDrawInterval(base::TimeDelta interval) override {}
void AddDrawIntervalWithCustomPropertyAnimations(
base::TimeDelta inverval) override {}
void AddBeginImplFrameLatency(base::TimeDelta delta) override {}
void AddCommitToReadyToActivateDuration(base::TimeDelta duration,
TreePriority priority) override {}
void AddInvalidationToReadyToActivateDuration(
base::TimeDelta duration,
TreePriority priority) override {}
void AddDrawDuration(base::TimeDelta duration) override {}
void AddImplFrameDeadlineType(
CompositorTimingHistory::DeadlineMode deadline_mode) override {}
};
} // namespace
CompositorTimingHistory::CompositorTimingHistory(
bool using_synchronous_renderer_compositor,
UMACategory uma_category,
RenderingStatsInstrumentation* rendering_stats_instrumentation)
: using_synchronous_renderer_compositor_(
using_synchronous_renderer_compositor),
enabled_(false),
did_send_begin_main_frame_(false),
compositor_drawing_continuously_(false),
begin_main_frame_queue_duration_history_(kDurationHistorySize),
begin_main_frame_queue_duration_critical_history_(kDurationHistorySize),
begin_main_frame_queue_duration_not_critical_history_(
kDurationHistorySize),
begin_main_frame_start_to_ready_to_commit_duration_history_(
kDurationHistorySize),
commit_duration_history_(kDurationHistorySize),
commit_to_ready_to_activate_duration_history_(kDurationHistorySize),
prepare_tiles_duration_history_(kDurationHistorySize),
activate_duration_history_(kDurationHistorySize),
draw_duration_history_(kDurationHistorySize),
duration_estimates_enabled_(base::FeatureList::IsEnabled(
features::kDurationEstimatesInCompositorTimingHistory)),
bmf_start_to_ready_to_commit_critical_history_(kDurationHistorySize),
bmf_start_to_ready_to_commit_critical_percentile_(
BeginMainFrameStartToReadyToCommitCriticalPercentile()),
bmf_start_to_ready_to_commit_not_critical_history_(kDurationHistorySize),
bmf_start_to_ready_to_commit_not_critical_percentile_(
BeginMainFrameStartToReadyToCommitNonCriticalPercentile()),
bmf_queue_to_activate_critical_history_(kDurationHistorySize),
bmf_queue_to_activate_critical_percentile_(
BeginMainFrameQueueToActivateCriticalPercentile()),
begin_main_frame_on_critical_path_(false),
uma_reporter_(CreateUMAReporter(uma_category)),
rendering_stats_instrumentation_(rendering_stats_instrumentation) {}
CompositorTimingHistory::~CompositorTimingHistory() = default;
std::unique_ptr<CompositorTimingHistory::UMAReporter>
CompositorTimingHistory::CreateUMAReporter(UMACategory category) {
switch (category) {
case RENDERER_UMA:
return base::WrapUnique(new RendererUMAReporter);
case BROWSER_UMA:
return base::WrapUnique(new BrowserUMAReporter);
case NULL_UMA:
return base::WrapUnique(new NullUMAReporter);
}
NOTREACHED();
return base::WrapUnique<CompositorTimingHistory::UMAReporter>(nullptr);
}
base::TimeTicks CompositorTimingHistory::Now() const {
return base::TimeTicks::Now();
}
void CompositorTimingHistory::SetRecordingEnabled(bool enabled) {
enabled_ = enabled;
}
void CompositorTimingHistory::SetCompositorDrawingContinuously(bool active) {
if (active == compositor_drawing_continuously_)
return;
draw_end_time_prev_ = base::TimeTicks();
compositor_drawing_continuously_ = active;
}
base::TimeDelta
CompositorTimingHistory::BeginMainFrameQueueDurationCriticalEstimate() const {
base::TimeDelta all = begin_main_frame_queue_duration_history_.Percentile(
kBeginMainFrameQueueDurationEstimationPercentile);
base::TimeDelta critical =
begin_main_frame_queue_duration_critical_history_.Percentile(
kBeginMainFrameQueueDurationCriticalEstimationPercentile);
// Return the min since critical BeginMainFrames are likely fast if
// the non critical ones are.
return std::min(critical, all);
}
base::TimeDelta
CompositorTimingHistory::BeginMainFrameQueueDurationNotCriticalEstimate()
const {
base::TimeDelta all = begin_main_frame_queue_duration_history_.Percentile(
kBeginMainFrameQueueDurationEstimationPercentile);
base::TimeDelta not_critical =
begin_main_frame_queue_duration_not_critical_history_.Percentile(
kBeginMainFrameQueueDurationNotCriticalEstimationPercentile);
// Return the max since, non critical BeginMainFrames are likely slow if
// the critical ones are.
return std::max(not_critical, all);
}
base::TimeDelta
CompositorTimingHistory::BeginMainFrameStartToReadyToCommitDurationEstimate()
const {
return begin_main_frame_start_to_ready_to_commit_duration_history_.Percentile(
kBeginMainFrameStartToReadyToCommitEstimationPercentile);
}
base::TimeDelta CompositorTimingHistory::CommitDurationEstimate() const {
return commit_duration_history_.Percentile(kCommitEstimatePercentile);
}
base::TimeDelta
CompositorTimingHistory::CommitToReadyToActivateDurationEstimate() const {
return commit_to_ready_to_activate_duration_history_.Percentile(
kCommitToReadyToActivateEstimationPercentile);
}
base::TimeDelta CompositorTimingHistory::PrepareTilesDurationEstimate() const {
return prepare_tiles_duration_history_.Percentile(
kPrepareTilesEstimationPercentile);
}
base::TimeDelta CompositorTimingHistory::ActivateDurationEstimate() const {
return activate_duration_history_.Percentile(kActivateEstimationPercentile);
}
base::TimeDelta CompositorTimingHistory::DrawDurationEstimate() const {
return draw_duration_history_.Percentile(kDrawEstimationPercentile);
}
base::TimeDelta
CompositorTimingHistory::BeginMainFrameStartToReadyToCommitCriticalEstimate()
const {
if (duration_estimates_enabled_) {
return bmf_start_to_ready_to_commit_critical_history_.Percentile(
bmf_start_to_ready_to_commit_critical_percentile_);
}
return BeginMainFrameStartToReadyToCommitDurationEstimate() +
BeginMainFrameQueueDurationCriticalEstimate();
}
base::TimeDelta
CompositorTimingHistory::BeginMainFrameStartToReadyToCommitNotCriticalEstimate()
const {
if (duration_estimates_enabled_) {
return bmf_start_to_ready_to_commit_not_critical_history_.Percentile(
bmf_start_to_ready_to_commit_not_critical_percentile_);
}
return BeginMainFrameStartToReadyToCommitDurationEstimate() +
BeginMainFrameQueueDurationNotCriticalEstimate();
}
base::TimeDelta
CompositorTimingHistory::BeginMainFrameQueueToActivateCriticalEstimate() const {
if (duration_estimates_enabled_) {
return bmf_queue_to_activate_critical_history_.Percentile(
bmf_queue_to_activate_critical_percentile_);
}
return BeginMainFrameStartToReadyToCommitDurationEstimate() +
CommitDurationEstimate() + CommitToReadyToActivateDurationEstimate() +
ActivateDurationEstimate() +
BeginMainFrameQueueDurationCriticalEstimate();
}
void CompositorTimingHistory::WillBeginImplFrame(
const viz::BeginFrameArgs& args,
base::TimeTicks now) {
viz::BeginFrameArgs::BeginFrameArgsType frame_type = args.type;
base::TimeTicks frame_time = args.frame_time;
if (frame_type == viz::BeginFrameArgs::NORMAL)
uma_reporter_->AddBeginImplFrameLatency(now - frame_time);
did_send_begin_main_frame_ = false;
}
void CompositorTimingHistory::WillFinishImplFrame(bool needs_redraw) {
if (!needs_redraw)
SetCompositorDrawingContinuously(false);
}
void CompositorTimingHistory::BeginImplFrameNotExpectedSoon() {
SetCompositorDrawingContinuously(false);
}
void CompositorTimingHistory::WillBeginMainFrame(
const viz::BeginFrameArgs& args) {
DCHECK_EQ(base::TimeTicks(), begin_main_frame_sent_time_);
begin_main_frame_on_critical_path_ = args.on_critical_path;
begin_main_frame_sent_time_ = Now();
did_send_begin_main_frame_ = true;
}
void CompositorTimingHistory::BeginMainFrameStarted(
base::TimeTicks main_thread_start_time) {
DCHECK_NE(base::TimeTicks(), begin_main_frame_sent_time_);
DCHECK_EQ(base::TimeTicks(), begin_main_frame_start_time_);
begin_main_frame_start_time_ = main_thread_start_time;
}
void CompositorTimingHistory::BeginMainFrameAborted() {
base::TimeTicks begin_main_frame_end_time = Now();
DidBeginMainFrame(begin_main_frame_end_time);
}
void CompositorTimingHistory::NotifyReadyToCommit() {
DCHECK_NE(begin_main_frame_start_time_, base::TimeTicks());
begin_main_frame_start_to_ready_to_commit_duration_history_.InsertSample(
Now() - begin_main_frame_start_time_);
if (duration_estimates_enabled_) {
bmf_start_to_activate_duration_ = Now() - begin_main_frame_start_time_;
if (begin_main_frame_on_critical_path_) {
bmf_start_to_ready_to_commit_critical_history_.InsertSample(
(Now() - begin_main_frame_start_time_) +
begin_main_frame_queue_duration_);
} else {
bmf_start_to_ready_to_commit_not_critical_history_.InsertSample(
(Now() - begin_main_frame_start_time_) +
begin_main_frame_queue_duration_);
}
}
}
void CompositorTimingHistory::WillCommit() {
DCHECK_NE(begin_main_frame_start_time_, base::TimeTicks());
commit_start_time_ = Now();
}
void CompositorTimingHistory::DidCommit() {
DCHECK_EQ(pending_tree_creation_time_, base::TimeTicks());
DCHECK_NE(commit_start_time_, base::TimeTicks());
base::TimeTicks begin_main_frame_end_time = Now();
DidBeginMainFrame(begin_main_frame_end_time);
commit_duration_history_.InsertSample(begin_main_frame_end_time -
commit_start_time_);
if (enabled_ && duration_estimates_enabled_) {
bmf_start_to_activate_duration_ +=
begin_main_frame_end_time - commit_start_time_;
}
pending_tree_is_impl_side_ = false;
pending_tree_creation_time_ = begin_main_frame_end_time;
}
void CompositorTimingHistory::DidBeginMainFrame(
base::TimeTicks begin_main_frame_end_time) {
DCHECK_NE(base::TimeTicks(), begin_main_frame_sent_time_);
// If the BeginMainFrame start time isn't know, assume it was immediate
// for scheduling purposes, but don't report it for UMA to avoid skewing
// the results.
bool begin_main_frame_start_time_is_valid =
!begin_main_frame_start_time_.is_null();
if (!begin_main_frame_start_time_is_valid)
begin_main_frame_start_time_ = begin_main_frame_sent_time_;
base::TimeDelta begin_main_frame_sent_to_commit_duration =
begin_main_frame_end_time - begin_main_frame_sent_time_;
base::TimeDelta begin_main_frame_queue_duration =
begin_main_frame_start_time_ - begin_main_frame_sent_time_;
rendering_stats_instrumentation_->AddBeginMainFrameToCommitDuration(
begin_main_frame_sent_to_commit_duration);
if (enabled_) {
begin_main_frame_queue_duration_history_.InsertSample(
begin_main_frame_queue_duration);
if (begin_main_frame_on_critical_path_) {
begin_main_frame_queue_duration_critical_history_.InsertSample(
begin_main_frame_queue_duration);
} else {
begin_main_frame_queue_duration_not_critical_history_.InsertSample(
begin_main_frame_queue_duration);
}
if (duration_estimates_enabled_) {
begin_main_frame_queue_duration_ = begin_main_frame_queue_duration;
}
}
begin_main_frame_sent_time_ = base::TimeTicks();
begin_main_frame_start_time_ = base::TimeTicks();
}
void CompositorTimingHistory::WillInvalidateOnImplSide() {
DCHECK(!pending_tree_is_impl_side_);
DCHECK_EQ(pending_tree_creation_time_, base::TimeTicks());
pending_tree_is_impl_side_ = true;
pending_tree_creation_time_ = base::TimeTicks::Now();
}
void CompositorTimingHistory::WillPrepareTiles() {
DCHECK_EQ(base::TimeTicks(), prepare_tiles_start_time_);
prepare_tiles_start_time_ = Now();
}
void CompositorTimingHistory::DidPrepareTiles() {
DCHECK_NE(base::TimeTicks(), prepare_tiles_start_time_);
base::TimeDelta prepare_tiles_duration = Now() - prepare_tiles_start_time_;
if (enabled_)
prepare_tiles_duration_history_.InsertSample(prepare_tiles_duration);
prepare_tiles_start_time_ = base::TimeTicks();
}
void CompositorTimingHistory::ReadyToActivate() {
DCHECK_NE(pending_tree_creation_time_, base::TimeTicks());
DCHECK_EQ(pending_tree_ready_to_activate_time_, base::TimeTicks());
pending_tree_ready_to_activate_time_ = Now();
if (pending_tree_is_impl_side_) {
base::TimeDelta time_since_invalidation =
pending_tree_ready_to_activate_time_ - pending_tree_creation_time_;
uma_reporter_->AddInvalidationToReadyToActivateDuration(
time_since_invalidation, tree_priority_);
} else {
base::TimeDelta time_since_commit =
pending_tree_ready_to_activate_time_ - pending_tree_creation_time_;
// Before adding the new data point to the timing history, see what we would
// have predicted for this frame. This allows us to keep track of the
// accuracy of our predictions.
base::TimeDelta commit_to_ready_to_activate_estimate =
CommitToReadyToActivateDurationEstimate();
uma_reporter_->AddCommitToReadyToActivateDuration(time_since_commit,
tree_priority_);
rendering_stats_instrumentation_->AddCommitToActivateDuration(
time_since_commit, commit_to_ready_to_activate_estimate);
if (enabled_) {
commit_to_ready_to_activate_duration_history_.InsertSample(
time_since_commit);
if (duration_estimates_enabled_)
bmf_start_to_activate_duration_ += time_since_commit;
}
}
}
void CompositorTimingHistory::WillActivate() {
DCHECK_EQ(base::TimeTicks(), activate_start_time_);
activate_start_time_ = Now();
pending_tree_is_impl_side_ = false;
pending_tree_creation_time_ = base::TimeTicks();
pending_tree_ready_to_activate_time_ = base::TimeTicks();
}
void CompositorTimingHistory::DidActivate() {
DCHECK_NE(base::TimeTicks(), activate_start_time_);
base::TimeDelta activate_duration = Now() - activate_start_time_;
if (enabled_) {
activate_duration_history_.InsertSample(activate_duration);
if (duration_estimates_enabled_) {
if (begin_main_frame_on_critical_path_) {
bmf_queue_to_activate_critical_history_.InsertSample(
bmf_start_to_activate_duration_ + activate_duration +
begin_main_frame_queue_duration_);
}
}
}
activate_start_time_ = base::TimeTicks();
}
void CompositorTimingHistory::WillDraw() {
DCHECK_EQ(base::TimeTicks(), draw_start_time_);
draw_start_time_ = Now();
}
void CompositorTimingHistory::DidDraw(bool used_new_active_tree,
bool has_custom_property_animations) {
DCHECK_NE(base::TimeTicks(), draw_start_time_);
base::TimeTicks draw_end_time = Now();
base::TimeDelta draw_duration = draw_end_time - draw_start_time_;
// Before adding the new data point to the timing history, see what we would
// have predicted for this frame. This allows us to keep track of the accuracy
// of our predictions.
base::TimeDelta draw_estimate = DrawDurationEstimate();
rendering_stats_instrumentation_->AddDrawDuration(draw_duration,
draw_estimate);
uma_reporter_->AddDrawDuration(draw_duration);
if (enabled_) {
draw_duration_history_.InsertSample(draw_duration);
}
SetCompositorDrawingContinuously(true);
if (!draw_end_time_prev_.is_null()) {
base::TimeDelta draw_interval = draw_end_time - draw_end_time_prev_;
uma_reporter_->AddDrawInterval(draw_interval);
// Emit a trace event to highlight a long time lapse between the draw times
// of back-to-back BeginImplFrames.
if (draw_interval > kDrawIntervalTraceThreshold) {
TRACE_EVENT_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP0(
"latency", "Long Draw Interval",
TRACE_ID_WITH_SCOPE("Long Draw Interval", g_num_long_draw_intervals),
draw_start_time_);
TRACE_EVENT_NESTABLE_ASYNC_END_WITH_TIMESTAMP0(
"latency", "Long Draw Interval",
TRACE_ID_WITH_SCOPE("Long Draw Interval", g_num_long_draw_intervals),
draw_end_time);
g_num_long_draw_intervals++;
}
if (has_custom_property_animations &&
previous_frame_had_custom_property_animations_)
uma_reporter_->AddDrawIntervalWithCustomPropertyAnimations(draw_interval);
}
previous_frame_had_custom_property_animations_ =
has_custom_property_animations;
draw_end_time_prev_ = draw_end_time;
if (used_new_active_tree)
new_active_tree_draw_end_time_prev_ = draw_end_time;
draw_start_time_ = base::TimeTicks();
}
void CompositorTimingHistory::SetTreePriority(TreePriority priority) {
tree_priority_ = priority;
}
void CompositorTimingHistory::RecordDeadlineMode(DeadlineMode deadline_mode) {
if (uma_reporter_)
uma_reporter_->AddImplFrameDeadlineType(deadline_mode);
}
void CompositorTimingHistory::ClearHistory() {
TRACE_EVENT0("cc,benchmark", "CompositorTimingHistory::ClearHistory");
begin_main_frame_queue_duration_history_.Clear();
begin_main_frame_queue_duration_critical_history_.Clear();
begin_main_frame_queue_duration_not_critical_history_.Clear();
begin_main_frame_start_to_ready_to_commit_duration_history_.Clear();
commit_duration_history_.Clear();
commit_to_ready_to_activate_duration_history_.Clear();
prepare_tiles_duration_history_.Clear();
activate_duration_history_.Clear();
draw_duration_history_.Clear();
bmf_start_to_ready_to_commit_critical_history_.Clear();
bmf_start_to_ready_to_commit_not_critical_history_.Clear();
bmf_queue_to_activate_critical_history_.Clear();
}
size_t CompositorTimingHistory::CommitDurationSampleCountForTesting() const {
return commit_duration_history_.sample_count();
}
} // namespace cc