File: speedometer_2_1.sql

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (245 lines) | stat: -rw-r--r-- 7,722 bytes parent folder | download | duplicates (10)
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
-- Copyright 2024 The Chromium Authors
-- Use of this source code is governed by a BSD-style license that can be
-- found in the LICENSE file.

-- List Speedometer 2.1 test marks. Used to find relevant slices.
CREATE PERFETTO VIEW _chrome_speedometer_2_1_mark_name (
  -- Expected slice name
  name STRING,
  -- Suite name
  suite_name STRING,
  -- Test name
  test_name STRING,
  -- Mark type
  mark_type STRING
) AS
WITH
  data(suite_name, test_name) AS (
    SELECT
      *
    FROM (VALUES
      ('Angular2-TypeScript-TodoMVC', 'Adding100Items'),
      ('Angular2-TypeScript-TodoMVC', 'CompletingAllItems'),
      ('Angular2-TypeScript-TodoMVC', 'DeletingItems'),
      ('AngularJS-TodoMVC', 'Adding100Items'),
      ('AngularJS-TodoMVC', 'CompletingAllItems'),
      ('AngularJS-TodoMVC', 'DeletingAllItems'),
      ('BackboneJS-TodoMVC', 'Adding100Items'),
      ('BackboneJS-TodoMVC', 'CompletingAllItems'),
      ('BackboneJS-TodoMVC', 'DeletingAllItems'),
      ('Elm-TodoMVC', 'Adding100Items'),
      ('Elm-TodoMVC', 'CompletingAllItems'),
      ('Elm-TodoMVC', 'DeletingItems'),
      ('EmberJS-Debug-TodoMVC', 'Adding100Items'),
      ('EmberJS-Debug-TodoMVC', 'CompletingAllItems'),
      ('EmberJS-Debug-TodoMVC', 'DeletingItems'),
      ('EmberJS-TodoMVC', 'Adding100Items'),
      ('EmberJS-TodoMVC', 'CompletingAllItems'),
      ('EmberJS-TodoMVC', 'DeletingItems'),
      ('Flight-TodoMVC', 'Adding100Items'),
      ('Flight-TodoMVC', 'CompletingAllItems'),
      ('Flight-TodoMVC', 'DeletingItems'),
      ('Inferno-TodoMVC', 'Adding100Items'),
      ('Inferno-TodoMVC', 'CompletingAllItems'),
      ('Inferno-TodoMVC', 'DeletingItems'),
      ('Preact-TodoMVC', 'Adding100Items'),
      ('Preact-TodoMVC', 'CompletingAllItems'),
      ('Preact-TodoMVC', 'DeletingItems'),
      ('React-Redux-TodoMVC', 'Adding100Items'),
      ('React-Redux-TodoMVC', 'CompletingAllItems'),
      ('React-Redux-TodoMVC', 'DeletingItems'),
      ('React-TodoMVC', 'Adding100Items'),
      ('React-TodoMVC', 'CompletingAllItems'),
      ('React-TodoMVC', 'DeletingAllItems'),
      ('Vanilla-ES2015-Babel-Webpack-TodoMVC', 'Adding100Items'),
      ('Vanilla-ES2015-Babel-Webpack-TodoMVC', 'CompletingAllItems'),
      ('Vanilla-ES2015-Babel-Webpack-TodoMVC', 'DeletingItems'),
      ('Vanilla-ES2015-TodoMVC', 'Adding100Items'),
      ('Vanilla-ES2015-TodoMVC', 'CompletingAllItems'),
      ('Vanilla-ES2015-TodoMVC', 'DeletingItems'),
      ('VanillaJS-TodoMVC', 'Adding100Items'),
      ('VanillaJS-TodoMVC', 'CompletingAllItems'),
      ('VanillaJS-TodoMVC', 'DeletingAllItems'),
      ('VueJS-TodoMVC', 'Adding100Items'),
      ('VueJS-TodoMVC', 'CompletingAllItems'),
      ('VueJS-TodoMVC', 'DeletingAllItems'),
      ('jQuery-TodoMVC', 'Adding100Items'),
      ('jQuery-TodoMVC', 'CompletingAllItems'),
      ('jQuery-TodoMVC', 'DeletingAllItems')) AS _values
  ),
  mark_type(mark_type) AS (
    SELECT
      *
    FROM (VALUES
      ('start'),
      ('sync-end'),
      ('async-end')) AS _values
  )
SELECT
  suite_name || '.' || test_name || '-' || mark_type AS name,
  suite_name,
  test_name,
  mark_type
FROM data, mark_type;

-- Augmented slices for Speedometer measurements.
-- These are the intervals of time Speedometer uses to compute the final score.
-- There are two intervals that are measured for every test: sync and async
-- sync is the time between the start and sync-end marks, async is the time
-- between the sync-end and async-end marks.
CREATE PERFETTO TABLE chrome_speedometer_2_1_measure (
  -- Start timestamp of the measure slice
  ts TIMESTAMP,
  -- Duration of the measure slice
  dur DURATION,
  -- Full measure name
  name STRING,
  -- Speedometer iteration the slice belongs to.
  iteration LONG,
  -- Suite name
  suite_name STRING,
  -- Test name
  test_name STRING,
  -- Type of the measure (sync or async)
  measure_type STRING
) AS
WITH
  mark AS (
    SELECT
      s.id AS slice_id,
      rank() OVER (PARTITION BY name ORDER BY ts ASC) AS iteration,
      m.suite_name,
      m.test_name,
      m.mark_type
    -- Join with _chrome_speedometer_2_1_mark_name to look only at slices with expected names.
    FROM slice AS s
    JOIN _chrome_speedometer_2_1_mark_name AS m
      USING (name)
    WHERE
      category = 'blink.user_timing'
  ),
  -- Get the 3 test timestamps (start, sync-end, async-end) in one row. Using a
  -- the LAG window function and partitioning by test. 2 out of the 3 rows
  -- generated per test will have some NULL ts values.
  augmented AS (
    SELECT
      iteration,
      suite_name,
      test_name,
      ts AS async_end_ts,
      lag(ts, 1) OVER (PARTITION BY iteration, suite_name, test_name ORDER BY ts ASC) AS sync_end_ts,
      lag(ts, 2) OVER (PARTITION BY iteration, suite_name, test_name ORDER BY ts ASC) AS start_ts,
      count() OVER (PARTITION BY iteration, suite_name, test_name ORDER BY ts ASC) AS mark_count
    FROM mark
    JOIN slice
      USING (slice_id)
  ),
  filtered AS (
    SELECT
      *
    FROM augmented
    -- This server 2 purposes: make sure we have all the marks (think truncated
    -- trace), and remove the NULL ts values due to the LAG window function.
    WHERE
      mark_count = 3
  ),
  base AS (
    SELECT
      sync_end_ts AS ts,
      async_end_ts - sync_end_ts AS dur,
      iteration,
      suite_name,
      test_name,
      'async' AS measure_type
    FROM filtered
    UNION ALL
    SELECT
      start_ts AS ts,
      sync_end_ts - start_ts AS dur,
      iteration,
      suite_name,
      test_name,
      'sync' AS measure_type
    FROM filtered
  )
SELECT
  ts,
  dur,
  suite_name || '.' || test_name || '-' || measure_type AS name,
  iteration,
  suite_name,
  test_name,
  measure_type
FROM base;

-- Slice that covers one Speedometer iteration.
-- This slice is actually estimated as a default Speedometer run will not emit
-- marks to cover this interval. The metrics associated are the same ones
-- Speedometer would output, but note we use ns precision (Speedometer uses
-- ~100us) so the actual values might differ a bit. Also note Speedometer
-- returns the values in ms these here and in ns.
CREATE PERFETTO TABLE chrome_speedometer_2_1_iteration (
  -- Start timestamp of the iteration
  ts TIMESTAMP,
  -- Duration of the iteration
  dur DURATION,
  -- Iteration name
  name STRING,
  -- Iteration number
  iteration LONG,
  -- Geometric mean of the suite durations for this iteration.
  geomean DOUBLE,
  -- Speedometer score for this iteration (The total score for a run in the
  -- average of all iteration scores).
  score DOUBLE
) AS
SELECT
  min(start) AS ts,
  max(end) - min(start) AS dur,
  'iteration-' || iteration AS name,
  iteration,
  -- Compute geometric mean using LN instead of multiplication to prevent
  -- overflows
  exp(avg(ln(suite_total))) AS geomean,
  1000 / exp(avg(ln(suite_total))) * 60 / 3 AS score
FROM (
  SELECT
    iteration,
    sum(dur / (
      1000.0 * 1000.0
    )) AS suite_total,
    min(ts) AS start,
    max(ts + dur) AS end
  FROM chrome_speedometer_2_1_measure
  GROUP BY
    suite_name,
    iteration
)
GROUP BY
  iteration;

-- Returns the Speedometer 2.1 score for all iterations in the trace
CREATE PERFETTO FUNCTION chrome_speedometer_2_1_score()
-- Speedometer 2.1 score
RETURNS DOUBLE AS
SELECT
  avg(score)
FROM chrome_speedometer_2_1_iteration;

-- Returns the utid for the main thread that ran Speedometer 2.1
CREATE PERFETTO FUNCTION chrome_speedometer_2_1_renderer_main_utid()
-- Renderer main utid
RETURNS LONG AS
SELECT
  utid
FROM thread_track
WHERE
  id IN (
    SELECT
      track_id
    FROM slice
    JOIN _chrome_speedometer_2_1_mark_name
      USING (name)
    WHERE
      category = 'blink.user_timing'
  );