xref: /aosp_15_r20/external/cronet/base/tracing/stdlib/chrome/startups.sql (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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
5INCLUDE PERFETTO MODULE slices.with_context;
6
7-- Access all startups, including those that don't lead to any visible content.
8-- If TimeToFirstVisibleContent is available, then this event will be the
9-- main event of the startup. Otherwise, the event for the start timestamp will
10-- be used.
11CREATE PERFETTO VIEW _startup_start_events AS
12WITH
13starts AS (
14  SELECT
15    name,
16    EXTRACT_ARG(arg_set_id, 'startup.activity_id') AS activity_id,
17    ts,
18    dur,
19    upid AS browser_upid
20  FROM thread_slice
21  WHERE name = 'Startup.ActivityStart'
22),
23times_to_first_visible_content AS (
24  SELECT
25    name,
26    EXTRACT_ARG(arg_set_id, 'startup.activity_id') AS activity_id,
27    ts,
28    dur,
29    upid AS browser_upid
30  FROM process_slice
31  WHERE name = 'Startup.TimeToFirstVisibleContent2'
32),
33all_activity_ids AS (
34  SELECT
35    DISTINCT activity_id,
36    browser_upid
37  FROM starts
38  UNION ALL
39  SELECT
40    DISTINCT activity_id,
41    browser_upid
42  FROM times_to_first_visible_content
43),
44activity_ids AS (
45  SELECT
46    DISTINCT activity_id,
47    browser_upid
48  FROM all_activity_ids
49)
50SELECT
51  activity_ids.activity_id,
52  'Startup' AS name,
53  IFNULL(times_to_first_visible_content.ts, starts.ts) AS startup_begin_ts,
54  times_to_first_visible_content.ts +
55    times_to_first_visible_content.dur AS first_visible_content_ts,
56  activity_ids.browser_upid
57FROM activity_ids
58  LEFT JOIN times_to_first_visible_content using(activity_id, browser_upid)
59  LEFT JOIN starts using(activity_id, browser_upid);
60
61-- Chrome launch causes, not recorded at start time; use the activity id to
62-- join with the actual startup events.
63CREATE PERFETTO VIEW _launch_causes AS
64SELECT
65  EXTRACT_ARG(arg_set_id, 'startup.activity_id') AS activity_id,
66  EXTRACT_ARG(arg_set_id, 'startup.launch_cause') AS launch_cause,
67  upid AS browser_upid
68FROM thread_slice
69WHERE name = 'Startup.LaunchCause';
70
71-- Chrome startups, including launch cause.
72CREATE PERFETTO TABLE chrome_startups(
73  -- Unique ID
74  id INT,
75  -- Chrome Activity event id of the launch.
76  activity_id INT,
77  -- Name of the launch start event.
78  name STRING,
79  -- Timestamp that the startup occurred.
80  startup_begin_ts INT,
81  -- Timestamp to the first visible content.
82  first_visible_content_ts INT,
83  -- Launch cause. See Startup.LaunchCauseType in chrome_track_event.proto.
84  launch_cause STRING,
85  -- Process ID of the Browser where the startup occurred.
86  browser_upid INT
87) AS
88SELECT
89  ROW_NUMBER() OVER (ORDER BY start_events.startup_begin_ts) AS id,
90  start_events.activity_id,
91  start_events.name,
92  start_events.startup_begin_ts,
93  start_events.first_visible_content_ts,
94  launches.launch_cause,
95  start_events.browser_upid
96FROM _startup_start_events start_events
97  LEFT JOIN _launch_causes launches
98  USING(activity_id, browser_upid);
99