Debian Codegraph @

infra/bots/recipes/perf_skottiewasm_lottieweb.py

raw
1 # Copyright 2019 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 # Recipe which runs Skottie-WASM and Lottie-Web perf.
6
7 import calendar
8 import json
9 import re
10
11
12 # trim
13 DEPS = [
14 'flavor',
15 'checkout',
16 'env',
17 'infra',
18 'recipe_engine/context',
19 'recipe_engine/file',
20 'recipe_engine/json',
21 'recipe_engine/path',
22 'recipe_engine/properties',
23 'recipe_engine/step',
24 'recipe_engine/time',
25 'run',
26 'vars',
27 ]
28
29 LOTTIE_WEB_EXCLUDE = [
30 # See https://bugs.chromium.org/p/skia/issues/detail?id=9187#c4
31 'lottiefiles.com - Progress Success.json',
32 # Fails with "val2 is not defined".
33 'lottiefiles.com - VR.json',
34 'vr_animation.json',
35 # Times out.
36 'lottiefiles.com - Nudge.json',
37 'lottiefiles.com - Retweet.json',
38 'regress-perspective-blur-01.json',
39 'regress-perspective-blur-02.json',
40 # Trace file has majority main_frame_aborted terminations in it and < 25
41 # occurrences of submitted_frame + missed_frame.
42 # Static scenes (nothing animating)
43 'mask1.json',
44 'mask2.json',
45 'stacking.json',
46 ]
47
48 SKOTTIE_WASM_EXCLUDE = [
49 # Trace file has majority main_frame_aborted terminations in it and < 25
50 # occurrences of submitted_frame + missed_frame.
51 # Below descriptions are added from fmalita@'s comments in
52 # https://skia-review.googlesource.com/c/skia/+/229419
53
54 # Static scenes (nothing animating)
55 'mask1.json',
56 'mask2.json',
57 'stacking.json',
58 # Static in Skottie only due to unsupported feature (expressions).
59 'dna.json',
60 'elephant_trunk_swing.json',
61 # Looks all static in both skottie/lottie, not sure why lottie doesn't abort
62 # as many frames.
63 'hexadots.json',
64 # Very short transition, mostly static.
65 'screenhole.json',
66 # Broken in Skottie due to unidentified missing feature.
67 'interleague_golf_logo.json',
68 'loading.json',
69 'lottiefiles.com - Loading 2.json',
70 'streetby_loading.json',
71 'streetby_test_loading.json',
72 # Times out
73 'beetle.json',
74 # Too slow? Doesn't provide enough frames for analysis b/325452373
75 'Name.json',
76 ]
77
78 # These files work in SVG but not in Canvas.
79 LOTTIE_WEB_CANVAS_EXCLUDE = LOTTIE_WEB_EXCLUDE + [
80 'Hello World.json',
81 'interactive_menu.json',
82 'Name.json',
83 ]
84
85
86 def RunSteps(api):
87 api.vars.setup()
88 api.flavor.setup(None)
89 checkout_root = api.path.start_dir
90 buildername = api.properties['buildername']
91 node_path = api.path.start_dir.joinpath('node', 'node', 'bin', 'node')
92 lottie_files = api.file.listdir(
93 'list lottie files', api.flavor.host_dirs.lotties_dir,
94 test_data=['lottie1.json', 'lottie2.json', 'lottie3.json', 'LICENSE'])
95
96 if 'SkottieWASM' in buildername:
97 source_type = 'skottie'
98 renderer = 'skottie-wasm'
99
100 perf_app_dir = checkout_root.joinpath('skia', 'tools', 'skottie-wasm-perf')
101 canvaskit_js_path = api.vars.build_dir.joinpath('canvaskit.js')
102 canvaskit_wasm_path = api.vars.build_dir.joinpath('canvaskit.wasm')
103 skottie_wasm_js_path = perf_app_dir.joinpath('skottie-wasm-perf.js')
104 perf_app_cmd = [
105 node_path, skottie_wasm_js_path,
106 '--canvaskit_js', canvaskit_js_path,
107 '--canvaskit_wasm', canvaskit_wasm_path,
108 ]
109 lottie_files = [x for x in lottie_files
110 if api.path.basename(x) not in SKOTTIE_WASM_EXCLUDE]
111 elif 'LottieWeb' in buildername:
112 source_type = 'lottie-web'
113 renderer = 'lottie-web'
114 if 'Canvas' in buildername:
115 backend = 'canvas'
116 lottie_files = [
117 x for x in lottie_files
118 if api.path.basename(x) not in LOTTIE_WEB_CANVAS_EXCLUDE]
119 else:
120 backend = 'svg'
121 lottie_files = [x for x in lottie_files
122 if api.path.basename(x) not in LOTTIE_WEB_EXCLUDE]
123
124 perf_app_dir = checkout_root.joinpath('skia', 'tools', 'lottie-web-perf')
125 lottie_web_js_path = perf_app_dir.joinpath('lottie-web-perf.js')
126 perf_app_cmd = [
127 node_path, lottie_web_js_path,
128 '--backend', backend,
129 ]
130 else:
131 raise Exception('Could not recognize the buildername %s' % buildername)
132
133 if api.vars.builder_cfg.get('cpu_or_gpu') == 'GPU':
134 perf_app_cmd.append('--use_gpu')
135
136 # Install prerequisites.
137 env_prefixes = {'PATH': [api.path.start_dir.joinpath('node', 'node', 'bin')]}
138 with api.context(cwd=perf_app_dir, env_prefixes=env_prefixes):
139 api.step('npm install', cmd=['npm', 'install'])
140
141 perf_results = {}
142 output_dir = api.path.mkdtemp('g3_try')
143 # Run the perf_app_cmd on each lottie file and parse the trace files.
144 for _, lottie_file in enumerate(lottie_files):
145 lottie_filename = api.path.basename(lottie_file)
146 if not lottie_filename.endswith('.json'):
147 continue
148 output_file = output_dir.joinpath(lottie_filename)
149 with api.context(cwd=perf_app_dir, env={'DISPLAY': ':0'}):
150 # This is occasionally flaky due to skbug.com/40040508, adding retries.
151 attempts = 3
152 # Add output and input arguments to the cmd.
153 api.run.with_retry(api.step, 'Run perf cmd line app', attempts,
154 cmd=perf_app_cmd + [
155 '--input', lottie_file,
156 '--output', output_file,
157 ], infra_step=True)
158
159 perf_results[lottie_filename] = {
160 'gl': parse_trace(output_file, lottie_filename, api, renderer),
161 }
162
163 # Construct contents of the output JSON.
164 perf_json = {
165 'gitHash': api.properties['revision'],
166 'swarming_bot_id': api.vars.swarming_bot_id,
167 'swarming_task_id': api.vars.swarming_task_id,
168 'key': {
169 'bench_type': 'tracing',
170 'source_type': source_type,
171 },
172 'renderer': renderer,
173 'results': perf_results,
174 }
175 if api.vars.is_trybot:
176 perf_json['issue'] = api.vars.issue
177 perf_json['patchset'] = api.vars.patchset
178 perf_json['patch_storage'] = api.vars.patch_storage
179 # Add tokens from the builder name to the key.
180 reg = re.compile('Perf-(?P<os>[A-Za-z0-9_]+)-'
181 '(?P<compiler>[A-Za-z0-9_]+)-'
182 '(?P<model>[A-Za-z0-9_]+)-'
183 '(?P<cpu_or_gpu>[A-Z]+)-'
184 '(?P<cpu_or_gpu_value>[A-Za-z0-9_]+)-'
185 '(?P<arch>[A-Za-z0-9_]+)-'
186 '(?P<configuration>[A-Za-z0-9_]+)-'
187 'All(-(?P<extra_config>[A-Za-z0-9_]+)|)')
188 m = reg.match(api.properties['buildername'])
189 keys = ['os', 'compiler', 'model', 'cpu_or_gpu', 'cpu_or_gpu_value', 'arch',
190 'configuration', 'extra_config']
191 for k in keys:
192 perf_json['key'][k] = m.group(k)
193
194 # Create the output JSON file in perf_data_dir for the Upload task to upload.
195 api.file.ensure_directory(
196 'makedirs perf_dir',
197 api.flavor.host_dirs.perf_data_dir)
198 now = api.time.utcnow()
199 ts = int(calendar.timegm(now.utctimetuple()))
200 json_path = api.flavor.host_dirs.perf_data_dir.joinpath(
201 'perf_%s_%d.json' % (api.properties['revision'], ts))
202 json_contents = json.dumps(
203 perf_json, indent=4, sort_keys=True, separators=(',', ': '))
204 api.file.write_text('write output JSON', json_path, json_contents)
205
206
207 def parse_trace(trace_json, lottie_filename, api, renderer):
208 """parse_trace parses the specified trace JSON.
209
210 Parses the trace JSON and calculates the time of a single frame.
211 A dictionary is returned that has the following structure:
212 {
213 'frame_max_us': 100,
214 'frame_min_us': 90,
215 'frame_avg_us': 95,
216 }
217 """
218 script = api.infra.resource('parse_lottieweb_trace.py')
219 step_result = api.run(
220 api.step,
221 'parse %s trace' % lottie_filename,
222 cmd=['python3', script, trace_json, api.json.output(), renderer])
223
224 # Sanitize float outputs to 2 precision points.
225 output = dict(step_result.json.output)
226 output['frame_max_us'] = float("%.2f" % output['frame_max_us'])
227 output['frame_min_us'] = float("%.2f" % output['frame_min_us'])
228 output['frame_avg_us'] = float("%.2f" % output['frame_avg_us'])
229 return output
230
231
232 def GenTests(api):
233 trace_output = """
234 [{"ph":"X","name":"void skottie::Animation::seek(SkScalar)","ts":452,"dur":2.57,"tid":1,"pid":0},{"ph":"X","name":"void SkCanvas::drawPaint(const SkPaint &)","ts":473,"dur":2.67e+03,"tid":1,"pid":0},{"ph":"X","name":"void skottie::Animation::seek(SkScalar)","ts":3.15e+03,"dur":2.25,"tid":1,"pid":0},{"ph":"X","name":"void skottie::Animation::render(SkCanvas *, const SkRect *, RenderFlags) const","ts":3.15e+03,"dur":216,"tid":1,"pid":0},{"ph":"X","name":"void SkCanvas::drawPath(const SkPath &, const SkPaint &)","ts":3.35e+03,"dur":15.1,"tid":1,"pid":0},{"ph":"X","name":"void skottie::Animation::seek(SkScalar)","ts":3.37e+03,"dur":1.17,"tid":1,"pid":0},{"ph":"X","name":"void skottie::Animation::render(SkCanvas *, const SkRect *, RenderFlags) const","ts":3.37e+03,"dur":140,"tid":1,"pid":0}]
235 """
236 parse_trace_json = {
237 'frame_avg_us': 179.71,
238 'frame_min_us': 141.17,
239 'frame_max_us': 218.25
240 }
241
242
243 skottie_cpu_buildername = ('Perf-Debian10-EMCC-GCE-CPU-AVX2-wasm-Release-All-'
244 'SkottieWASM')
245 yield (
246 api.test('skottie_wasm_perf') +
247 api.properties(buildername=skottie_cpu_buildername,
248 repository='https://skia.googlesource.com/skia.git',
249 revision='abc123',
250 path_config='kitchen',
251 trace_test_data=trace_output,
252 swarm_out_dir='[SWARM_OUT_DIR]') +
253 api.step_data('parse lottie1.json trace',
254 api.json.output(parse_trace_json)) +
255 api.step_data('parse lottie2.json trace',
256 api.json.output(parse_trace_json)) +
257 api.step_data('parse lottie3.json trace',
258 api.json.output(parse_trace_json))
259 )
260 yield (
261 api.test('skottie_wasm_perf_trybot') +
262 api.properties(buildername=skottie_cpu_buildername,
263 repository='https://skia.googlesource.com/skia.git',
264 revision='abc123',
265 path_config='kitchen',
266 trace_test_data=trace_output,
267 swarm_out_dir='[SWARM_OUT_DIR]',
268 patch_ref='89/456789/12',
269 patch_repo='https://skia.googlesource.com/skia.git',
270 patch_storage='gerrit',
271 patch_set=7,
272 patch_issue=1234,
273 gerrit_project='skia',
274 gerrit_url='https://skia-review.googlesource.com/') +
275 api.step_data('parse lottie1.json trace',
276 api.json.output(parse_trace_json)) +
277 api.step_data('parse lottie2.json trace',
278 api.json.output(parse_trace_json)) +
279 api.step_data('parse lottie3.json trace',
280 api.json.output(parse_trace_json))
281 )
282
283 skottie_gpu_buildername = ('Perf-Debian10-EMCC-NUC7i5BNK-GPU-IntelIris640-'
284 'wasm-Release-All-SkottieWASM')
285 yield (
286 api.test('skottie_wasm_perf_gpu') +
287 api.properties(buildername=skottie_gpu_buildername,
288 repository='https://skia.googlesource.com/skia.git',
289 revision='abc123',
290 path_config='kitchen',
291 trace_test_data=trace_output,
292 swarm_out_dir='[SWARM_OUT_DIR]') +
293 api.step_data('parse lottie1.json trace',
294 api.json.output(parse_trace_json)) +
295 api.step_data('parse lottie2.json trace',
296 api.json.output(parse_trace_json)) +
297 api.step_data('parse lottie3.json trace',
298 api.json.output(parse_trace_json))
299 )
300
301 lottieweb_cpu_buildername = ('Perf-Debian10-none-GCE-CPU-AVX2-x86_64-Release-'
302 'All-LottieWeb')
303 yield (
304 api.test('lottie_web_perf') +
305 api.properties(buildername=lottieweb_cpu_buildername,
306 repository='https://skia.googlesource.com/skia.git',
307 revision='abc123',
308 path_config='kitchen',
309 trace_test_data=trace_output,
310 swarm_out_dir='[SWARM_OUT_DIR]') +
311 api.step_data('parse lottie1.json trace',
312 api.json.output(parse_trace_json)) +
313 api.step_data('parse lottie2.json trace',
314 api.json.output(parse_trace_json)) +
315 api.step_data('parse lottie3.json trace',
316 api.json.output(parse_trace_json))
317 )
318 yield (
319 api.test('lottie_web_perf_trybot') +
320 api.properties(buildername=lottieweb_cpu_buildername,
321 repository='https://skia.googlesource.com/skia.git',
322 revision='abc123',
323 path_config='kitchen',
324 trace_test_data=trace_output,
325 swarm_out_dir='[SWARM_OUT_DIR]',
326 patch_ref='89/456789/12',
327 patch_repo='https://skia.googlesource.com/skia.git',
328 patch_storage='gerrit',
329 patch_set=7,
330 patch_issue=1234,
331 gerrit_project='skia',
332 gerrit_url='https://skia-review.googlesource.com/') +
333 api.step_data('parse lottie1.json trace',
334 api.json.output(parse_trace_json)) +
335 api.step_data('parse lottie2.json trace',
336 api.json.output(parse_trace_json)) +
337 api.step_data('parse lottie3.json trace',
338 api.json.output(parse_trace_json))
339 )
340
341 lottieweb_canvas_cpu_buildername = (
342 'Perf-Debian10-none-GCE-CPU-AVX2-x86_64-Release-All-LottieWeb_Canvas')
343 yield (
344 api.test('lottie_web_canvas_perf') +
345 api.properties(buildername=lottieweb_canvas_cpu_buildername,
346 repository='https://skia.googlesource.com/skia.git',
347 revision='abc123',
348 path_config='kitchen',
349 trace_test_data=trace_output,
350 swarm_out_dir='[SWARM_OUT_DIR]') +
351 api.step_data('parse lottie1.json trace',
352 api.json.output(parse_trace_json)) +
353 api.step_data('parse lottie2.json trace',
354 api.json.output(parse_trace_json)) +
355 api.step_data('parse lottie3.json trace',
356 api.json.output(parse_trace_json))
357 )
358 yield (
359 api.test('lottie_web_canvas_perf_trybot') +
360 api.properties(buildername=lottieweb_canvas_cpu_buildername,
361 repository='https://skia.googlesource.com/skia.git',
362 revision='abc123',
363 path_config='kitchen',
364 trace_test_data=trace_output,
365 swarm_out_dir='[SWARM_OUT_DIR]',
366 patch_ref='89/456789/12',
367 patch_repo='https://skia.googlesource.com/skia.git',
368 patch_storage='gerrit',
369 patch_set=7,
370 patch_issue=1234,
371 gerrit_project='skia',
372 gerrit_url='https://skia-review.googlesource.com/') +
373 api.step_data('parse lottie1.json trace',
374 api.json.output(parse_trace_json)) +
375 api.step_data('parse lottie2.json trace',
376 api.json.output(parse_trace_json)) +
377 api.step_data('parse lottie3.json trace',
378 api.json.output(parse_trace_json))
379 )
380
381 unrecognized_buildername = ('Perf-Debian10-none-GCE-CPU-AVX2-x86_64-Release-'
382 'All-Unrecognized')
383 yield (
384 api.test('unrecognized_builder') +
385 api.properties(buildername=unrecognized_buildername,
386 repository='https://skia.googlesource.com/skia.git',
387 revision='abc123',
388 path_config='kitchen',
389 swarm_out_dir='[SWARM_OUT_DIR]') +
390 api.expect_exception('Exception')
391 )