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 skpbench.
7
8
9import calendar
10
11from recipe_engine import recipe_api
12
13
14def _run(api, title, *cmd, **kwargs):
15  with api.step.context({'cwd': api.vars.skia_dir}):
16    return api.run(api.step, title, cmd=list(cmd), **kwargs)
17
18
19def _adb(api, title, *cmd, **kwargs):
20  if 'infra_step' not in kwargs:
21    kwargs['infra_step'] = True
22  return _run(api, title, 'adb', *cmd, **kwargs)
23
24
25def skpbench_steps(api):
26  """benchmark Skia using skpbench."""
27  app = api.vars.skia_out.join(api.vars.configuration, 'skpbench')
28  _adb(api, 'push skpbench', 'push', app, api.vars.android_bin_dir)
29
30  skpbench_dir = api.vars.slave_dir.join('skia', 'tools', 'skpbench')
31  table = api.path.join(api.vars.swarming_out_dir, 'table')
32
33  config = 'gles,glesinst4'
34  if 'Vulkan' in api.vars.builder_name:
35    config = 'vk'
36
37  skpbench_args = [
38        api.path.join(api.vars.android_bin_dir, 'skpbench'),
39        api.path.join(api.vars.android_data_dir, 'skps'),
40        '--adb',
41        '--resultsfile', table,
42        '--config', config]
43
44  api.run(api.python, 'skpbench',
45      script=skpbench_dir.join('skpbench.py'),
46      args=skpbench_args)
47
48  skiaperf_args = [
49    table,
50    '--properties',
51    'gitHash',      api.vars.got_revision,
52    'build_number', api.vars.build_number,
53  ]
54
55  skiaperf_args.extend(['no_buildbot', 'True'])
56  skiaperf_args.extend(['swarming_bot_id', api.vars.swarming_bot_id])
57  skiaperf_args.extend(['swarming_task_id', api.vars.swarming_task_id])
58
59  now = api.time.utcnow()
60  ts = int(calendar.timegm(now.utctimetuple()))
61  api.file.makedirs('perf_dir', api.vars.perf_data_dir)
62  json_path = api.path.join(
63      api.vars.perf_data_dir,
64      'skpbench_%s_%d.json' % (api.vars.got_revision, ts))
65
66  skiaperf_args.extend([
67    '--outfile', json_path
68  ])
69
70  keys_blacklist = ['configuration', 'role', 'is_trybot']
71  skiaperf_args.append('--key')
72  for k in sorted(api.vars.builder_cfg.keys()):
73    if not k in keys_blacklist:
74      skiaperf_args.extend([k, api.vars.builder_cfg[k]])
75
76  api.run(api.python, 'Parse skpbench output into Perf json',
77      script=skpbench_dir.join('skiaperf.py'),
78      args=skiaperf_args)
79
80
81class SkpBenchApi(recipe_api.RecipeApi):
82  def run(self):
83    self.m.core.setup()
84    try:
85      self.m.flavor.install(skps=True)
86      skpbench_steps(self.m)
87    finally:
88      self.m.flavor.cleanup_steps()
89    self.m.run.check_failure()
90