• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1--
2-- Copyright 2021 The Android Open Source Project
3--
4-- Licensed under the Apache License, Version 2.0 (the "License");
5-- you may not use this file except in compliance with the License.
6-- You may obtain a copy of the License at
7--
8--     https://www.apache.org/licenses/LICENSE-2.0
9--
10-- Unless required by applicable law or agreed to in writing, software
11-- distributed under the License is distributed on an "AS IS" BASIS,
12-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-- See the License for the specific language governing permissions and
14-- limitations under the License.
15
16DROP VIEW IF EXISTS InteractionEvents;
17CREATE VIEW InteractionEvents AS
18SELECT
19  ts, dur, ts AS ts_ir, dur AS dur_ir
20FROM slice WHERE name LIKE 'Interaction.%';
21
22DROP VIEW IF EXISTS GestureLegacyEvents;
23CREATE VIEW GestureLegacyEvents AS
24SELECT
25  ts,
26  EXTRACT_ARG(arg_set_id, 'legacy_event.phase') AS phase
27FROM raw
28WHERE EXTRACT_ARG(arg_set_id, 'legacy_event.name') = 'SyntheticGestureController::running';
29
30-- Convert pairs of 'S' and 'F' events into slices with ts and dur.
31DROP VIEW IF EXISTS GestureEvents;
32CREATE VIEW GestureEvents AS
33SELECT
34  ts, dur, ts AS ts_ge, dur AS dur_ge
35FROM (
36  SELECT
37    ts,
38    phase,
39    LEAD(ts) OVER (ORDER BY ts) - ts as dur
40  FROM GestureLegacyEvents
41)
42WHERE phase = 'S';
43
44DROP TABLE IF EXISTS InteractionEventsJoinGestureEvents;
45CREATE VIRTUAL TABLE InteractionEventsJoinGestureEvents
46USING SPAN_LEFT_JOIN(InteractionEvents, GestureEvents);
47
48--------------------------------------------------------------------------------
49-- Interesting segments are:
50-- 1) If there's a gesture overlapping with interaction, then gesture's range.
51-- 2) Else, interaction's range.
52
53DROP VIEW IF EXISTS InterestingSegments;
54CREATE VIEW InterestingSegments AS
55SELECT  -- 1) Gestures overlapping interactions.
56  ts_ge AS ts,
57  dur_ge AS dur
58FROM InteractionEventsJoinGestureEvents
59WHERE ts_ge IS NOT NULL
60GROUP BY ts_ge
61UNION ALL
62SELECT  -- 2) Interactions without gestures.
63  ts_ir AS ts,
64  dur_ir AS dur
65FROM InteractionEventsJoinGestureEvents
66WHERE ts_ge IS NULL
67GROUP BY ts_ir
68HAVING COUNT(*) = 1;
69
70--------------------------------------------------------------------------------
71-- On ChromeOS, DRM events, if they exist, are the source of truth. Otherwise,
72-- look for display rendering stats.
73-- On Android, the TBMv2 version relied on Surface Flinger events that are
74-- currently unavailable in proto traces. So results may be different from
75-- the TBMv2 version on this platform.
76
77DROP TABLE IF EXISTS DisplayCompositorPresentationEvents;
78CREATE TABLE DisplayCompositorPresentationEvents AS
79SELECT ts, FALSE AS exp
80FROM slice
81WHERE name = 'DrmEventFlipComplete'
82GROUP BY ts;
83
84INSERT INTO DisplayCompositorPresentationEvents
85SELECT ts, FALSE AS exp
86FROM slice
87WHERE
88  name = 'vsync_before'
89  AND NOT EXISTS (SELECT * FROM DisplayCompositorPresentationEvents)
90GROUP BY ts;
91
92INSERT INTO DisplayCompositorPresentationEvents
93SELECT ts, FALSE AS exp
94FROM slice
95WHERE
96  name = 'BenchmarkInstrumentation::DisplayRenderingStats'
97  AND NOT EXISTS (SELECT * FROM DisplayCompositorPresentationEvents)
98GROUP BY ts;
99
100INSERT INTO DisplayCompositorPresentationEvents
101SELECT ts, TRUE AS exp
102FROM slice
103WHERE name = 'Display::FrameDisplayed'
104GROUP BY ts;
105
106DROP VIEW IF EXISTS FrameSegments;
107CREATE VIEW FrameSegments AS
108SELECT
109  ts,
110  LEAD(ts) OVER wnd - ts as dur,
111  ts as ts_fs,
112  LEAD(ts) OVER wnd - ts as dur_fs,
113  exp
114FROM DisplayCompositorPresentationEvents
115WINDOW wnd AS (PARTITION BY exp ORDER BY ts);
116
117DROP TABLE IF EXISTS FrameSegmentsJoinInterestingSegments;
118CREATE VIRTUAL TABLE FrameSegmentsJoinInterestingSegments USING
119SPAN_JOIN(FrameSegments, InterestingSegments);
120
121DROP VIEW IF EXISTS FrameTimes;
122CREATE VIEW FrameTimes AS
123SELECT dur / 1e6 AS dur_ms, exp
124FROM FrameSegmentsJoinInterestingSegments
125WHERE ts = ts_fs AND dur = dur_fs;
126
127--------------------------------------------------------------------------------
128-- Determine frame rate
129
130DROP VIEW IF EXISTS RefreshPeriodAndroid;
131CREATE VIEW RefreshPeriodAndroid AS
132-- Not implemented yet.
133SELECT NULL AS interval_ms
134;
135
136DROP VIEW IF EXISTS RefreshPeriodNonAndroid;
137CREATE VIEW RefreshPeriodNonAndroid AS
138SELECT EXTRACT_ARG(arg_set_id, 'debug.args.interval_us') / 1e3 AS interval_ms
139FROM slice
140JOIN thread_track ON (slice.track_id = thread_track.id)
141JOIN thread ON (thread_track.utid = thread.utid)
142WHERE thread.name = 'Compositor' AND slice.name = 'Scheduler::BeginFrame'
143LIMIT 1;
144
145DROP VIEW IF EXISTS RefreshPeriodDefault;
146CREATE VIEW RefreshPeriodDefault AS
147SELECT 1000.0 / 60 AS interval_ms;
148
149DROP TABLE IF EXISTS RefreshPeriod;
150CREATE TABLE RefreshPeriod AS
151SELECT COALESCE(
152  (SELECT interval_ms FROM RefreshPeriodAndroid),
153  (SELECT interval_ms FROM RefreshPeriodNonAndroid),
154  (SELECT interval_ms FROM RefreshPeriodDefault)
155) AS interval_ms;
156
157--------------------------------------------------------------------------------
158-- Compute average FPS
159
160DROP VIEW IF EXISTS ValidFrameTimes;
161CREATE VIEW ValidFrameTimes AS
162SELECT
163  dur_ms / (SELECT interval_ms FROM RefreshPeriod) AS length,
164  exp
165FROM FrameTimes
166WHERE dur_ms / (SELECT interval_ms FROM RefreshPeriod) >= 0.5;
167
168DROP VIEW IF EXISTS AvgSurfaceFps;
169CREATE VIEW AvgSurfaceFps AS
170SELECT
171  exp,
172  1e3 * COUNT(*) / (SELECT SUM(dur_ms) FROM FrameTimes WHERE exp = valid.exp) AS fps
173FROM ValidFrameTimes valid
174GROUP BY exp;
175
176DROP VIEW IF EXISTS frame_times_output;
177CREATE VIEW frame_times_output AS
178SELECT FrameTimes(
179  'frame_time', (SELECT RepeatedField(dur_ms) FROM FrameTimes WHERE NOT exp),
180  'exp_frame_time', (SELECT RepeatedField(dur_ms) FROM FrameTimes WHERE exp),
181  'avg_surface_fps', (SELECT fps FROM AvgSurfaceFps WHERE NOT exp),
182  'exp_avg_surface_fps', (SELECT fps FROM AvgSurfaceFps WHERE exp)
183);
184
185