refresh.dart 2.1 KB
Newer Older
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
// Copyright (c) 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.

import 'dart:async';
import 'dart:io';

import 'package:path/path.dart' as path;

import '../framework/adb.dart';
import '../framework/benchmarks.dart';
import '../framework/framework.dart';
import '../framework/utils.dart';

TaskFunction createRefreshTest({ String commit, DateTime timestamp }) =>
    new EditRefreshTask(commit, timestamp);

class EditRefreshTask {
  EditRefreshTask(this.commit, this.timestamp) {
    assert(commit != null);
    assert(timestamp != null);
  }

  final String commit;
  final DateTime timestamp;

  Future<TaskResult> call() async {
28
    Device device = await devices.workingDevice;
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
    await device.unlock();
    Benchmark benchmark = new EditRefreshBenchmark(commit, timestamp);
    section(benchmark.name);
    await runBenchmark(benchmark, iterations: 3, warmUpBenchmark: true);
    return benchmark.bestResult;
  }
}

class EditRefreshBenchmark extends Benchmark {
  EditRefreshBenchmark(this.commit, this.timestamp) : super('edit refresh');

  final String commit;
  final DateTime timestamp;

  Directory get megaDir => dir(
      path.join(flutterDirectory.path, 'dev/benchmarks/mega_gallery'));
  File get benchmarkFile =>
      file(path.join(megaDir.path, 'refresh_benchmark.json'));

  @override
  TaskResult get lastResult => new TaskResult.successFromFile(benchmarkFile);

  @override
  Future<Null> init() {
    return inDirectory(flutterDirectory, () async {
      await dart(<String>['dev/tools/mega_gallery.dart']);
    });
  }

  @override
  Future<num> run() async {
60
    Device device = await devices.workingDevice;
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
    rm(benchmarkFile);
    int exitCode = await inDirectory(megaDir, () async {
      return await flutter('run',
          options: <String>['-d', device.deviceId, '--benchmark'],
          canFail: true);
    });
    if (exitCode != 0) return new Future<num>.error(exitCode);
    return addBuildInfo(
      benchmarkFile,
      timestamp: timestamp,
      expected: 200,
      commit: commit,
    );
  }
}