[kernel/CFE] Dill extractor tool; CFE compile dir tool; fixes for stats

This CL adds two tools
* A dill extractor tool which extracts the source files inside the dill
  to a new directory, trying to recrease the package config too so the
  sources can be compiled again. Thought as being useful for doing
  benchmarks between the CFE and the analyzer to make sure they look at
  the exact same source files. No more. No less.
* A CFE compile entry point that compiles all files in a directory.
  Again thought as being useful to compare the CFE with the Analyzer.

Additionally it introduces "--gcs=<int>" to `benchmarker.dart` so it can
do multiple runs and do statistics on combined gc times.

Usage example:

```
$ out/ReleaseX64/dart pkg/front_end/tool/compile.dart pkg/front_end/tool/compile.dart

$ out/ReleaseX64/dart-sdk/bin/dart pkg/kernel/bin/dill_extractor.dart pkg/front_end/tool/compile.dart.dill /tmp/extracted_compile_dart_compile
Done. Wrote 687 source files.

$ out/ReleaseX64/dart-sdk/bin/dart compile aot-snapshot pkg/front_end/tool/compile_files_in_folders.dart
Generated: [...]/pkg/front_end/tool/compile_files_in_folders.aot

$ out/ReleaseX64/dart-sdk/bin/dart compile aot-snapshot pkg/analyzer_cli/bin/analyzer.dart
Generated: [...]/pkg/analyzer_cli/bin/analyzer.aot

$ time out/ReleaseX64/dart-sdk/bin/dartaotruntime pkg/front_end/tool/compile_files_in_folders.aot /tmp/extracted_compile_dart_compile/
Got 626 libraries.
Finished in 0:00:03.496817

real    0m3.530s
user    0m4.985s
sys     0m0.257s

$ time out/ReleaseX64/dart-sdk/bin/dartaotruntime pkg/analyzer_cli/bin/analyzer.aot /tmp/extracted_compile_dart_compile/
Analyzing /tmp/extracted_compile_dart_compile...
  warning • Target of URI doesn't exist: 'package:compiler/src/io/source_file.dart'. • package:_fe_analyzer_shared/src/scanner/utf8_bytes_scanner.dart:5:16 • uri_does_not_exist_in_doc_import
1 warning found.

real    0m8.479s
user    0m9.997s
sys     0m1.048s

$ out/ReleaseX64/dart pkg/front_end/tool/benchmarker.dart --silent --iterations=10 --gcs=5 --snapshot=pkg/front_end/tool/compile_files_in_folders.aot --snapshot=pkg/analyzer_cli/bin/analyzer.aot --arguments="/tmp/extracted_compile_dart_compile/"
Will now run 10 iterations with 2 snapshots.
..............................

Comparing snapshot #1 (compile_files_in_folders.aot) with snapshot #2 (analyzer.aot)
msec task-clock:u: 141.1012% +/- 1.5550% (6281.55 +/- 69.22) (4451.81 -> 10733.36)
page-faults:u: 47.5414% +/- 0.7786% (45602.90 +/- 746.84) (95922.50 -> 141525.40)
cycles:u: 119.3182% +/- 1.5751% (22131655652.90 +/- 292155654.08) (18548436164.50 -> 40680091817.40)
instructions:u: 140.2463% +/- 0.0340% (30410953910.60 +/- 7375789.67) (21683959961.20 -> 52094913871.80)
branch-misses:u: 97.9816% +/- 7.3049% (73071988.00 +/- 5447773.30) (74577266.40 -> 147649254.40)
seconds time elapsed: 141.0789% +/- 1.5479% (6.28 +/- 0.07) (4.45 -> 10.74)
seconds user: 124.4165% +/- 1.8322% (5.31 +/- 0.08) (4.26 -> 9.57)
seconds sys: 521.0422% +/- 17.4291% (0.98 +/- 0.03) (0.19 -> 1.16)
Comparing GC:
Combined GC time: 63.8901% +/- 1.2946% (1008.76 +/- 20.44) (1578.90 -> 2587.66)
```

(note that benchmarker passes `--deterministic` and limits the run to one cpu, both of which (potentially) makes it slower --- which is why the stats say 4.45 s instead of ~3.53 s and 10.74 s instead of ~8.48 s)

Change-Id: I785620ce40af11ca1f7b6c88a0ac863b2200f7d3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/449180
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>

https://dart.googlesource.com/sdk/+/1a218c01036c738acb47cca637cf0cdb2b509a59
2 files changed
tree: 7b28578f24c7d393f6f4c06843237b8b887eb39c
  1. engine/
  2. tools/
  3. .gitignore
  4. commits.json
  5. DEPS
  6. OWNERS
  7. README.md
README.md

Monorepo

A gclient solution for checking out Dart and Flutter source trees

Monorepo is:

  • Optimized for Tip-of-Tree testing: The Monorepo DEPS used to check out Dart and Flutter dependencies comes from the Flutter engine DEPS with updated dependencies from Dart.

Checking out Monorepo

With depot_tools installed and on your path, create a directory for your monorepo checkout and run these commands to create a gclient solution in that directory:

mkdir monorepo
cd monorepo
gclient config --unmanaged https://dart.googlesource.com/monorepo
gclient sync -D

This gives you a checkout in the monorepo directory that contains:

monorepo/
  DEPS - the DEPS used for this gclient checkout
  commits.json - the pinned commits for Dart, flutter/engine,
                 and flutter/flutter
  tools/ - scripts used to create monorepo DEPS
engine/src/ - the flutter/buildroot repo
    flutter/ - the flutter/engine repo
    out/ - the build directory, where Flutter engine builds are created
    third_party/ - Flutter dependencies checked out by DEPS
      dart/ - the Dart SDK checkout.
        third_party - Dart dependencies, also used by Flutter
flutter/ - the flutter/flutter repo

Building Flutter engine

Flutter's instructions for building the engine are at Compiling the engine

They can be followed closely, with a few changes:

  • Googlers working on Dart do not need to switch to Fuchsia's Goma RBE, except for Windows. The GOMA_DIR enviroment variable can just point to the .cipd_bin directory in a depot_tools installation, and just goma_ctl ensure_start is sufficient.
  • The --no-prebuilt-dart-sdk option has to be added to every gn command, so that the build is set up to build and use a local Dart SDK.
  • The --full-dart-sdk option must be added to gn for the host build target if you will be building web or desktop apps.

Example build commands that work on linux:

MONOREPO_PATH=$PWD
if [[ ! $PATH =~ (^|:)$MONOREPO_PATH/flutter/bin(:|$) ]]; then
  PATH=$MONOREPO_PATH/flutter/bin:$PATH
fi

export GOMA_DIR=$(dirname $(command -v gclient))/.cipd_bin
goma_ctl ensure_start

pushd engine/src
flutter/tools/gn --goma --no-prebuilt-dart-sdk --unoptimized --full-dart-sdk
autoninja -C out/host_debug_unopt
popd

Building Flutter apps

The Flutter commands used to build and run apps will use the locally built Flutter engine and Dart SDK, instead of the one downloaded by the Flutter tool, if the --local-engine option is provided.

For example, to build and run the Flutter spinning square sample on the web platform,

MONOREPO_PATH=$PWD
cd flutter/examples/layers
flutter --local-engine=host_debug_unopt \
  -d chrome run widgets/spinning_square.dart
cd $MONOREPO_PATH

To build for desktop, specify the desktop platform device in flutter run as -d macos or -d linux or -d windows. You may also need to run the command

flutter create --platforms=windows,macos,linux

on existing apps, such as sample apps. New apps created with flutter create already include these support files. Details of desktop support are at Desktop Support for Flutter

Testing

Tests in the Flutter source tree can be run with the flutter test command, run in the directory of a package containing tests. For example:

MONOREPO_PATH=$PWD
cd flutter/packages/flutter
flutter test --local-engine=host_debug_unopt
cd $MONOREPO_PATH

Troubleshooting

Please file an issue or email the dart-engprod team with any problems with or questions about using monorepo.

We will update this documentation to address them.

  • flutter commands may download the engine and Dart SDK files for the configured channel, even though they will be using the local engine and its SDK.

Windows

  • On Windows, gclient sync needs to be run in an administrator session, because some installed dependencies create symlinks.