File: preload_serving_metrics.md

package info (click to toggle)
chromium 142.0.7444.175-1~deb13u1
  • links: PTS, VCS
  • area: main
  • in suites: trixie-proposed-updates
  • size: 6,295,408 kB
  • sloc: cpp: 35,488,378; ansic: 7,479,680; javascript: 4,259,373; python: 1,466,843; xml: 757,444; asm: 710,716; pascal: 187,980; sh: 89,247; perl: 88,690; objc: 79,984; sql: 56,984; cs: 42,192; fortran: 24,137; makefile: 22,913; tcl: 15,277; php: 14,018; yacc: 9,005; ruby: 7,553; awk: 3,720; lisp: 3,096; lex: 1,330; ada: 727; jsp: 228; sed: 36
file content (138 lines) | stat: -rw-r--r-- 5,369 bytes parent folder | download | duplicates (6)
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
# PreloadServingMetrics: Logs/metrics related to preload serving

Design doc: https://docs.google.com/document/d/1bBhfhO7BotUB7Myy_8mtFF_4lI5N8hUyNayV_gI019Y

This document will become truth once the CL https://crrev.com/c/6884362 has
landed.
TODO(crrev.com/360094997): Remove the above.

## Goal

Enable collecting, recording, and analyzing serving metrics of preloads. For example:

- Continuously collect page load metrics for navigations under different
  conditions: without preloads, with prefetch used, and with prerender used.
  (E.g. to evaluate improvements of preload execution stacks.)
- Investigate the cause of regressions from new features by
  understanding what is happening during the serving phase.

## Overview

Logs/metrics are processed in three steps:

1. Log objects are recorded in each component of preloads.
2. During a navigation, log objects are collected and associated with that
   navigation.
3. At the end of the navigation, the collected logs are recorded as metrics
   (UMAs/UKMs) if certain conditions are met. (E.g. a prerender initial
   navigation is cancelled.)

## Logs

`PreloadServingMetrics` collects per-navigation, **serving-related** data about
preloads, and contains logs objects collected from several preloading components.

While `PreloadServingMetrics` must be **serving**-side metrics, it also collects
and uses non-serving-side data (e.g., data about prefetching or the initial
prerender navigation) insofar as it relates to the serving navigation.

(Some of the non-serving-side data contained in log objects are also used for
non-serving-side metrics outside `PreloadServingMetrics`.)

Examples:

- `PreloadServingMetrics`: Log of preloads associated with a navigation. May hold:
  - `PrefetchMatchMetrics` and
  - `PreloadServingMetrics` for prerender initial navigation (if the navigation
    is prerender activation navigation).
- `PrefetchMatchMetrics`: Log of prefetch matching. May hold
  `PrefetchContainerMetrics`.
- `PrefetchContainerMetrics`: Log of `PrefetchContainer`.
  - This contains data about the prefetching phase.
  - This is used for `PreloadServingMetrics`, only in the context of serving
    metrics (e.g., when the corresponding prefetch received the non-redirect
    header relative to the serving/navigation timing).
  - This is also used for metrics outside `PreloadServingMetrics` (including
    prefetching-side metrics).

The log objects are always:

- `struct`
- Passed by `std::unique_ptr<>`.
- Not movable.

Each log object is built by a related component, and becomes read-only outside
that component. For example, `PrefetchContainerMetrics` is built by
`PrefetchContainer`. It will be copied to a field of
`PrefetchMatchMetrics`, and read-only after the copy. See each log object's
comment to identify its builder component.

## Life of `PreloadServingMetrics` {#life-of-PreloadServingMetrics}

A `PreloadServingMetrics` object is created per-navigation and is owned by
`PreloadServingMetricsHolder` until navigation commit or failure.

After that, the ownership is moved to:

- `PrerenderHost` for committed prerender initial navigation.
  - The `PreloadServingMetrics` from the initial prerender navigation is then
    moved to the activation navigation's `PreloadServingMetrics` and processed
    along with it.
- `PreloadServingMetricsPageLoadMetricsObserver` (via
  `PreloadServingMetricsCapsule` that exposes `PreloadServingMetrics` to
  `//content` public) for committed non-prerender-initial navigation.
  - `PreloadServingMetricsPageLoadMetricsObserver` records UMAs/UKMs based on
    `PreloadServingMetrics`, when a navigation is committed and FCP is received.
- Discarded with recording UMAs/UKMs if it is a failed prerender initial navigation.
- Discarded without recording UMAs/UKMs otherwise.

Non-prerender navigation:

```mermaid
flowchart LR
  subgraph PreloadServingMetricsPageLoadObserver
    PreloadServingMetricsCapsule
  end
  subgraph non-prerender-navigation
    PreloadServingMetricsHolder
  end
  PreloadServingMetricsHolder --> PreloadServingMetricsCapsule
```

- If navigation is not committed, `PreloadServingMetrics` is not taken.

Prerender navigations:

```mermaid
flowchart LR
  subgraph PreloadServingMetricsPageLoadObserver
    PreloadServingMetricsCapsule
  end
  subgraph prerender initial navigation
    PreloadServingMetricsHolder-1
  end
  subgraph prerender activation navigation
    PreloadServingMetricsHolder-2
  end
  PreloadServingMetricsHolder-1 --> PrerenderHost
  PrerenderHost --> PreloadServingMetricsHolder-2
  PreloadServingMetricsHolder-2 --> PreloadServingMetricsCapsule
```

- If the prerender initial navigation is not committed and fails,
  `PreloadServingMetrics` is taken by `PrerenderHost` and used to report
  metrics for failure.
- If the prerender initial navigation is committed but `PrerenderHost` is
  cancelled, the same applies.

## Test

Tests are managed in

- //content/browser/preloading/preload_serving_metrics_unittest.cc
  - Detailed checks of the correspondence between the `PreloadServingMetrics`
    structure and the recorded metrics.
- //content/browser/preloading/prerenderer_impl_browsertest.cc
  - End-to-end checks for basic scenarios.
- //chrome/browser/preloading/search_preload/search_preload_browsertest.cc
  - End-to-end checks that include `PreloadServingMetricsPageLoadMetricsObserver`.