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
|
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/metrics/compositor_frame_reporter.h"
#include <algorithm>
#include <array>
#include <memory>
#include <utility>
#include <vector>
#include "base/rand_util.h"
#include "base/strings/strcat.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/simple_test_tick_clock.h"
#include "base/time/time.h"
#include "cc/metrics/compositor_frame_reporting_controller.h"
#include "cc/metrics/event_metrics.h"
#include "components/viz/common/frame_timing_details.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/types/scroll_input_type.h"
namespace cc {
namespace {
using ::testing::Each;
using ::testing::IsEmpty;
using ::testing::NotNull;
class CompositorFrameReporterTest : public testing::Test {
public:
CompositorFrameReporterTest() : pipeline_reporter_(CreatePipelineReporter()) {
AdvanceNowByUs(1);
}
protected:
base::TimeTicks AdvanceNowByUs(int advance_ms) {
test_tick_clock_.Advance(base::Microseconds(advance_ms));
return test_tick_clock_.NowTicks();
}
base::TimeTicks Now() { return test_tick_clock_.NowTicks(); }
std::unique_ptr<BeginMainFrameMetrics> BuildBlinkBreakdown() {
auto breakdown = std::make_unique<BeginMainFrameMetrics>();
breakdown->handle_input_events = base::Microseconds(10);
breakdown->animate = base::Microseconds(9);
breakdown->style_update = base::Microseconds(8);
breakdown->layout_update = base::Microseconds(7);
breakdown->compositing_inputs = base::Microseconds(6);
breakdown->prepaint = base::Microseconds(5);
breakdown->paint = base::Microseconds(3);
breakdown->composite_commit = base::Microseconds(2);
breakdown->update_layers = base::Microseconds(1);
// Advance now by the sum of the breakdowns.
AdvanceNowByUs(10 + 9 + 8 + 7 + 6 + 5 + 3 + 2 + 1);
return breakdown;
}
viz::FrameTimingDetails BuildVizBreakdown() {
viz::FrameTimingDetails viz_breakdown;
viz_breakdown.received_compositor_frame_timestamp = AdvanceNowByUs(1);
viz_breakdown.draw_start_timestamp = AdvanceNowByUs(2);
viz_breakdown.swap_timings.swap_start = AdvanceNowByUs(3);
viz_breakdown.swap_timings.swap_end = AdvanceNowByUs(4);
viz_breakdown.presentation_feedback.timestamp = AdvanceNowByUs(5);
return viz_breakdown;
}
std::unique_ptr<EventMetrics> SetupEventMetrics(
std::unique_ptr<EventMetrics> metrics) {
if (metrics) {
AdvanceNowByUs(3);
metrics->SetDispatchStageTimestamp(
EventMetrics::DispatchStage::kRendererCompositorStarted);
AdvanceNowByUs(3);
metrics->SetDispatchStageTimestamp(
EventMetrics::DispatchStage::kRendererCompositorFinished);
}
return metrics;
}
// Sets up the dispatch durations of each EventMetrics according to
// stage_durations. Stages with a duration of -1 will be skipped.
std::unique_ptr<EventMetrics> SetupEventMetricsWithDispatchTimes(
std::unique_ptr<EventMetrics> metrics,
const std::vector<int>& stage_durations) {
if (metrics) {
int num_stages = stage_durations.size();
int max_num_stages =
static_cast<int>(EventMetrics::DispatchStage::kMaxValue) + 1;
CHECK(num_stages <= max_num_stages)
<< num_stages << " > " << max_num_stages;
// Start indexing from 2 because the 0th index held duration from
// kGenerated to kArrivedInRendererCompositor, which was already used in
// when the EventMetrics was created.
for (int i = 2; i < num_stages; i++) {
if (stage_durations[i] >= 0) {
AdvanceNowByUs(stage_durations[i]);
metrics->SetDispatchStageTimestamp(
EventMetrics::DispatchStage(i + 2));
}
}
}
return metrics;
}
std::unique_ptr<EventMetrics> CreateEventMetrics(ui::EventType type) {
const base::TimeTicks event_time = AdvanceNowByUs(3);
const base::TimeTicks arrived_in_browser_main_timestamp = AdvanceNowByUs(2);
AdvanceNowByUs(3);
return SetupEventMetrics(EventMetrics::CreateForTesting(
type, event_time, arrived_in_browser_main_timestamp, &test_tick_clock_,
std::nullopt));
}
// Creates EventMetrics with elements in stage_durations representing each
// dispatch stage's desired duration respectively, with the 0th index
// representing the duration from kGenerated to kArrivedInRendererCompositor.
// stage_durations must have at least 1 element for the first required stage
// Use -1 for stages that want to be skipped.
std::unique_ptr<EventMetrics> CreateScrollUpdateEventMetricsWithDispatchTimes(
bool is_inertial,
ScrollUpdateEventMetrics::ScrollUpdateType scroll_update_type,
const std::vector<int>& stage_durations) {
CHECK_GE(stage_durations.size(), 2u);
const base::TimeTicks event_time = AdvanceNowByUs(3);
// kGenerated -> kArrivedInBrowserMain
int begin_rwh_latency_ms = stage_durations[0];
const base::TimeTicks arrived_in_browser_main_timestamp =
AdvanceNowByUs(begin_rwh_latency_ms);
// kArrivedInBrowserMain -> kArrivedInRendererCompositor
AdvanceNowByUs(stage_durations[1]);
// Creates a kGestureScrollUpdate event.
return SetupEventMetricsWithDispatchTimes(
ScrollUpdateEventMetrics::CreateForTesting(
ui::EventType::kGestureScrollUpdate, ui::ScrollInputType::kWheel,
is_inertial, scroll_update_type, /*delta=*/10.0f, event_time,
arrived_in_browser_main_timestamp, &test_tick_clock_, std::nullopt),
stage_durations);
}
std::unique_ptr<EventMetrics> CreateScrollBeginMetrics(
ui::ScrollInputType input_type) {
const base::TimeTicks event_time = AdvanceNowByUs(3);
const base::TimeTicks arrived_in_browser_main_timestamp = AdvanceNowByUs(2);
AdvanceNowByUs(3);
return SetupEventMetrics(ScrollEventMetrics::CreateForTesting(
ui::EventType::kGestureScrollBegin, input_type,
/*is_inertial=*/false, event_time, arrived_in_browser_main_timestamp,
&test_tick_clock_));
}
std::unique_ptr<EventMetrics> CreateScrollUpdateEventMetrics(
ui::ScrollInputType input_type,
bool is_inertial,
ScrollUpdateEventMetrics::ScrollUpdateType scroll_update_type) {
const base::TimeTicks event_time = AdvanceNowByUs(3);
const base::TimeTicks arrived_in_browser_main_timestamp = AdvanceNowByUs(2);
AdvanceNowByUs(3);
return SetupEventMetrics(ScrollUpdateEventMetrics::CreateForTesting(
ui::EventType::kGestureScrollUpdate, input_type, is_inertial,
scroll_update_type, /*delta=*/10.0f, event_time,
arrived_in_browser_main_timestamp, &test_tick_clock_, std::nullopt));
}
std::unique_ptr<EventMetrics> CreatePinchEventMetrics(
ui::EventType type,
ui::ScrollInputType input_type) {
const base::TimeTicks event_time = AdvanceNowByUs(3);
AdvanceNowByUs(3);
return SetupEventMetrics(PinchEventMetrics::CreateForTesting(
type, input_type, event_time, &test_tick_clock_));
}
std::vector<base::TimeTicks> GetEventTimestamps(
const EventMetrics::List& events_metrics) {
std::vector<base::TimeTicks> event_times;
event_times.reserve(events_metrics.size());
std::ranges::transform(events_metrics, std::back_inserter(event_times),
[](const auto& event_metrics) {
return event_metrics->GetDispatchStageTimestamp(
EventMetrics::DispatchStage::kGenerated);
});
return event_times;
}
std::unique_ptr<CompositorFrameReporter> CreatePipelineReporter() {
GlobalMetricsTrackers trackers{nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
&frame_sorter_};
auto reporter = std::make_unique<CompositorFrameReporter>(
ActiveTrackers(), viz::BeginFrameArgs(),
/*should_report_metrics=*/true,
CompositorFrameReporter::SmoothThread::kSmoothBoth,
FrameInfo::SmoothEffectDrivingThread::kUnknown,
/*layer_tree_host_id=*/1, trackers);
reporter->set_tick_clock(&test_tick_clock_);
return reporter;
}
void IntToTimeDeltaVector(std::vector<base::TimeDelta>& timedelta_vector,
std::vector<int> int_vector) {
size_t vector_size = int_vector.size();
for (size_t i = 0; i < vector_size; i++) {
timedelta_vector[i] = base::Microseconds(int_vector[i]);
}
}
// Disable sub-sampling to deterministically record histograms under test.
base::MetricsSubSampler::ScopedAlwaysSampleForTesting no_subsampling_;
// This should be defined before |pipeline_reporter_| so it is created before
// and destroyed after that.
base::SimpleTestTickClock test_tick_clock_;
FrameSorter frame_sorter_;
std::unique_ptr<CompositorFrameReporter> pipeline_reporter_;
// Number of breakdown stages of the current PipelineReporter
const int kNumOfCompositorStages =
static_cast<int>(CompositorFrameReporter::StageType::kStageTypeCount) - 1;
const int kNumDispatchStages =
static_cast<int>(EventMetrics::DispatchStage::kMaxValue);
const base::TimeDelta kLatencyPredictionDeviationThreshold =
base::Milliseconds(8.33);
};
TEST_F(CompositorFrameReporterTest, MainFrameAbortedReportingTest) {
base::HistogramTester histogram_tester;
pipeline_reporter_->StartStage(
CompositorFrameReporter::StageType::kBeginImplFrameToSendBeginMainFrame,
Now());
EXPECT_EQ(0u, pipeline_reporter_->stage_history_size_for_testing());
AdvanceNowByUs(3);
pipeline_reporter_->StartStage(
CompositorFrameReporter::StageType::kSendBeginMainFrameToCommit, Now());
EXPECT_EQ(1u, pipeline_reporter_->stage_history_size_for_testing());
AdvanceNowByUs(3);
pipeline_reporter_->StartStage(
CompositorFrameReporter::StageType::kEndActivateToSubmitCompositorFrame,
Now());
EXPECT_EQ(2u, pipeline_reporter_->stage_history_size_for_testing());
AdvanceNowByUs(3);
pipeline_reporter_->StartStage(
CompositorFrameReporter::StageType::
kSubmitCompositorFrameToPresentationCompositorFrame,
Now());
EXPECT_EQ(3u, pipeline_reporter_->stage_history_size_for_testing());
AdvanceNowByUs(3);
pipeline_reporter_->TerminateFrame(
CompositorFrameReporter::FrameTerminationStatus::kPresentedFrame, Now());
EXPECT_EQ(4u, pipeline_reporter_->stage_history_size_for_testing());
pipeline_reporter_ = nullptr;
histogram_tester.ExpectTotalCount(
"CompositorLatency2.BeginImplFrameToSendBeginMainFrame", 1);
histogram_tester.ExpectTotalCount(
"CompositorLatency2.SendBeginMainFrameToCommit", 1);
histogram_tester.ExpectTotalCount("CompositorLatency2.Commit", 0);
histogram_tester.ExpectTotalCount("CompositorLatency2.EndCommitToActivation",
0);
histogram_tester.ExpectTotalCount(
"CompositorLatency2.EndActivateToSubmitCompositorFrame", 1);
histogram_tester.ExpectTotalCount(
"CompositorLatency2.SubmitCompositorFrameToPresentationCompositorFrame",
1);
}
TEST_F(CompositorFrameReporterTest, ReplacedByNewReporterReportingTest) {
base::HistogramTester histogram_tester;
pipeline_reporter_->StartStage(CompositorFrameReporter::StageType::kCommit,
Now());
EXPECT_EQ(0u, pipeline_reporter_->stage_history_size_for_testing());
AdvanceNowByUs(3);
pipeline_reporter_->StartStage(
CompositorFrameReporter::StageType::kEndCommitToActivation, Now());
EXPECT_EQ(1u, pipeline_reporter_->stage_history_size_for_testing());
AdvanceNowByUs(2);
pipeline_reporter_->TerminateFrame(
CompositorFrameReporter::FrameTerminationStatus::kReplacedByNewReporter,
Now());
EXPECT_EQ(2u, pipeline_reporter_->stage_history_size_for_testing());
pipeline_reporter_ = nullptr;
histogram_tester.ExpectTotalCount("CompositorLatency2.Commit", 0);
histogram_tester.ExpectTotalCount("CompositorLatency2.EndCommitToActivation",
0);
}
TEST_F(CompositorFrameReporterTest, SubmittedFrameReportingTest) {
base::HistogramTester histogram_tester;
pipeline_reporter_->StartStage(
CompositorFrameReporter::StageType::kActivation, Now());
EXPECT_EQ(0u, pipeline_reporter_->stage_history_size_for_testing());
AdvanceNowByUs(3);
pipeline_reporter_->StartStage(
CompositorFrameReporter::StageType::kEndActivateToSubmitCompositorFrame,
Now());
EXPECT_EQ(1u, pipeline_reporter_->stage_history_size_for_testing());
AdvanceNowByUs(2);
pipeline_reporter_->TerminateFrame(
CompositorFrameReporter::FrameTerminationStatus::kPresentedFrame, Now());
EXPECT_EQ(2u, pipeline_reporter_->stage_history_size_for_testing());
pipeline_reporter_ = nullptr;
histogram_tester.ExpectTotalCount("CompositorLatency2.Activation", 1);
histogram_tester.ExpectTotalCount(
"CompositorLatency2.EndActivateToSubmitCompositorFrame", 1);
histogram_tester.ExpectTotalCount("CompositorLatency2.TotalLatency", 1);
histogram_tester.ExpectTotalCount(
"CompositorLatency2.DroppedFrame.Activation", 0);
histogram_tester.ExpectTotalCount(
"CompositorLatency2.DroppedFrame.EndActivateToSubmitCompositorFrame", 0);
histogram_tester.ExpectTotalCount(
"CompositorLatency2.DroppedFrame.TotalLatency", 0);
histogram_tester.ExpectBucketCount("CompositorLatency2.Activation", 3, 1);
histogram_tester.ExpectBucketCount(
"CompositorLatency2.EndActivateToSubmitCompositorFrame", 2, 1);
histogram_tester.ExpectBucketCount("CompositorLatency2.TotalLatency", 5, 1);
}
// Tests that when a frame is presented to the user, total event latency metrics
// are reported properly.
TEST_F(CompositorFrameReporterTest,
EventLatencyTotalForPresentedFrameReported) {
base::HistogramTester histogram_tester;
std::unique_ptr<EventMetrics> event_metrics_ptrs[] = {
CreateEventMetrics(ui::EventType::kTouchPressed),
CreateEventMetrics(ui::EventType::kTouchMoved),
CreateEventMetrics(ui::EventType::kTouchMoved),
};
EXPECT_THAT(event_metrics_ptrs, Each(NotNull()));
EventMetrics::List events_metrics(
std::make_move_iterator(std::begin(event_metrics_ptrs)),
std::make_move_iterator(std::end(event_metrics_ptrs)));
std::vector<base::TimeTicks> event_times = GetEventTimestamps(events_metrics);
AdvanceNowByUs(3);
pipeline_reporter_->StartStage(
CompositorFrameReporter::StageType::kBeginImplFrameToSendBeginMainFrame,
Now());
AdvanceNowByUs(3);
pipeline_reporter_->StartStage(
CompositorFrameReporter::StageType::kEndActivateToSubmitCompositorFrame,
Now());
AdvanceNowByUs(3);
pipeline_reporter_->StartStage(
CompositorFrameReporter::StageType::
kSubmitCompositorFrameToPresentationCompositorFrame,
Now());
pipeline_reporter_->AddEventsMetrics(std::move(events_metrics));
const base::TimeTicks presentation_time = AdvanceNowByUs(3);
pipeline_reporter_->TerminateFrame(
CompositorFrameReporter::FrameTerminationStatus::kPresentedFrame,
presentation_time);
pipeline_reporter_ = nullptr;
struct {
const char* name;
const base::HistogramBase::Count32 count;
} expected_counts[] = {
{"EventLatency.TouchPressed.TotalLatency", 1},
{"EventLatency.TouchMoved.TotalLatency", 2},
{"EventLatency.TotalLatency", 3},
};
for (const auto& expected_count : expected_counts) {
histogram_tester.ExpectTotalCount(expected_count.name,
expected_count.count);
}
struct {
const char* name;
const base::HistogramBase::Sample32 latency_ms;
} expected_latencies[] = {
{"EventLatency.TouchPressed.TotalLatency",
static_cast<base::HistogramBase::Sample32>(
(presentation_time - event_times[0]).InMicroseconds())},
{"EventLatency.TouchMoved.TotalLatency",
static_cast<base::HistogramBase::Sample32>(
(presentation_time - event_times[1]).InMicroseconds())},
{"EventLatency.TouchMoved.TotalLatency",
static_cast<base::HistogramBase::Sample32>(
(presentation_time - event_times[2]).InMicroseconds())},
{"EventLatency.TotalLatency",
static_cast<base::HistogramBase::Sample32>(
(presentation_time - event_times[0]).InMicroseconds())},
{"EventLatency.TotalLatency",
static_cast<base::HistogramBase::Sample32>(
(presentation_time - event_times[1]).InMicroseconds())},
{"EventLatency.TotalLatency",
static_cast<base::HistogramBase::Sample32>(
(presentation_time - event_times[2]).InMicroseconds())},
};
for (const auto& expected_latency : expected_latencies) {
histogram_tester.ExpectBucketCount(expected_latency.name,
expected_latency.latency_ms, 1);
}
}
// Tests that when a frame is presented to the user, total scroll event latency
// metrics are reported properly.
TEST_F(CompositorFrameReporterTest,
EventLatencyScrollTotalForPresentedFrameReported) {
base::HistogramTester histogram_tester;
const bool kScrollIsInertial = true;
const bool kScrollIsNotInertial = false;
std::unique_ptr<EventMetrics> event_metrics_ptrs[] = {
CreateScrollBeginMetrics(ui::ScrollInputType::kWheel),
CreateScrollUpdateEventMetrics(
ui::ScrollInputType::kWheel, kScrollIsNotInertial,
ScrollUpdateEventMetrics::ScrollUpdateType::kStarted),
CreateScrollUpdateEventMetrics(
ui::ScrollInputType::kWheel, kScrollIsNotInertial,
ScrollUpdateEventMetrics::ScrollUpdateType::kContinued),
CreateScrollUpdateEventMetrics(
ui::ScrollInputType::kWheel, kScrollIsInertial,
ScrollUpdateEventMetrics::ScrollUpdateType::kContinued),
CreateScrollBeginMetrics(ui::ScrollInputType::kTouchscreen),
CreateScrollUpdateEventMetrics(
ui::ScrollInputType::kTouchscreen, kScrollIsNotInertial,
ScrollUpdateEventMetrics::ScrollUpdateType::kStarted),
CreateScrollUpdateEventMetrics(
ui::ScrollInputType::kTouchscreen, kScrollIsNotInertial,
ScrollUpdateEventMetrics::ScrollUpdateType::kContinued),
CreateScrollUpdateEventMetrics(
ui::ScrollInputType::kTouchscreen, kScrollIsInertial,
ScrollUpdateEventMetrics::ScrollUpdateType::kContinued),
};
EXPECT_THAT(event_metrics_ptrs, Each(NotNull()));
EventMetrics::List events_metrics(
std::make_move_iterator(std::begin(event_metrics_ptrs)),
std::make_move_iterator(std::end(event_metrics_ptrs)));
std::vector<base::TimeTicks> event_times = GetEventTimestamps(events_metrics);
AdvanceNowByUs(3);
pipeline_reporter_->StartStage(
CompositorFrameReporter::StageType::kBeginImplFrameToSendBeginMainFrame,
Now());
AdvanceNowByUs(3);
pipeline_reporter_->StartStage(
CompositorFrameReporter::StageType::kEndActivateToSubmitCompositorFrame,
Now());
AdvanceNowByUs(3);
pipeline_reporter_->StartStage(
CompositorFrameReporter::StageType::
kSubmitCompositorFrameToPresentationCompositorFrame,
Now());
pipeline_reporter_->AddEventsMetrics(std::move(events_metrics));
AdvanceNowByUs(3);
viz::FrameTimingDetails viz_breakdown = BuildVizBreakdown();
pipeline_reporter_->SetVizBreakdown(viz_breakdown);
pipeline_reporter_->TerminateFrame(
CompositorFrameReporter::FrameTerminationStatus::kPresentedFrame,
viz_breakdown.presentation_feedback.timestamp);
pipeline_reporter_ = nullptr;
struct {
const char* name;
const base::HistogramBase::Count32 count;
} expected_counts[] = {
{"EventLatency.GestureScrollBegin.Wheel.TotalLatency2", 1},
{"EventLatency.FirstGestureScrollUpdate.Wheel.TotalLatency2", 1},
{"EventLatency.GestureScrollUpdate.Wheel.TotalLatency2", 1},
{"EventLatency.InertialGestureScrollUpdate.Wheel.TotalLatency2", 1},
{"EventLatency.GestureScrollBegin.Touchscreen.TotalLatency2", 1},
{"EventLatency.FirstGestureScrollUpdate.Touchscreen.TotalLatency2", 1},
{"EventLatency.GestureScrollUpdate.Touchscreen.TotalLatency", 1},
{"EventLatency.GestureScrollUpdate.Touchscreen.TotalLatency2", 1},
{"EventLatency.InertialGestureScrollUpdate.Touchscreen.TotalLatency2", 1},
{"EventLatency.GestureScrollBegin.TotalLatency2", 2},
{"EventLatency.GestureScrollBegin.GenerationToBrowserMain", 2},
{"EventLatency.FirstGestureScrollUpdate.TotalLatency2", 2},
{"EventLatency.FirstGestureScrollUpdate.GenerationToBrowserMain", 2},
{"EventLatency.GestureScrollUpdate.TotalLatency2", 2},
{"EventLatency.GestureScrollUpdate.GenerationToBrowserMain", 2},
{"EventLatency.InertialGestureScrollUpdate.TotalLatency2", 2},
{"EventLatency.InertialGestureScrollUpdate.GenerationToBrowserMain", 2},
{"EventLatency.TotalLatency", 8},
};
for (const auto& expected_count : expected_counts) {
histogram_tester.ExpectTotalCount(expected_count.name,
expected_count.count);
}
const base::TimeTicks presentation_time =
viz_breakdown.presentation_feedback.timestamp;
struct {
const char* name;
const base::HistogramBase::Sample32 latency_ms;
} expected_latencies[] = {
{"EventLatency.GestureScrollBegin.Wheel.TotalLatency2",
static_cast<base::HistogramBase::Sample32>(
(presentation_time - event_times[0]).InMicroseconds())},
{"EventLatency.FirstGestureScrollUpdate.Wheel.TotalLatency2",
static_cast<base::HistogramBase::Sample32>(
(presentation_time - event_times[1]).InMicroseconds())},
{"EventLatency.GestureScrollUpdate.Wheel.TotalLatency2",
static_cast<base::HistogramBase::Sample32>(
(presentation_time - event_times[2]).InMicroseconds())},
{"EventLatency.InertialGestureScrollUpdate.Wheel.TotalLatency2",
static_cast<base::HistogramBase::Sample32>(
(presentation_time - event_times[3]).InMicroseconds())},
{"EventLatency.GestureScrollBegin.Touchscreen.TotalLatency2",
static_cast<base::HistogramBase::Sample32>(
(presentation_time - event_times[4]).InMicroseconds())},
{"EventLatency.FirstGestureScrollUpdate.Touchscreen.TotalLatency2",
static_cast<base::HistogramBase::Sample32>(
(presentation_time - event_times[5]).InMicroseconds())},
{"EventLatency.GestureScrollUpdate.Touchscreen.TotalLatency",
static_cast<base::HistogramBase::Sample32>(
(presentation_time - event_times[6]).InMicroseconds())},
{"EventLatency.GestureScrollUpdate.Touchscreen.TotalLatency2",
static_cast<base::HistogramBase::Sample32>(
(presentation_time - event_times[6]).InMicroseconds())},
{"EventLatency.InertialGestureScrollUpdate.Touchscreen.TotalLatency2",
static_cast<base::HistogramBase::Sample32>(
(presentation_time - event_times[7]).InMicroseconds())},
};
for (const auto& expected_latency : expected_latencies) {
histogram_tester.ExpectBucketCount(expected_latency.name,
expected_latency.latency_ms, 1);
}
}
// Tests that when a frame is presented to the user, total pinch event latency
// metrics are reported properly.
TEST_F(CompositorFrameReporterTest,
EventLatencyPinchTotalForPresentedFrameReported) {
base::HistogramTester histogram_tester;
std::unique_ptr<EventMetrics> event_metrics_ptrs[] = {
CreatePinchEventMetrics(ui::EventType::kGesturePinchBegin,
ui::ScrollInputType::kWheel),
CreatePinchEventMetrics(ui::EventType::kGesturePinchUpdate,
ui::ScrollInputType::kWheel),
CreatePinchEventMetrics(ui::EventType::kGesturePinchBegin,
ui::ScrollInputType::kTouchscreen),
CreatePinchEventMetrics(ui::EventType::kGesturePinchUpdate,
ui::ScrollInputType::kTouchscreen),
};
EXPECT_THAT(event_metrics_ptrs, Each(NotNull()));
EventMetrics::List events_metrics(
std::make_move_iterator(std::begin(event_metrics_ptrs)),
std::make_move_iterator(std::end(event_metrics_ptrs)));
std::vector<base::TimeTicks> event_times = GetEventTimestamps(events_metrics);
AdvanceNowByUs(3);
pipeline_reporter_->StartStage(
CompositorFrameReporter::StageType::kBeginImplFrameToSendBeginMainFrame,
Now());
AdvanceNowByUs(3);
pipeline_reporter_->StartStage(
CompositorFrameReporter::StageType::kEndActivateToSubmitCompositorFrame,
Now());
AdvanceNowByUs(3);
pipeline_reporter_->StartStage(
CompositorFrameReporter::StageType::
kSubmitCompositorFrameToPresentationCompositorFrame,
Now());
pipeline_reporter_->AddEventsMetrics(std::move(events_metrics));
AdvanceNowByUs(3);
viz::FrameTimingDetails viz_breakdown = BuildVizBreakdown();
pipeline_reporter_->SetVizBreakdown(viz_breakdown);
pipeline_reporter_->TerminateFrame(
CompositorFrameReporter::FrameTerminationStatus::kPresentedFrame,
viz_breakdown.presentation_feedback.timestamp);
pipeline_reporter_ = nullptr;
struct {
const char* name;
const base::HistogramBase::Count32 count;
} expected_counts[] = {
{"EventLatency.GesturePinchBegin.Touchscreen.TotalLatency", 1},
{"EventLatency.GesturePinchUpdate.Touchscreen.TotalLatency", 1},
{"EventLatency.GesturePinchBegin.Touchpad.TotalLatency", 1},
{"EventLatency.GesturePinchUpdate.Touchpad.TotalLatency", 1},
{"EventLatency.TotalLatency", 4},
};
for (const auto& expected_count : expected_counts) {
histogram_tester.ExpectTotalCount(expected_count.name,
expected_count.count);
}
const base::TimeTicks presentation_time =
viz_breakdown.presentation_feedback.timestamp;
struct {
const char* name;
const base::HistogramBase::Sample32 latency_ms;
} expected_latencies[] = {
{"EventLatency.GesturePinchBegin.Touchpad.TotalLatency",
static_cast<base::HistogramBase::Sample32>(
(presentation_time - event_times[0]).InMicroseconds())},
{"EventLatency.GesturePinchUpdate.Touchpad.TotalLatency",
static_cast<base::HistogramBase::Sample32>(
(presentation_time - event_times[1]).InMicroseconds())},
{"EventLatency.GesturePinchBegin.Touchscreen.TotalLatency",
static_cast<base::HistogramBase::Sample32>(
(presentation_time - event_times[2]).InMicroseconds())},
{"EventLatency.GesturePinchUpdate.Touchscreen.TotalLatency",
static_cast<base::HistogramBase::Sample32>(
(presentation_time - event_times[3]).InMicroseconds())},
};
for (const auto& expected_latency : expected_latencies) {
histogram_tester.ExpectBucketCount(expected_latency.name,
expected_latency.latency_ms, 1);
}
}
// Tests that when the frame is not presented to the user, event latency metrics
// are not reported.
TEST_F(CompositorFrameReporterTest,
EventLatencyForDidNotPresentFrameNotReported) {
base::HistogramTester histogram_tester;
std::unique_ptr<EventMetrics> event_metrics_ptrs[] = {
CreateEventMetrics(ui::EventType::kTouchPressed),
CreateEventMetrics(ui::EventType::kTouchMoved),
CreateEventMetrics(ui::EventType::kTouchMoved),
};
EXPECT_THAT(event_metrics_ptrs, Each(NotNull()));
EventMetrics::List events_metrics(
std::make_move_iterator(std::begin(event_metrics_ptrs)),
std::make_move_iterator(std::end(event_metrics_ptrs)));
AdvanceNowByUs(3);
pipeline_reporter_->StartStage(
CompositorFrameReporter::StageType::kBeginImplFrameToSendBeginMainFrame,
Now());
AdvanceNowByUs(3);
pipeline_reporter_->StartStage(
CompositorFrameReporter::StageType::kEndActivateToSubmitCompositorFrame,
Now());
AdvanceNowByUs(3);
pipeline_reporter_->StartStage(
CompositorFrameReporter::StageType::
kSubmitCompositorFrameToPresentationCompositorFrame,
Now());
pipeline_reporter_->AddEventsMetrics(std::move(events_metrics));
AdvanceNowByUs(3);
pipeline_reporter_->TerminateFrame(
CompositorFrameReporter::FrameTerminationStatus::kDidNotPresentFrame,
Now());
pipeline_reporter_ = nullptr;
EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix("EventLaterncy."),
IsEmpty());
}
// Verifies that partial update dependent queues are working as expected when
// they reach their maximum capacity.
TEST_F(CompositorFrameReporterTest, PartialUpdateDependentQueues) {
// This constant should match the constant with the same name in
// compositor_frame_reporter.cc.
const size_t kMaxOwnedPartialUpdateDependents = 300u;
// The first three dependent reporters for the front of the queue.
auto deps = std::to_array<std::unique_ptr<CompositorFrameReporter>>({
CreatePipelineReporter(),
CreatePipelineReporter(),
CreatePipelineReporter(),
});
// Set `deps[0]` as a dependent of the main reporter and adopt it at the same
// time. This should enqueue it in both non-owned and owned dependents queues.
deps[0]->SetPartialUpdateDecider(pipeline_reporter_.get());
pipeline_reporter_->AdoptReporter(std::move(deps[0]));
DCHECK_EQ(1u,
pipeline_reporter_->partial_update_dependents_size_for_testing());
DCHECK_EQ(
1u,
pipeline_reporter_->owned_partial_update_dependents_size_for_testing());
// Set `deps[1]` as a dependent of the main reporter, but don't adopt it yet.
// This should enqueue it in non-owned dependents queue only.
deps[1]->SetPartialUpdateDecider(pipeline_reporter_.get());
DCHECK_EQ(2u,
pipeline_reporter_->partial_update_dependents_size_for_testing());
DCHECK_EQ(
1u,
pipeline_reporter_->owned_partial_update_dependents_size_for_testing());
// Set `deps[2]` as a dependent of the main reporter and adopt it at the same
// time. This should enqueue it in both non-owned and owned dependents queues.
deps[2]->SetPartialUpdateDecider(pipeline_reporter_.get());
pipeline_reporter_->AdoptReporter(std::move(deps[2]));
DCHECK_EQ(3u,
pipeline_reporter_->partial_update_dependents_size_for_testing());
DCHECK_EQ(
2u,
pipeline_reporter_->owned_partial_update_dependents_size_for_testing());
// Now adopt `deps[1]` to enqueue it in the owned dependents queue.
pipeline_reporter_->AdoptReporter(std::move(deps[1]));
DCHECK_EQ(3u,
pipeline_reporter_->partial_update_dependents_size_for_testing());
DCHECK_EQ(
3u,
pipeline_reporter_->owned_partial_update_dependents_size_for_testing());
// Fill the queues with more dependent reporters until the capacity is
// reached. After this, the queues should look like this (assuming n equals
// `kMaxOwnedPartialUpdateDependents`):
// Partial Update Dependents: [0, 1, 2, 3, 4, ..., n-1]
// Owned Partial Update Dependents: [0, 2, 1, 3, 4, ..., n-1]
while (
pipeline_reporter_->owned_partial_update_dependents_size_for_testing() <
kMaxOwnedPartialUpdateDependents) {
std::unique_ptr<CompositorFrameReporter> dependent =
CreatePipelineReporter();
dependent->SetPartialUpdateDecider(pipeline_reporter_.get());
pipeline_reporter_->AdoptReporter(std::move(dependent));
}
DCHECK_EQ(kMaxOwnedPartialUpdateDependents,
pipeline_reporter_->partial_update_dependents_size_for_testing());
DCHECK_EQ(
kMaxOwnedPartialUpdateDependents,
pipeline_reporter_->owned_partial_update_dependents_size_for_testing());
// Enqueue a new dependent reporter. This should pop `deps[0]` from the front
// of the owned dependents queue and destroy it. Since the same one is in
// front of the non-owned dependents queue, it will be popped out of that
// queue, too. The queues will look like this:
// Partial Update Dependents: [1, 2, 3, 4, ..., n]
// Owned Partial Update Dependents: [2, 1, 3, 4, ..., n]
auto new_dep = CreatePipelineReporter();
new_dep->SetPartialUpdateDecider(pipeline_reporter_.get());
pipeline_reporter_->AdoptReporter(std::move(new_dep));
DCHECK_EQ(kMaxOwnedPartialUpdateDependents,
pipeline_reporter_->partial_update_dependents_size_for_testing());
DCHECK_EQ(
kMaxOwnedPartialUpdateDependents,
pipeline_reporter_->owned_partial_update_dependents_size_for_testing());
// Enqueue another new dependent reporter. This should pop `deps[2]` from the
// front of the owned dependents queue and destroy it. It should be removed
// from the non-owned dependents queue as well.
// Partial Update Dependents: [2, 3, 4, ..., n+1]
// Owned Partial Update Dependents: [2, 3, 4, ..., n+1]
new_dep = CreatePipelineReporter();
new_dep->SetPartialUpdateDecider(pipeline_reporter_.get());
pipeline_reporter_->AdoptReporter(std::move(new_dep));
DCHECK_EQ(kMaxOwnedPartialUpdateDependents,
pipeline_reporter_->partial_update_dependents_size_for_testing());
DCHECK_EQ(
kMaxOwnedPartialUpdateDependents,
pipeline_reporter_->owned_partial_update_dependents_size_for_testing());
// Enqueue yet another new dependent reporter. This should pop `deps[1]` from
// the front of the owned dependents queue and destroy it. Since the same one
// is in front of the non-owned dependents queue followed by `deps[2]` which
// was destroyed in the previous step, they will be popped out of that queue,
// too. The queues will look like this:
// Partial Update Dependents: [3, 4, ..., n+2]
// Owned Partial Update Dependents: [3, 4, ..., n+2]
new_dep = CreatePipelineReporter();
new_dep->SetPartialUpdateDecider(pipeline_reporter_.get());
pipeline_reporter_->AdoptReporter(std::move(new_dep));
DCHECK_EQ(kMaxOwnedPartialUpdateDependents,
pipeline_reporter_->partial_update_dependents_size_for_testing());
DCHECK_EQ(
kMaxOwnedPartialUpdateDependents,
pipeline_reporter_->owned_partial_update_dependents_size_for_testing());
}
} // namespace
} // namespace cc
|