platform_channels_benchmarks.dart 1.8 KB
Newer Older
1 2 3 4
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'dart:io' show Directory, Process;
6 7 8

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

9 10 11 12 13 14
import '../framework/devices.dart' as adb;
import '../framework/framework.dart' show TaskFunction;
import '../framework/task_result.dart' show TaskResult;
import '../framework/utils.dart' as utils;
import '../microbenchmarks.dart' as microbenchmarks;

15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
TaskFunction runTask(adb.DeviceOperatingSystem operatingSystem) {
  return () async {
    adb.deviceOperatingSystem = operatingSystem;
    final adb.Device device = await adb.devices.workingDevice;
    await device.unlock();

    final Directory appDir = utils.dir(path.join(utils.flutterDirectory.path,
        'dev/benchmarks/platform_channels_benchmarks'));
    final Process flutterProcess = await utils.inDirectory(appDir, () async {
      final String flutterExe =
          path.join(utils.flutterDirectory.path, 'bin', 'flutter');
      final List<String> createArgs = <String>[
        'create',
        '--platforms',
        'ios,android',
        '--no-overwrite',
        '-v',
32
        '.',
33 34
      ];
      print('\nExecuting: $flutterExe $createArgs $appDir');
35
      await utils.eval(flutterExe, createArgs);
36 37 38 39 40 41 42 43 44

      final List<String> options = <String>[
        '-v',
        // --release doesn't work on iOS due to code signing issues
        '--profile',
        '--no-publish-port',
        '-d',
        device.deviceId,
      ];
45 46
      return utils.startFlutter(
        'run',
47 48 49 50 51 52 53 54 55 56
        options: options,
      );
    });

    final Map<String, double> results =
        await microbenchmarks.readJsonResults(flutterProcess);
    return TaskResult.success(results,
        benchmarkScoreKeys: results.keys.toList());
  };
}