mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 10:49:00 +00:00
add kernel generation to the front_end/tool/perf script
BUG= R=paulberry@google.com Review URL: https://codereview.chromium.org/2439053003 .
This commit is contained in:
parent
5964bdfa0b
commit
2bcd189f2d
2 changed files with 59 additions and 11 deletions
|
@ -11,3 +11,9 @@ dependencies:
|
|||
source_span: '^1.2.3'
|
||||
dev_dependencies:
|
||||
package_config: '^1.0.0'
|
||||
# TODO(sigmund): update to a version constraint once we roll the latest kernel
|
||||
# to the repo.
|
||||
kernel: {path: ../../third_party/pkg/kernel}
|
||||
# TODO(sigmund): remove once kernel is moved into the sdk repo.
|
||||
dependency_overrides:
|
||||
analyzer: '^0.29.0'
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
library front_end.tool.perf;
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io' show exit;
|
||||
import 'dart:io' show exit, stderr;
|
||||
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/ast/token.dart';
|
||||
|
@ -22,6 +22,8 @@ import 'package:analyzer/src/dart/sdk/sdk.dart' show FolderBasedDartSdk;
|
|||
import 'package:analyzer/src/generated/parser.dart';
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
import 'package:analyzer/src/generated/source_io.dart';
|
||||
import 'package:kernel/analyzer/loader.dart';
|
||||
import 'package:kernel/kernel.dart';
|
||||
import 'package:package_config/discovery.dart';
|
||||
|
||||
/// Cumulative total number of chars scanned.
|
||||
|
@ -46,19 +48,36 @@ main(List<String> args) async {
|
|||
|
||||
await setup(entryUri);
|
||||
|
||||
if (bench == 'scan') {
|
||||
Set<Source> files = scanReachableFiles(entryUri);
|
||||
// TODO(sigmund): consider replacing the warmup with instrumented snapshots.
|
||||
for (int i = 0; i < 10; i++) scanFiles(files);
|
||||
} else if (bench == 'parse') {
|
||||
Set<Source> files = scanReachableFiles(entryUri);
|
||||
// TODO(sigmund): consider replacing the warmup with instrumented snapshots.
|
||||
for (int i = 0; i < 10; i++) parseFiles(files);
|
||||
} else {
|
||||
print('unsupported bench-id: $bench. Please specify "scan" or "parse"');
|
||||
var handlers = {
|
||||
'scan': () async {
|
||||
Set<Source> files = scanReachableFiles(entryUri);
|
||||
// TODO(sigmund): replace the warmup with instrumented snapshots.
|
||||
for (int i = 0; i < 10; i++) scanFiles(files);
|
||||
},
|
||||
'parse': () async {
|
||||
Set<Source> files = scanReachableFiles(entryUri);
|
||||
// TODO(sigmund): replace the warmup with instrumented snapshots.
|
||||
for (int i = 0; i < 10; i++) parseFiles(files);
|
||||
},
|
||||
'kernel_gen_e2e': () async {
|
||||
// TODO(sigmund): remove. This is used to compute the input size, we
|
||||
// should extract input size from frontend instead.
|
||||
scanReachableFiles(entryUri);
|
||||
// TODO(sigmund): replace this warmup. Note that for very large programs,
|
||||
// the GC pressure on the VM seems to make this worse with time (maybe we
|
||||
// are leaking memory?). That's why we run it twice and not 10 times.
|
||||
for (int i = 0; i < 2; i++) await generateKernel(entryUri);
|
||||
},
|
||||
};
|
||||
|
||||
var handler = handlers[bench];
|
||||
if (handler == null) {
|
||||
// TODO(sigmund): implement the remaining benchmarks.
|
||||
print('unsupported bench-id: $bench. Please specify one of the following: '
|
||||
'${handler.keys.join(", ")}');
|
||||
exit(1);
|
||||
}
|
||||
await handler();
|
||||
|
||||
totalTimer.stop();
|
||||
report("total", totalTimer.elapsedMicroseconds);
|
||||
|
@ -201,3 +220,26 @@ void report(String name, int time) {
|
|||
sb.write(', ${scanTotalChars * 1000 ~/ time} chars/ms');
|
||||
print('$sb');
|
||||
}
|
||||
|
||||
// TODO(sigmund): replace this once kernel is produced by the frontend directly.
|
||||
Future<Program> generateKernel(Uri entryUri) async {
|
||||
var dartkTimer = new Stopwatch()..start();
|
||||
var options = new DartOptions(strongMode: false, sdk: 'sdk');
|
||||
var packages =
|
||||
await createPackages(options.packagePath, discoveryPath: entryUri.path);
|
||||
var repository = new Repository();
|
||||
DartLoader loader = new DartLoader(repository, options, packages);
|
||||
|
||||
Program program = loader.loadProgram(entryUri.path);
|
||||
List errors = loader.errors;
|
||||
if (errors.isNotEmpty) {
|
||||
const int errorLimit = 100;
|
||||
stderr.writeln(errors.take(errorLimit).join('\n'));
|
||||
if (errors.length > errorLimit) {
|
||||
stderr.writeln('[error] ${errors.length - errorLimit} errors not shown');
|
||||
}
|
||||
}
|
||||
dartkTimer.stop();
|
||||
report("kernel_gen_e2e", dartkTimer.elapsedMicroseconds);
|
||||
return program;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue