Files
sdk/pkg/analysis_server/benchmark/perf/utils.dart
T
Jens Johansen fa88e0c91f [analyzer] Add benchmarks of running dart analyze
This CL:
  * Adds a benchmark of running `dart analyze` on a single small file.
  * Adds a benchmark of running `dart analyze` on a single project.
  * Adds a benchmark of running `dart analyze` on several projects.
  * Adds a hidden flag to `dart analyze` so it reports ram usage:
    run via `dart analyze --format=json --memory` and the memory
    usage will be reported in the json output.

All the bencmarks run without and with cache for speed testing, and
without and with cache when measuring memory usage.

The idea of running this via `dart analyze` instead of running either
the script or the snapshot is to measure the "real world" speed which
could be different (although in practise it _does_ just run the
snapshot).

Future CL(s) should also add benchmarks for queries using the
language server.

Change-Id: Iad6d6d72c1a2ed18ab51d056b4914f8b6eb963e4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/276100
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2022-12-19 08:22:32 +00:00

49 lines
1.1 KiB
Dart

// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:convert';
import 'dart:io';
Future<int> runProcess(
String command,
List<String> args, {
String? cwd,
bool failOnError = true,
bool verbose = true,
List<String>? stdout,
}) async {
if (verbose) {
print('\n$command ${args.join(' ')}');
}
var process = await Process.start(command, args, workingDirectory: cwd);
process.stdout
.transform(utf8.decoder)
.transform(LineSplitter())
.listen((line) {
if (verbose) {
print(' $line');
}
if (stdout != null) {
stdout.add(line);
}
});
process.stderr
.transform(utf8.decoder)
.transform(LineSplitter())
.listen((line) {
if (verbose) {
print(' $line');
}
});
var exitCode = await process.exitCode;
if (exitCode != 0 && failOnError) {
throw '$command exited with $exitCode';
}
return exitCode;
}