• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2016 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
6# Recipe module for Skia Swarming perf.
7
8
9import calendar
10import json
11import os
12
13PYTHON_VERSION_COMPATIBILITY = "PY2+3"
14
15DEPS = [
16  'env',
17  'flavor',
18  'recipe_engine/file',
19  'recipe_engine/json',
20  'recipe_engine/path',
21  'recipe_engine/platform',
22  'recipe_engine/properties',
23  'recipe_engine/raw_io',
24  'recipe_engine/step',
25  'recipe_engine/time',
26  'run',
27  'vars',
28]
29
30
31def perf_steps(api):
32  """Run Skia benchmarks."""
33  do_upload = api.properties.get('do_upload') == 'true'
34  images = api.properties.get('images') == 'true'
35  resources = api.properties.get('resources') == 'true'
36  skps = api.properties.get('skps') == 'true'
37  svgs = api.properties.get('svgs') == 'true'
38  texttraces = api.properties.get('texttraces') == 'true'
39
40  api.flavor.install(
41      resources=resources,
42      skps=skps,
43      images=images,
44      svgs=svgs,
45      texttraces=texttraces,
46  )
47
48  if do_upload:
49    api.flavor.create_clean_device_dir(
50        api.flavor.device_dirs.perf_data_dir)
51
52  # Find nanobench flags.
53  args = json.loads(api.properties['nanobench_flags'])
54  props = json.loads(api.properties['nanobench_properties'])
55  swarming_bot_id = api.vars.swarming_bot_id
56  swarming_task_id = api.vars.swarming_task_id
57  if do_upload:
58    args.append('--properties')
59    # Map iteration order is arbitrary; in order to maintain a consistent step
60    # ordering, sort by key.
61    for k in sorted(props.keys()):
62      v = props[k]
63      if v == '${SWARMING_BOT_ID}':
64        v = swarming_bot_id
65      elif v == '${SWARMING_TASK_ID}':
66        v = swarming_task_id
67      if v != '':
68        args.extend([k, v])
69
70  # Paths to required resources.
71  if resources:
72    args.extend(['-i', api.flavor.device_dirs.resource_dir])
73  if skps:
74    args.extend(['--skps', api.flavor.device_dirs.skp_dir]),
75  if images:
76    args.extend(['--images', api.flavor.device_path_join(
77        api.flavor.device_dirs.images_dir, 'nanobench')])
78  if texttraces:
79    assert api.flavor.device_dirs.texttraces_dir
80    args.extend(['--texttraces', api.flavor.device_dirs.texttraces_dir])
81  if svgs:
82    args.extend(['--svgs',  api.flavor.device_dirs.svg_dir])
83  if do_upload:
84    now = api.time.utcnow()
85    ts = int(calendar.timegm(now.utctimetuple()))
86    json_path = api.flavor.device_path_join(
87        api.flavor.device_dirs.perf_data_dir,
88        'nanobench_%s_%d.json' % (api.properties['revision'], ts))
89    args.extend(['--outResultsFile', json_path])
90
91  api.run(api.flavor.step, 'nanobench', cmd=args,
92          abort_on_failure=False)
93
94  # Copy results to swarming out dir.
95  if do_upload:
96    api.file.ensure_directory(
97        'makedirs perf_dir',
98        api.flavor.host_dirs.perf_data_dir)
99    api.flavor.copy_directory_contents_to_host(
100        api.flavor.device_dirs.perf_data_dir,
101        api.flavor.host_dirs.perf_data_dir)
102
103
104def RunSteps(api):
105  api.vars.setup()
106  api.file.ensure_directory('makedirs tmp_dir', api.vars.tmp_dir)
107  api.flavor.setup('nanobench')
108
109  try:
110    perf_steps(api)
111  finally:
112    api.flavor.cleanup_steps()
113  api.run.check_failure()
114
115
116TEST_BUILDERS = [
117  'Perf-Android-Clang-Nexus7-CPU-Tegra3-arm-Debug-All-Android',
118  ('Perf-Ubuntu18-Clang-Golo-GPU-QuadroP400-x86_64-Release-All'
119   '-Valgrind_SK_CPU_LIMIT_SSE41'),
120  'Perf-Win10-Clang-Golo-GPU-QuadroP400-x86_64-Release-All-ANGLE',
121]
122
123
124def GenTests(api):
125  for builder in TEST_BUILDERS:
126    props = dict(
127      buildername=builder,
128      nanobench_flags='["nanobench","--example","--flags"]',
129      nanobench_properties=('{"key1":"value1","key2":"",'
130                            '"bot":"${SWARMING_BOT_ID}",'
131                            '"task":"${SWARMING_TASK_ID}"}'),
132      path_config='kitchen',
133      resources='true',
134      revision='abc123',
135      swarm_out_dir='[SWARM_OUT_DIR]'
136    )
137    if 'Valgrind' not in builder and 'Debug' not in builder:
138      props['do_upload'] = 'true'
139    if 'GPU' not in builder:
140      props['images'] = 'true'
141    if 'iOS' not in builder:
142      props['skps'] = 'true'
143    if 'Valgrind' not in builder:
144      props['svgs'] = 'true'
145    if 'Android' in builder and 'CPU' in builder:
146      props['texttraces'] = 'true'
147    test = (
148      api.test(builder) +
149      api.properties(**props) +
150      api.path.exists(
151          api.path['start_dir'].join('skia'),
152          api.path['start_dir'].join('skia', 'infra', 'bots', 'assets',
153                                     'skimage', 'VERSION'),
154          api.path['start_dir'].join('skia', 'infra', 'bots', 'assets',
155                                     'skp', 'VERSION'),
156          api.path['start_dir'].join('tmp', 'uninteresting_hashes.txt')
157      ) +
158      api.step_data('get swarming bot id',
159          stdout=api.raw_io.output('skia-bot-123')) +
160      api.step_data('get swarming task id',
161          stdout=api.raw_io.output('123456'))
162    )
163    if 'Win' in builder:
164      test += api.platform('win', 64)
165
166    yield test
167