Commit b5e4f7f7 authored by Nicolás Peña Moreno's avatar Nicolás Peña Moreno Committed by Commit Bot

Add UKM for full viewport image LCP

Privacy review:
https://docs.google.com/document/d/1L93H6TYrtq4qRWzvEa3H7uKZhwWCtTTJ_bT6QFdg_ys/edit#heading=h.k5jx6iluw4yt

Bug: 1133883
Change-Id: I07a89ebca144e8ee7d5600f2b5eba79b7069a64c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2450610
Commit-Queue: Nicolás Peña Moreno <npm@chromium.org>
Reviewed-by: default avatarXianzhu Wang <wangxianzhu@chromium.org>
Reviewed-by: default avatarBryan McQuade <bmcquade@chromium.org>
Reviewed-by: default avatarAnnie Sullivan <sullivan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816645}
parent 5aeef1b8
......@@ -3,6 +3,8 @@
// found in the LICENSE file.
#include "third_party/blink/renderer/core/paint/image_paint_timing_detector.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/local_frame_view.h"
#include "third_party/blink/renderer/core/layout/layout_image_resource.h"
......@@ -175,6 +177,17 @@ void ImagePaintTimingDetector::NotifyImageRemoved(
need_update_timing_at_frame_end_ = true;
}
void ImagePaintTimingDetector::StopRecordEntries() {
is_recording_ = false;
if (frame_view_->GetFrame().IsMainFrame()) {
DCHECK(frame_view_->GetFrame().GetDocument());
ukm::builders::Blink_PaintTiming(
frame_view_->GetFrame().GetDocument()->UkmSourceID())
.SetLCPDebugging_HasViewportImage(contains_full_viewport_image_)
.Record(ukm::UkmRecorder::Get());
}
}
void ImagePaintTimingDetector::RegisterNotifySwapTime() {
auto callback = WTF::Bind(&ImagePaintTimingDetector::ReportSwapTime,
WrapCrossThreadWeakPersistent(this),
......@@ -307,8 +320,10 @@ uint64_t ImagePaintTimingDetector::ComputeImageRectSize(
// SVG, so |rect_size| can be larger than |*viewport_size| in edge cases. If
// the rect occupies the whole viewport, disregard this candidate by saying
// the size is 0.
if (rect_size >= *viewport_size_)
if (rect_size >= *viewport_size_) {
contains_full_viewport_image_ = true;
return 0;
}
rect_size = DownScaleIfIntrinsicSizeIsSmaller(
rect_size, intrinsic_size.Area(),
......
......@@ -266,7 +266,7 @@ class CORE_EXPORT ImagePaintTimingDetector final
// an image is recorded before stopping recording, and finish loading after
// stopping recording, the detector can still observe the loading being
// finished.
inline void StopRecordEntries() { is_recording_ = false; }
void StopRecordEntries();
inline bool IsRecording() const { return is_recording_; }
inline bool FinishedReportingImages() const {
return !is_recording_ && num_pending_swap_callbacks_ == 0;
......@@ -322,6 +322,8 @@ class CORE_EXPORT ImagePaintTimingDetector final
// |FindLargestPaintCandidate| occur during the paint tree walk.
bool need_update_timing_at_frame_end_ = false;
bool contains_full_viewport_image_ = false;
// We cache the viewport size computation to avoid performing it on every
// image. This value is reset when paint is finished and is computed if unset
// when needed. 0 means that the size has not been computed.
......
......@@ -8,6 +8,8 @@
#include "base/test/test_mock_time_task_runner.h"
#include "base/test/trace_event_analyzer.h"
#include "build/build_config.h"
#include "components/ukm/test_ukm_recorder.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "third_party/blink/public/web/web_performance.h"
#include "third_party/blink/public/web/web_widget_client.h"
#include "third_party/blink/renderer/core/frame/frame_test_helpers.h"
......@@ -50,6 +52,8 @@ namespace blink {
"oIRn/wsGUQIIy4Vr9TH6SYFCNzw4nALn5627K4vIttOUOwfa5YnrDYzt/9OLv9I5l8kk5hZ3XL" \
"O20b7tbR7zHLy/BX8G0IeBEM7ZN1NGIaFUaKLgAAAAAElFTkSuQmCC"
using UkmPaintTiming = ukm::builders::Blink_PaintTiming;
class ImagePaintTimingDetectorTest : public testing::Test,
public PaintTestConfigurations {
public:
......@@ -259,6 +263,10 @@ class ImagePaintTimingDetectorTest : public testing::Test,
GetPaintTimingDetector().NotifyScroll(mojom::blink::ScrollType::kUser);
}
void SimulateKeyDown() {
GetPaintTimingDetector().NotifyInputEvent(WebInputEvent::Type::kKeyDown);
}
void SimulateKeyUp() {
GetPaintTimingDetector().NotifyInputEvent(WebInputEvent::Type::kKeyUp);
}
......@@ -305,6 +313,7 @@ TEST_P(ImagePaintTimingDetectorTest, LargestImagePaint_NoImage) {
}
TEST_P(ImagePaintTimingDetectorTest, LargestImagePaint_OneImage) {
ukm::TestAutoSetUkmRecorder test_ukm_recorder;
SetBodyInnerHTML(R"HTML(
<img id="target"></img>
)HTML");
......@@ -315,6 +324,13 @@ TEST_P(ImagePaintTimingDetectorTest, LargestImagePaint_OneImage) {
EXPECT_EQ(record->first_size, 25ul);
EXPECT_TRUE(record->loaded);
EXPECT_EQ(ExperimentalLargestPaintSize(), 25ul);
// Simulate some input event to force StopRecordEntries().
SimulateKeyDown();
auto entries = test_ukm_recorder.GetEntriesByName(UkmPaintTiming::kEntryName);
EXPECT_EQ(1ul, entries.size());
auto* entry = entries[0];
test_ukm_recorder.ExpectEntryMetric(
entry, UkmPaintTiming::kLCPDebugging_HasViewportImageName, false);
}
TEST_P(ImagePaintTimingDetectorTest, InsertionOrderIsSecondaryRankingKey) {
......@@ -1234,4 +1250,23 @@ TEST_P(ImagePaintTimingDetectorTest, OpacityZeroHTML2) {
EXPECT_EQ(CountVisibleImageRecords(), 0u);
}
TEST_P(ImagePaintTimingDetectorTest, LargestImagePaint_FullViewportImage) {
ukm::TestAutoSetUkmRecorder test_ukm_recorder;
SetBodyInnerHTML(R"HTML(
<style>body {margin: 0px;}</style>
<img id="target"></img>
)HTML");
SetImageAndPaint("target", 3000, 3000);
UpdateAllLifecyclePhasesAndInvokeCallbackIfAny();
ImageRecord* record = FindLargestPaintCandidate();
EXPECT_FALSE(record);
// Simulate some input event to force StopRecordEntries().
SimulateKeyDown();
auto entries = test_ukm_recorder.GetEntriesByName(UkmPaintTiming::kEntryName);
EXPECT_EQ(1ul, entries.size());
auto* entry = entries[0];
test_ukm_recorder.ExpectEntryMetric(
entry, UkmPaintTiming::kLCPDebugging_HasViewportImageName, true);
}
} // namespace blink
......@@ -2062,6 +2062,21 @@ be describing additional metrics about the same event.
</metric>
</event>
<event name="Blink.PaintTiming" singular="True">
<owner>npm@chromium.org</owner>
<owner>sullivan@chromium.org</owner>
<summary>
Paint timing metrics recorded in Blink, usually used as debugging metrics
for PaintTiming metrics in the PageLoad event.
</summary>
<metric name="LCPDebugging.HasViewportImage" enum="Boolean">
<summary>
Records whether a page has an image whose size equals the full viewport.
Recorded when the LCP algorithm has stopped.
</summary>
</metric>
</event>
<event name="Blink.Script.AsyncScripts" singular="True">
<owner>dom@chromium.org</owner>
<owner>chrome-loading@google.com</owner>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment