From 7e6c7d8d13e996f2ce9e729fb9a98828df691f67 Mon Sep 17 00:00:00 2001 From: Perfetto Team Date: Tue, 12 Dec 2023 21:29:43 +0000 Subject: [PATCH] Project import generated by Copybara. GitOrigin-RevId: 35ff80a930b42b4aa25bf8b0e8624448c9c34f35 Change-Id: I2130ffbc51277600627a601f1dadaf57142e0885 --- .../chromium/chrome_track_event.proto | 1 + .../stdlib/chrome/interactions.sql | 24 ++++- .../stdlib/chrome/perfetto_sql_files.gni | 2 + .../scroll_jank/scroll_jank_cause_utils.sql | 3 +- .../perfetto_sql/stdlib/chrome/startups.sql | 98 +++++++++++++++++++ .../chrome/web_content_interactions.sql | 44 +++++++++ 6 files changed, 169 insertions(+), 3 deletions(-) create mode 100644 src/trace_processor/perfetto_sql/stdlib/chrome/startups.sql create mode 100644 src/trace_processor/perfetto_sql/stdlib/chrome/web_content_interactions.sql diff --git a/protos/third_party/chromium/chrome_track_event.proto b/protos/third_party/chromium/chrome_track_event.proto index a68feef36e..a4ababe38e 100644 --- a/protos/third_party/chromium/chrome_track_event.proto +++ b/protos/third_party/chromium/chrome_track_event.proto @@ -751,6 +751,7 @@ message RendererMainThreadTaskExecution { TASK_TYPE_STORAGE = 82; TASK_TYPE_NETWORKING_UNFREEZABLE_IMAGE_LOADING = 83; TASK_TYPE_MAIN_THREAD_TASK_QUEUE_V8_LOW_PRIORITY = 84; + TASK_TYPE_CLIPBOARD = 85; } enum FrameType { diff --git a/src/trace_processor/perfetto_sql/stdlib/chrome/interactions.sql b/src/trace_processor/perfetto_sql/stdlib/chrome/interactions.sql index 129258c0fa..78600dc1cd 100644 --- a/src/trace_processor/perfetto_sql/stdlib/chrome/interactions.sql +++ b/src/trace_processor/perfetto_sql/stdlib/chrome/interactions.sql @@ -7,6 +7,8 @@ -- Currently we only track Chrome page loads and their associated metrics. INCLUDE PERFETTO MODULE chrome.page_loads; +INCLUDE PERFETTO MODULE chrome.startups; +INCLUDE PERFETTO MODULE chrome.web_content_interactions; -- All critical user interaction events, including type and table with -- associated metrics. @@ -33,4 +35,24 @@ SELECT 'PageLoad' AS name, navigation_start_ts AS ts, IFNULL(lcp, fcp) AS dur -FROM chrome_page_loads; +FROM chrome_page_loads +UNION ALL +SELECT + id AS scoped_id, + 'chrome_startups' AS type, + name, + startup_begin_ts AS ts, + CASE + WHEN first_visible_content_ts IS NOT NULL + THEN first_visible_content_ts - startup_begin_ts + ELSE 0 + END AS dur +FROM chrome_startups +UNION ALL +SELECT + id AS scoped_id, + 'chrome_web_content_interactions' AS type, + 'InteractionToFirstPaint' AS name, + ts, + dur +FROM chrome_web_content_interactions; diff --git a/src/trace_processor/perfetto_sql/stdlib/chrome/perfetto_sql_files.gni b/src/trace_processor/perfetto_sql/stdlib/chrome/perfetto_sql_files.gni index 5edf42c9af..9a84d4a65d 100644 --- a/src/trace_processor/perfetto_sql/stdlib/chrome/perfetto_sql_files.gni +++ b/src/trace_processor/perfetto_sql/stdlib/chrome/perfetto_sql_files.gni @@ -12,8 +12,10 @@ chrome_stdlib_sql_files = [ "metadata.sql", "page_loads.sql", "speedometer.sql", + "startups.sql", "tasks.sql", "vsync_intervals.sql", + "web_content_interactions.sql", "scroll_jank/scroll_jank_cause_map.sql", "scroll_jank/scroll_jank_cause_utils.sql", "scroll_jank/scroll_jank_intervals.sql", diff --git a/src/trace_processor/perfetto_sql/stdlib/chrome/scroll_jank/scroll_jank_cause_utils.sql b/src/trace_processor/perfetto_sql/stdlib/chrome/scroll_jank/scroll_jank_cause_utils.sql index 35780fb57b..78d3964d38 100644 --- a/src/trace_processor/perfetto_sql/stdlib/chrome/scroll_jank/scroll_jank_cause_utils.sql +++ b/src/trace_processor/perfetto_sql/stdlib/chrome/scroll_jank/scroll_jank_cause_utils.sql @@ -2,7 +2,6 @@ -- Use of this source code is governed by a BSD-style license that can be -- found in the LICENSE file. - -- Function to retrieve the upid for a surfaceflinger, as these are attributed -- to the GPU but are recorded on a different data source (and track group). CREATE PERFETTO FUNCTION internal_get_process_id_for_surfaceflinger() @@ -32,7 +31,7 @@ WITH process_names ( AS ( VALUES ('Browser', 'Browser', '*.chrome'), - ('GPU', 'Gpu', '*.chrome:privileged_process*')) + ('GPU', 'Gpu', '*.chrome*:privileged_process*')) SELECT process_type, process_name, diff --git a/src/trace_processor/perfetto_sql/stdlib/chrome/startups.sql b/src/trace_processor/perfetto_sql/stdlib/chrome/startups.sql new file mode 100644 index 0000000000..8d7e6407a0 --- /dev/null +++ b/src/trace_processor/perfetto_sql/stdlib/chrome/startups.sql @@ -0,0 +1,98 @@ +-- Copyright 2023 The Chromium Authors +-- Use of this source code is governed by a BSD-style license that can be +-- found in the LICENSE file. + +INCLUDE PERFETTO MODULE common.slices; + +-- Access all startups, including those that don't lead to any visible content. +-- If TimeToFirstVisibleContent is available, then this event will be the +-- main event of the startup. Otherwise, the event for the start timestamp will +-- be used. +CREATE PERFETTO VIEW internal_startup_start_events AS +WITH +starts AS ( + SELECT + name, + EXTRACT_ARG(arg_set_id, 'startup.activity_id') AS activity_id, + ts, + dur, + upid AS browser_upid + FROM thread_slice + WHERE name = 'Startup.ActivityStart' +), +times_to_first_visible_content AS ( + SELECT + name, + EXTRACT_ARG(arg_set_id, 'startup.activity_id') AS activity_id, + ts, + dur, + upid AS browser_upid + FROM process_slice + WHERE name = 'Startup.TimeToFirstVisibleContent2' +), +all_activity_ids AS ( + SELECT + DISTINCT activity_id, + browser_upid + FROM starts + UNION ALL + SELECT + DISTINCT activity_id, + browser_upid + FROM times_to_first_visible_content +), +activity_ids AS ( + SELECT + DISTINCT activity_id, + browser_upid + FROM all_activity_ids +) +SELECT + activity_ids.activity_id, + 'Startup' AS name, + IFNULL(times_to_first_visible_content.ts, starts.ts) AS startup_begin_ts, + times_to_first_visible_content.ts + + times_to_first_visible_content.dur AS first_visible_content_ts, + activity_ids.browser_upid +FROM activity_ids + LEFT JOIN times_to_first_visible_content using(activity_id, browser_upid) + LEFT JOIN starts using(activity_id, browser_upid); + +-- Chrome launch causes, not recorded at start time; use the activity id to +-- join with the actual startup events. +CREATE PERFETTO VIEW internal_launch_causes AS +SELECT + EXTRACT_ARG(arg_set_id, 'startup.activity_id') AS activity_id, + EXTRACT_ARG(arg_set_id, 'startup.launch_cause') AS launch_cause, + upid AS browser_upid +FROM thread_slice +WHERE name = 'Startup.LaunchCause'; + +-- Chrome startups, including launch cause. +CREATE PERFETTO TABLE chrome_startups( + -- Unique ID + id INT, + -- Chrome Activity event id of the launch. + activity_id INT, + -- Name of the launch start event. + name STRING, + -- Timestamp that the startup occurred. + startup_begin_ts INT, + -- Timestamp to the first visible content. + first_visible_content_ts INT, + -- Launch cause. See Startup.LaunchCauseType in chrome_track_event.proto. + launch_cause STRING, + -- Process ID of the Browser where the startup occurred. + browser_upid INT +) AS +SELECT + ROW_NUMBER() OVER (ORDER BY start_events.startup_begin_ts) AS id, + start_events.activity_id, + start_events.name, + start_events.startup_begin_ts, + start_events.first_visible_content_ts, + launches.launch_cause, + start_events.browser_upid +FROM internal_startup_start_events start_events + LEFT JOIN internal_launch_causes launches + USING(activity_id, browser_upid); diff --git a/src/trace_processor/perfetto_sql/stdlib/chrome/web_content_interactions.sql b/src/trace_processor/perfetto_sql/stdlib/chrome/web_content_interactions.sql new file mode 100644 index 0000000000..bb9d9619dc --- /dev/null +++ b/src/trace_processor/perfetto_sql/stdlib/chrome/web_content_interactions.sql @@ -0,0 +1,44 @@ +-- Copyright 2023 The Chromium Authors +-- Use of this source code is governed by a BSD-style license that can be +-- found in the LICENSE file. + +INCLUDE PERFETTO MODULE common.slices; + +-- Chrome web content interactions (InteractionToFirstPaint), including +-- associated high-level metrics and properties. +-- +-- Multiple events may occur for the same interaction; each row in this table +-- represents the primary (longest) event for the interaction. +-- +-- Web content interactions are discrete, as opposed to sustained (e.g. +-- scrolling); and only occur with the web content itself, as opposed to other +-- parts of Chrome (e.g. omnibox). Interaction events include taps, clicks, +-- keyboard input (typing), and drags. +CREATE PERFETTO TABLE chrome_web_content_interactions( + -- Unique id for this interaction. + id INT, + -- Start timestamp of the event. Because multiple events may occur for the + -- same interaction, this is the start timestamp of the longest event. + ts INT, + -- Duration of the event. Because multiple events may occur for the same + -- interaction, this is the duration of the longest event. + dur INT, + -- The interaction type. + interaction_type STRING, + -- The total duration of all events that occurred for the same interaction. + total_duration_ms INT, + -- The process id this event occurred on. + renderer_upid INT +) AS +SELECT + id, + ts, + dur, + EXTRACT_ARG(arg_set_id, 'web_content_interaction.type') AS interaction_type, + EXTRACT_ARG( + arg_set_id, + 'web_content_intaraction.total_duration_ms' + ) AS total_duration_ms, + upid AS renderer_upid +FROM process_slice +WHERE name = 'Web Interaction';