• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1-- Copyright 2023 The Chromium Authors
2-- Use of this source code is governed by a BSD-style license that can be
3-- found in the LICENSE file.
4
5-- TODO(b/306300843): The recorded navigation ids are not guaranteed to be
6-- unique within a trace; they are only guaranteed to be unique within a single
7-- chrome instance. Chrome instance id needs to be recorded, and used here in
8-- combination with navigation id to uniquely identify page load metrics.
9
10INCLUDE PERFETTO MODULE slices.with_context;
11
12CREATE PERFETTO VIEW _fcp_metrics AS
13SELECT
14  ts,
15  dur,
16  EXTRACT_ARG(arg_set_id, 'page_load.navigation_id') AS navigation_id,
17  EXTRACT_ARG(arg_set_id, 'page_load.url') AS url,
18  upid AS browser_upid
19FROM process_slice
20WHERE name = 'PageLoadMetrics.NavigationToFirstContentfulPaint';
21
22CREATE PERFETTO FUNCTION _page_load_metrics(event_name STRING)
23RETURNS TABLE(
24  ts TIMESTAMP,
25  dur DURATION,
26  navigation_id LONG,
27  browser_upid LONG
28) AS
29SELECT
30  ts,
31  dur,
32  EXTRACT_ARG(arg_set_id, 'page_load.navigation_id')
33    AS navigation_id,
34  upid AS browser_upid
35FROM process_slice
36WHERE name = $event_name;
37
38-- Chrome page loads, including associated high-level metrics and properties.
39CREATE PERFETTO TABLE chrome_page_loads(
40  -- ID of the navigation and Chrome browser process; this combination is
41  -- unique to every individual navigation.
42  id LONG,
43  -- ID of the navigation associated with the page load (i.e. the cross-document
44  -- navigation in primary main frame which created this page's main document).
45  -- Also note that navigation_id is specific to a given Chrome browser process,
46  -- and not globally unique.
47  navigation_id LONG,
48  -- Timestamp of the start of navigation.
49  navigation_start_ts TIMESTAMP,
50  -- Duration between the navigation start and the first contentful paint event
51  -- (web.dev/fcp).
52  fcp LONG,
53  -- Timestamp of the first contentful paint.
54  fcp_ts TIMESTAMP,
55  -- Duration between the navigation start and the largest contentful paint event
56  -- (web.dev/lcp).
57  lcp LONG,
58  -- Timestamp of the largest contentful paint.
59  lcp_ts TIMESTAMP,
60  -- Timestamp of the DomContentLoaded event:
61  -- https://developer.mozilla.org/en-US/docs/Web/API/Document/DOMContentLoaded_event
62  dom_content_loaded_event_ts TIMESTAMP,
63  -- Timestamp of the window load event:
64  -- https://developer.mozilla.org/en-US/docs/Web/API/Window/load_event
65  load_event_ts TIMESTAMP,
66  -- Timestamp of the page self-reporting as fully loaded through the
67  -- performance.mark('mark_fully_loaded') API.
68  mark_fully_loaded_ts TIMESTAMP,
69  -- Timestamp of the page self-reporting as fully visible through the
70  -- performance.mark('mark_fully_visible') API.
71  mark_fully_visible_ts TIMESTAMP,
72  -- Timestamp of the page self-reporting as fully interactive through the
73  -- performance.mark('mark_interactive') API.
74  mark_interactive_ts TIMESTAMP,
75  -- URL at the page load event.
76  url STRING,
77  -- The unique process id (upid) of the browser process where the page load occurred.
78  browser_upid LONG
79) AS
80SELECT
81  ROW_NUMBER() OVER(ORDER BY fcp.ts) AS id,
82  fcp.navigation_id,
83  fcp.ts AS navigation_start_ts,
84  fcp.dur AS fcp,
85  fcp.ts + fcp.dur AS fcp_ts,
86  lcp.dur AS lcp,
87  lcp.dur + lcp.ts AS lcp_ts,
88  load_fired.ts AS dom_content_loaded_event_ts,
89  start_load.ts AS load_event_ts,
90  timing_loaded.ts AS mark_fully_loaded_ts,
91  timing_visible.ts AS mark_fully_visible_ts,
92  timing_interactive.ts AS mark_interactive_ts,
93  fcp.url,
94  fcp.browser_upid
95FROM _fcp_metrics fcp
96LEFT JOIN
97  _page_load_metrics('PageLoadMetrics.NavigationToLargestContentfulPaint') lcp
98    USING (navigation_id, browser_upid)
99LEFT JOIN
100  _page_load_metrics('PageLoadMetrics.NavigationToDOMContentLoadedEventFired') load_fired
101    USING (navigation_id, browser_upid)
102LEFT JOIN
103  _page_load_metrics('PageLoadMetrics.NavigationToMainFrameOnLoad') start_load
104    USING (navigation_id, browser_upid)
105LEFT JOIN
106  _page_load_metrics('PageLoadMetrics.UserTimingMarkFullyLoaded') timing_loaded
107    USING (navigation_id, browser_upid)
108LEFT JOIN
109  _page_load_metrics('PageLoadMetrics.UserTimingMarkFullyVisible') timing_visible
110    USING (navigation_id, browser_upid)
111LEFT JOIN
112  _page_load_metrics('PageLoadMetrics.UserTimingMarkInteractive') timing_interactive
113    USING (navigation_id, browser_upid);
114