microbenchmarks.dart 3.01 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6 7
// 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';

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

10 11 12 13 14 15
import '../framework/devices.dart';
import '../framework/framework.dart';
import '../framework/task_result.dart';
import '../framework/utils.dart';
import '../microbenchmarks.dart';

16 17 18 19
/// Creates a device lab task that runs benchmarks in
/// `dev/benchmarks/microbenchmarks` reports results to the dashboard.
TaskFunction createMicrobenchmarkTask() {
  return () async {
20
    final Device device = await devices.workingDevice;
21
    await device.unlock();
22
    await device.clearLogs();
23

24 25
    Future<Map<String, double>> runMicrobench(String benchmarkPath) async {
      Future<Map<String, double>> run() async {
26 27 28 29
        print('Running $benchmarkPath');
        final Directory appDir = dir(
            path.join(flutterDirectory.path, 'dev/benchmarks/microbenchmarks'));
        final Process flutterProcess = await inDirectory(appDir, () async {
30 31 32 33
          final List<String> options = <String>[
            '-v',
            // --release doesn't work on iOS due to code signing issues
            '--profile',
34
            '--no-publish-port',
35 36 37 38
            '-d',
            device.deviceId,
          ];
          options.add(benchmarkPath);
39
          return startFlutter(
40
            'run',
41
            options: options,
42 43
          );
        });
44

45
        return readJsonResults(flutterProcess);
46
      }
47

48
      return run();
49 50
    }

51
    final Map<String, double> allResults = <String, double>{
52 53 54 55 56 57 58
      ...await runMicrobench('lib/foundation/all_elements_bench.dart'),
      ...await runMicrobench('lib/foundation/change_notifier_bench.dart'),
      ...await runMicrobench('lib/foundation/clamp.dart'),
      ...await runMicrobench('lib/foundation/platform_asset_bundle.dart'),
      ...await runMicrobench('lib/foundation/standard_message_codec_bench.dart'),
      ...await runMicrobench('lib/foundation/standard_method_codec_bench.dart'),
      ...await runMicrobench('lib/foundation/timeline_bench.dart'),
59 60 61
      ...await runMicrobench('lib/geometry/matrix_utils_transform_bench.dart'),
      ...await runMicrobench('lib/geometry/rrect_contains_bench.dart'),
      ...await runMicrobench('lib/gestures/gesture_detector_bench.dart'),
62
      ...await runMicrobench('lib/gestures/velocity_tracker_bench.dart'),
63 64 65
      ...await runMicrobench('lib/language/compute_bench.dart'),
      ...await runMicrobench('lib/language/sync_star_bench.dart'),
      ...await runMicrobench('lib/language/sync_star_semantics_bench.dart'),
66 67 68 69
      ...await runMicrobench('lib/stocks/animation_bench.dart'),
      ...await runMicrobench('lib/stocks/build_bench_profiled.dart'),
      ...await runMicrobench('lib/stocks/build_bench.dart'),
      ...await runMicrobench('lib/stocks/layout_bench.dart'),
70
      ...await runMicrobench('lib/ui/image_bench.dart'),
71
    };
72

73 74
    return TaskResult.success(allResults,
        benchmarkScoreKeys: allResults.keys.toList());
75 76
  };
}