File: bulk-download.js

package info (click to toggle)
chromium 120.0.6099.224-1~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,112,112 kB
  • sloc: cpp: 32,907,025; ansic: 8,148,123; javascript: 3,679,536; python: 2,031,248; asm: 959,718; java: 804,675; xml: 617,256; sh: 111,417; objc: 100,835; perl: 88,443; cs: 53,032; makefile: 29,579; fortran: 24,137; php: 21,162; tcl: 21,147; sql: 20,809; ruby: 17,735; pascal: 12,864; yacc: 8,045; lisp: 3,388; lex: 1,323; ada: 727; awk: 329; jsp: 267; csh: 117; exp: 43; sed: 37
file content (129 lines) | stat: -rw-r--r-- 3,843 bytes parent folder | download | duplicates (4)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

'use strict';

const bulider = require('./builder.js');
const gsutil = require('./gsutil.js');
const tryrequire = require('./try-require.js');

const fs = require('fs');
const yargs = tryrequire.tryrequire('yargs');
if (!yargs) {
  console.error('Please install the `yargs` package from npm (`npm i yargs`).');
  return;
}

function printUpdate(msg) {
  console.log('*** ' + msg);
}

async function main() {
  if (!gsutil.exists()) {
    console.error('Command `gsutil` (used to download the files) not found.');
    console.error('You may need to install `google-cloud-sdk` package.');
    return;
  }

  const argv =
      yargs
          .option('benchmark', {
            alias: 'b',
            description: 'The benchmark to download traces for.',
            type: 'string'
          })
          .option('output', {
            alias: 'o',
            description: 'The output location for the downloaded trace files.',
            type: 'string'
          })
          .usage('Usage: $0 -b <benchmark> -o <download-path> <build-url>')
          .example(
              '$0 -b rendering.mobile -o /tmp/foo https://ci.chromium.org/ui/p/chrome/builders/ci/android-pixel2_webview-perf/24015/overview')
          .wrap(null)
          .argv;

  if (!argv.benchmark) {
    console.error('Please specify the name of a benchmark (using -b).');
    return;
  }

  if (!argv.output) {
    console.error(
        'Please specify the location to download the files to (using -o).');
    return;
  }

  if (!fs.existsSync(argv.output)) {
    console.error(`Create output location (${argv.output}) first.`);
    return;
  }

  const builder = new bulider.Build(argv._[0]);
  const task = builder.findSwarmingTask();
  printUpdate(
      `Found swarming task ${task.task_id}. Looking for child tasks ... `);
  const children = task.findChildTasks();
  printUpdate(`Found ${children.length} child tasks.`);

  const all = {};
  const promises = [];
  let taskno = 0;
  for (const child of children) {
    const p = child.downloadJSONFile('output.json');
    promises.push(p);

    p.then((output) => {
      if (argv.benchmark in output.tests) {
        const tests = Object.keys(output.tests[argv.benchmark]);
        printUpdate(
            `${++taskno}/${children.length} ${tests.length} tests found for ${
                argv.benchmark} in ${child.task_id}.`);
        for (const t of tests) {
          const artifacts = output.tests[argv.benchmark][t].artifacts;
          if (artifacts && artifacts['trace.html']) {
            const trace = artifacts['trace.html'];
            const url = (typeof (trace) === 'object' &&
                         typeof (trace[0]) === 'string') ?
                trace[0] :
                trace;
            if (t in all) {
              all[t].push(url);
            } else {
              all[t] = [url];
            }
          }
        }
      } else {
        printUpdate(`${++taskno}/${children.length} 0 tests found for ${
            argv.benchmark} in ${child.task_id}.`);
      }
    });
  }
  await Promise.all(promises);

  // Maps a gs:// url to a local filename.
  const map = {};
  const names = Object.keys(all);
  while (names.length > 0) {
    const orig = names.shift();
    const name = orig.replace('/', '_').replace('\.', '_');
    const urls = all[orig];
    if (urls.length === 1) {
      map[urls[0]] = name + '.html';
    } else {
      for (let i = 0; i < urls.length; ++i) {
        map[urls[i]] = `${name}_${i}.html`;
      }
    }
  }

  const total = Object.keys(map).length;
  printUpdate(`There are ${total} files to download.`);

  await gsutil.downloadFiles(map, argv.output);
  process.stdout.write('\nDone.\n');
}

main();