Skip to content

Commit

Permalink
Use struct to pass LCP info around for ukm recording
Browse files Browse the repository at this point in the history
Refactor data passing in Ukm recording of LCP

This CL refactors how LCP information is passed around for Ukm
recording.

Currently, each LCP field, like LCP type, LCP image
paint, LCP image size, etc, has a getter in 3 objects,
PaintTimingDetector, PerformanceTimingForReporting, and
WebPerformanceTimingForReporting and is passed around individually. This
results in increasingly many getters with similar names.

This CL use a struct that contains all LCP information to pass around.
This is more readable and maintainable.

Change-Id: Ief04b054ea8b0d23f01d6fbc3714dd48398a8a87
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4545168
Reviewed-by: Ian Clelland <iclelland@chromium.org>
Reviewed-by: Yoav Weiss <yoavweiss@chromium.org>
Commit-Queue: Hao Liu <haoliuk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1150258}
  • Loading branch information
haoliuk authored and Chromium LUCI CQ committed May 29, 2023
1 parent 6134c4b commit 7325483
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 357 deletions.
4 changes: 4 additions & 0 deletions components/page_load_metrics/common/page_load_timing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ mojom::PageLoadTimingPtr CreatePageLoadTiming() {
absl::optional<base::TimeDelta>());
}

mojom::LargestContentfulPaintTimingPtr CreateLargestContentfulPaintTiming() {
return mojom::LargestContentfulPaintTiming::New();
}

bool IsEmpty(const page_load_metrics::mojom::DocumentTiming& timing) {
return !timing.dom_content_loaded_event_start && !timing.load_event_start;
}
Expand Down
1 change: 1 addition & 0 deletions components/page_load_metrics/common/page_load_timing.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace page_load_metrics {

// Initialize an empty PageLoadTiming with initialized empty sub-members.
mojom::PageLoadTimingPtr CreatePageLoadTiming();
mojom::LargestContentfulPaintTimingPtr CreateLargestContentfulPaintTiming();

bool IsEmpty(const mojom::DocumentTiming& timing);
bool IsEmpty(const mojom::PaintTiming& timing);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -622,68 +622,82 @@ MetricsRenderFrameObserver::Timing MetricsRenderFrameObserver::GetTiming()
CreateTimeDeltaFromTimestampsInSeconds(perf.FirstMeaningfulPaint(),
start);
}
if (perf.LargestImagePaintSizeForMetrics() > 0) {
blink::LargestContentfulPaintDetailsForReporting
largest_contentful_paint_details =
perf.LargestContentfulDetailsForMetrics();

if (largest_contentful_paint_details.image_paint_size > 0) {
timing->paint_timing->largest_contentful_paint->largest_image_paint_size =
perf.LargestImagePaintSizeForMetrics();
largest_contentful_paint_details.image_paint_size;
// Note that size can be nonzero while the time is 0 since a time of 0 is
// sent when the image is painting. We assign the time even when it is 0 so
// that it's not ignored, but need to be careful when doing operations on
// the value.
timing->paint_timing->largest_contentful_paint->largest_image_paint =
perf.LargestImagePaintForMetrics() == 0.0
largest_contentful_paint_details.image_paint_time == 0.0
? base::TimeDelta()
: CreateTimeDeltaFromTimestampsInSeconds(
perf.LargestImagePaintForMetrics(), start);
largest_contentful_paint_details.image_paint_time, start);

timing->paint_timing->largest_contentful_paint->type =
LargestContentfulPaintTypeToUKMFlags(
perf.LargestContentfulPaintTypeForMetrics());
largest_contentful_paint_details.type);

timing->paint_timing->largest_contentful_paint->image_bpp =
perf.LargestContentfulPaintImageBPPForMetrics();
if (perf.LargestContentfulPaintImageRequestPriorityForMetrics()) {
largest_contentful_paint_details.image_bpp;

if (largest_contentful_paint_details.image_request_priority.has_value()) {
timing->paint_timing->largest_contentful_paint
->image_request_priority_valid = true;
timing->paint_timing->largest_contentful_paint
->image_request_priority_value =
blink::WebURLRequest::ConvertToNetPriority(
*perf.LargestContentfulPaintImageRequestPriorityForMetrics());
largest_contentful_paint_details.image_request_priority.value());
} else {
timing->paint_timing->largest_contentful_paint
->image_request_priority_valid = false;
}

// Set largest image load type
if (perf.LargestContentfulPaintImageLoadStart().has_value()) {
if (largest_contentful_paint_details.image_load_start.has_value()) {
timing->paint_timing->largest_contentful_paint->largest_image_load_start =
CreateTimeDeltaFromTimestampsInSeconds(
(*perf.LargestContentfulPaintImageLoadStart()).InSecondsF(),
(largest_contentful_paint_details.image_load_start.value())
.InSecondsF(),
start);
}
if (perf.LargestContentfulPaintImageLoadEnd().has_value()) {

if (largest_contentful_paint_details.image_load_end.has_value()) {
timing->paint_timing->largest_contentful_paint->largest_image_load_end =
CreateTimeDeltaFromTimestampsInSeconds(
(*perf.LargestContentfulPaintImageLoadEnd()).InSecondsF(), start);
(largest_contentful_paint_details.image_load_end.value())
.InSecondsF(),
start);
}

timing->paint_timing->largest_contentful_paint
->is_loaded_from_memory_cache =
perf.LargestContentfulPaintImageIsLoadedFromMemoryCache();
largest_contentful_paint_details.is_loaded_from_memory_cache;

timing->paint_timing->largest_contentful_paint
->is_preloaded_with_early_hints =
perf.LargestContentfulPaintImageIsPreloadedWithEarlyHints();
largest_contentful_paint_details.is_preloaded_with_early_hints;
}
if (perf.LargestTextPaintSizeForMetrics() > 0) {
if (largest_contentful_paint_details.text_paint_size > 0) {
// LargestTextPaint and LargestTextPaintSize should be available at the
// same time. This is a renderer side DCHECK to ensure this.
DCHECK(perf.LargestTextPaintForMetrics());
DCHECK(largest_contentful_paint_details.text_paint_time);

timing->paint_timing->largest_contentful_paint->largest_text_paint =
CreateTimeDeltaFromTimestampsInSeconds(
perf.LargestTextPaintForMetrics(), start);
largest_contentful_paint_details.text_paint_time, start);

timing->paint_timing->largest_contentful_paint->largest_text_paint_size =
perf.LargestTextPaintSizeForMetrics();
largest_contentful_paint_details.text_paint_size;

timing->paint_timing->largest_contentful_paint->type =
LargestContentfulPaintTypeToUKMFlags(
perf.LargestContentfulPaintTypeForMetrics());
largest_contentful_paint_details.type);
}
// It is possible for a frame to switch from eligible for painting to
// ineligible for it prior to the first paint. If this occurs, we need to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@ namespace blink {

class WindowPerformance;

struct LargestContentfulPaintDetailsForReporting {
double image_paint_time = 0;
uint64_t image_paint_size = 0;
absl::optional<base::TimeDelta> image_load_start = absl::nullopt;
absl::optional<base::TimeDelta> image_load_end = absl::nullopt;
blink::LargestContentfulPaintType type =
blink::LargestContentfulPaintType::kNone;
double image_bpp = 0.0;
double text_paint_time = 0;
uint64_t text_paint_size = 0;
base::TimeTicks paint_time = base::TimeTicks();
absl::optional<WebURLRequest::Priority> image_request_priority =
absl::nullopt;
bool is_loaded_from_memory_cache = false;
bool is_preloaded_with_early_hints = false;
};

// This class is used for reporting purposes (e.g. ukm) of non-web-exposed
// metrics.
class BLINK_EXPORT WebPerformanceMetricsForReporting {
Expand Down Expand Up @@ -78,20 +95,8 @@ class BLINK_EXPORT WebPerformanceMetricsForReporting {
base::TimeTicks FirstContentfulPaintRenderedButNotPresentedAsMonotonicTime()
const;
double FirstMeaningfulPaint() const;
double LargestImagePaintForMetrics() const;
uint64_t LargestImagePaintSizeForMetrics() const;
absl::optional<base::TimeDelta> LargestContentfulPaintImageLoadStart() const;
absl::optional<base::TimeDelta> LargestContentfulPaintImageLoadEnd() const;
bool LargestContentfulPaintImageIsLoadedFromMemoryCache() const;
bool LargestContentfulPaintImageIsPreloadedWithEarlyHints() const;
double LargestTextPaintForMetrics() const;
uint64_t LargestTextPaintSizeForMetrics() const;
base::TimeTicks LargestContentfulPaintAsMonotonicTimeForMetrics() const;
blink::LargestContentfulPaintType LargestContentfulPaintTypeForMetrics()
LargestContentfulPaintDetailsForReporting LargestContentfulDetailsForMetrics()
const;
double LargestContentfulPaintImageBPPForMetrics() const;
absl::optional<WebURLRequest::Priority>
LargestContentfulPaintImageRequestPriorityForMetrics() const;
double FirstEligibleToPaint() const;
double FirstInputOrScrollNotifiedTimestamp() const;
absl::optional<base::TimeDelta> FirstInputDelay() const;
Expand Down

0 comments on commit 7325483

Please sign in to comment.