aboutsummaryrefslogtreecommitdiffhomepage
path: root/infra/bots/recipe_modules/upload_nano_results/api.py
blob: aabfdc6db871fc0aeec22e79a96f373ea474e627 (plain)
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
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.


# Recipe for uploading nanobench results.


from recipe_engine import recipe_api


class UploadNanoResultsApi(recipe_api.RecipeApi):
  def run(self):
    # Upload the nanobench resuls.
    builder_name = self.m.properties['buildername']

    now = self.m.time.utcnow()
    src_path = self.m.path['start_dir'].join(
        'perfdata', builder_name, 'data')
    with self.m.step.context({'cwd': src_path}):
      results = self.m.file.glob(
          'find results',
          src_path.join('*.json'),
          test_data=[src_path.join('nanobench_abc123.json')],
          infra_step=True)
    if len(results) != 1:  # pragma: nocover
      raise Exception('Unable to find nanobench or skpbench JSON file!')

    src = results[0]
    basename = self.m.path.basename(src)
    gs_path = '/'.join((
        'nano-json-v1', str(now.year).zfill(4),
        str(now.month).zfill(2), str(now.day).zfill(2), str(now.hour).zfill(2),
        builder_name))

    issue = str(self.m.properties.get('issue', ''))
    patchset = str(self.m.properties.get('patchset', ''))
    if self.m.properties.get('patch_storage', '') == 'gerrit':
      issue = str(self.m.properties['patch_issue'])
      patchset = str(self.m.properties['patch_set'])
    if issue and patchset:
      gs_path = '/'.join(('trybot', gs_path, issue, patchset))

    dst = '/'.join((
        'gs://%s' % self.m.properties['gs_bucket'], gs_path, basename))

    self.m.step(
        'upload',
        cmd=['gsutil', 'cp', '-z', 'json', src, dst],
        infra_step=True)