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 for uploading nanobench results.
7
8
9from recipe_engine import recipe_api
10
11
12class UploadNanoResultsApi(recipe_api.RecipeApi):
13  def run(self):
14    # Upload the nanobench resuls.
15    builder_name = self.m.properties['buildername']
16
17    now = self.m.time.utcnow()
18    src_path = self.m.path['start_dir'].join(
19        'perfdata', builder_name, 'data')
20    with self.m.step.context({'cwd': src_path}):
21      results = self.m.file.glob(
22          'find results',
23          src_path.join('*.json'),
24          test_data=[src_path.join('nanobench_abc123.json')],
25          infra_step=True)
26    if len(results) != 1:  # pragma: nocover
27      raise Exception('Unable to find nanobench or skpbench JSON file!')
28
29    src = results[0]
30    basename = self.m.path.basename(src)
31    gs_path = '/'.join((
32        'nano-json-v1', str(now.year).zfill(4),
33        str(now.month).zfill(2), str(now.day).zfill(2), str(now.hour).zfill(2),
34        builder_name))
35
36    issue = str(self.m.properties.get('issue', ''))
37    patchset = str(self.m.properties.get('patchset', ''))
38    if self.m.properties.get('patch_storage', '') == 'gerrit':
39      issue = str(self.m.properties['patch_issue'])
40      patchset = str(self.m.properties['patch_set'])
41    if issue and patchset:
42      gs_path = '/'.join(('trybot', gs_path, issue, patchset))
43
44    dst = '/'.join((
45        'gs://%s' % self.m.properties['gs_bucket'], gs_path, basename))
46
47    self.m.step(
48        'upload',
49        cmd=['gsutil', 'cp', '-z', 'json', src, dst],
50        infra_step=True)
51