microbenchmarks.dart 3.27 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
/// Creates a device lab task that runs benchmarks in
/// `dev/benchmarks/microbenchmarks` reports results to the dashboard.
18
TaskFunction createMicrobenchmarkTask({bool? enableImpeller}) {
19
  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
            if (enableImpeller != null && enableImpeller) '--enable-impeller',
            if (enableImpeller != null && !enableImpeller) '--no-enable-impeller',
37
            '-d',
38 39 40
            device.deviceId,
          ];
          options.add(benchmarkPath);
41
          return startFlutter(
42
            'run',
43
            options: options,
44 45
          );
        });
46

47
        return readJsonResults(flutterProcess);
48
      }
49

50
      return run();
51 52
    }

53
    final Map<String, double> allResults = <String, double>{
54 55 56 57 58 59 60
      ...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'),
61
      ...await runMicrobench('lib/foundation/decode_and_parse_asset_manifest.dart'),
62 63 64
      ...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'),
65
      ...await runMicrobench('lib/gestures/velocity_tracker_bench.dart'),
66 67 68
      ...await runMicrobench('lib/language/compute_bench.dart'),
      ...await runMicrobench('lib/language/sync_star_bench.dart'),
      ...await runMicrobench('lib/language/sync_star_semantics_bench.dart'),
69 70 71 72
      ...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'),
73
      ...await runMicrobench('lib/ui/image_bench.dart'),
74
    };
75

76 77
    return TaskResult.success(allResults,
        benchmarkScoreKeys: allResults.keys.toList());
78 79
  };
}