Skip to content

Commit 08c802c

Browse files
jensjohaCommit Queue
authored and
Commit Queue
committed
[CFE] Additions to benchmarker.dart et al
## Added --cache to benchmarker.dart This doubles the amount of runs by running an additional round of `perf stat` runs outputting low level cache information: L1-icache-load-misses (instruction load misses), LLC-loads (last level cache loads, i.e. probably how many loads goes to L3 cache) and LLC-load-misses (last level cache load misses, i.e. how many loads goes to ram). I don't know if these are generally available, only that they are available on my machine. ## Added --silent to benchmarker.dart Some benchmarks output information to stdout which is great when running it by hand, but when running it via the benchmarker script it just pollutes the output: The benchmarker script et al measures what is supposed to be measured. This CL adds the `--silent` option to the benchmarker script which then won't print the stdout output from the benchmarkee. ## Output filename in benchmarker.dart This CL adds the filenames of the benchmarked snapshots in an attempt to avoid confusion. Example output before: ``` Comparing snapshot #1 with snapshot #2 ``` ``` Example output now: Comparing snapshot #1 (optimization_attempt_41.aot) with snapshot #2 (optimization_attempt_42.aot) ``` ## Utility to summarize --verbose-gc output Takes input from --verbose-gc from stdin and summarizes the time taken on GC and reports it back. Example: ``` $ out/ReleaseX64/dart --verbose-gc hello.dart 2> /dev/stdout 1> /dev/null | out/ReleaseX64/dart pkg/front_end/tool/verbose_gc_helper.dart 6.1 ``` Change-Id: I206f21cd8b42f844e60358aed711e676e453c77c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/406845 Reviewed-by: Johnni Winther <johnniwinther@google.com> Commit-Queue: Jens Johansen <jensj@google.com>
1 parent a11aeeb commit 08c802c

File tree

3 files changed

+84
-11
lines changed

3 files changed

+84
-11
lines changed

pkg/front_end/test/spell_checking_list_tests.txt

+2
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ hunk
424424
hurray
425425
i'm
426426
ia
427+
icache
427428
identification
428429
idle
429430
if's
@@ -499,6 +500,7 @@ linebreaks
499500
lints
500501
listening
501502
listing
503+
llc
502504
ln
503505
locale
504506
locating

pkg/front_end/tool/benchmarker.dart

+52-11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ late final Uri repoDir = computeRepoDirUri();
1212
void main(List<String> args) {
1313
if (args.contains("--help")) return _help();
1414
_checkEnvironment();
15+
bool doCacheBenchmarkingToo = false;
16+
bool silent = false;
1517
int iterations = 5;
1618
int core = 7;
1719
String? aotRuntime;
@@ -31,6 +33,10 @@ void main(List<String> args) {
3133
arguments.add(arg.substring("--arguments=".length));
3234
} else if (arg.startsWith("--filesize=")) {
3335
checkFileSize = arg.substring("--filesize=".length);
36+
} else if (arg == "--cache") {
37+
doCacheBenchmarkingToo = true;
38+
} else if (arg == "--silent") {
39+
silent = true;
3440
} else {
3541
throw "Don't know argument '$arg'";
3642
}
@@ -44,6 +50,17 @@ void main(List<String> args) {
4450
print("Note: Running without any arguments to the snapshots.");
4551
}
4652

53+
_doRun(iterations, snapshots, aotRuntime, core, arguments, checkFileSize,
54+
cacheBenchmarking: false, silent: silent);
55+
if (doCacheBenchmarkingToo) {
56+
_doRun(iterations, snapshots, aotRuntime, core, arguments, checkFileSize,
57+
cacheBenchmarking: true, silent: silent);
58+
}
59+
}
60+
61+
void _doRun(int iterations, List<String> snapshots, String aotRuntime, int core,
62+
List<String> arguments, String? checkFileSize,
63+
{required bool cacheBenchmarking, required bool silent}) {
4764
print("Will now run $iterations iterations with "
4865
"${snapshots.length} snapshots.");
4966

@@ -54,9 +71,14 @@ void main(List<String> args) {
5471
List<Map<String, num>> snapshotResults = [];
5572
runResults.add(snapshotResults);
5673
for (int iteration = 0; iteration < iterations; iteration++) {
74+
// We want this silent to mean no stdout print, but still want progress
75+
// info which is what the dot provides.
76+
if (silent) stdout.write(".");
5777
Map<String, num> benchmarkRun = _benchmark(
5878
aotRuntime, core, snapshot, [], arguments,
59-
warnings: warnings);
79+
warnings: warnings,
80+
cacheBenchmarking: cacheBenchmarking,
81+
silent: silent);
6082
if (checkFileSize != null) {
6183
File f = new File(checkFileSize);
6284
if (f.existsSync()) {
@@ -67,14 +89,17 @@ void main(List<String> args) {
6789
}
6890

6991
// Do a single GC run too.
70-
gcInfos.add(_verboseGcRun(aotRuntime, snapshot, [], arguments));
92+
if (silent) stdout.write(".");
93+
gcInfos
94+
.add(_verboseGcRun(aotRuntime, snapshot, [], arguments, silent: true));
7195
}
7296
stdout.write("\n\n");
7397

7498
List<Map<String, num>> firstSnapshotResults = runResults.first;
7599
for (int i = 1; i < runResults.length; i++) {
76100
if (i > 1) print("");
77-
print("Comparing snapshot #1 with snapshot #${i + 1}");
101+
print("Comparing snapshot #1 (${_getName(snapshots[0])}) with "
102+
"snapshot #${i + 1} (${_getName(snapshots[i])})");
78103
List<Map<String, num>> compareToResults = runResults[i];
79104
if (!_compare(firstSnapshotResults, compareToResults)) {
80105
print("No change.");
@@ -92,6 +117,10 @@ void main(List<String> args) {
92117
}
93118
}
94119

120+
String _getName(String urlIsh) {
121+
return Uri.parse(urlIsh).pathSegments.last;
122+
}
123+
95124
void _help() {
96125
print("CFE benchmarker tool");
97126
print("");
@@ -170,30 +199,38 @@ List<num> _extractDataForCaption(String caption, List<Map<String, num>> data) {
170199

171200
Map<String, num> benchmark(
172201
String snapshot, List<String> extraVmArguments, List<String> arguments,
173-
{String? aotRuntime, int? core}) {
202+
{String? aotRuntime, int? core, bool cacheBenchmarking = false}) {
174203
return _benchmark(aotRuntime ?? _computeAotRuntime(), core ?? 7, snapshot,
175204
extraVmArguments, arguments,
176-
silent: true);
205+
silent: true, cacheBenchmarking: cacheBenchmarking);
177206
}
178207

179208
late final RegExp _extractNumbers =
180209
new RegExp(r"([\d+\,\.]+)\s+(.+)\s*", caseSensitive: false);
181210

182211
Map<String, num> _benchmark(String aotRuntime, int core, String snapshot,
183212
List<String> extraVmArguments, List<String> arguments,
184-
{bool silent = false, Warnings? warnings}) {
213+
{bool silent = false, Warnings? warnings, bool cacheBenchmarking = false}) {
185214
if (!silent) stdout.write(".");
215+
216+
// These influence scaling, so only pick 3 (apparently that's now the
217+
// magic limit)
218+
String scalingEvents = "cycles:u,"
219+
"instructions:u,"
220+
"branch-misses:u";
221+
if (cacheBenchmarking) {
222+
scalingEvents = "L1-icache-load-misses:u,"
223+
"LLC-loads:u,"
224+
"LLC-load-misses:u";
225+
}
186226
ProcessResult processResult = Process.runSync("perf", [
187227
"stat",
188228
"-B",
189229
"-e",
190230
// These doesn't influence scaling
191231
"task-clock:u,context-switches:u,cpu-migrations:u,page-faults:u,"
192-
// These influence scaling, so only pick 3 (apparently that's now the
193-
// magic limit)
194-
"cycles:u,"
195-
"instructions:u,"
196-
"branch-misses:u",
232+
// These influence scaling
233+
"$scalingEvents",
197234
"taskset",
198235
"-c",
199236
"$core",
@@ -309,6 +346,10 @@ bool _whichOk(String what) {
309346

310347
GCInfo parseVerboseGcOutput(ProcessResult processResult) {
311348
List<String> stderrLines = processResult.stderr.split("\n");
349+
return parseVerboseGcText(stderrLines);
350+
}
351+
352+
GCInfo parseVerboseGcText(List<String> stderrLines) {
312353
double combinedTime = 0;
313354
Map<String, int> countWhat = {};
314355
for (String line in stderrLines) {
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import 'dart:async';
2+
import 'dart:convert';
3+
import 'dart:typed_data' show BytesBuilder;
4+
import 'dart:io';
5+
6+
import 'benchmarker.dart';
7+
8+
/// Take --verbose-gc data from stdin and print the combined runtime.
9+
///
10+
/// E.g. (and this is not pretty):
11+
/// out/ReleaseX64/dart --verbose-gc \
12+
/// hello.dart 2> /dev/stdout 1> /dev/null | out/ReleaseX64/dart \
13+
/// pkg/front_end/tool/verbose_gc_helper.dart
14+
Future<void> main() async {
15+
Completer completer = new Completer();
16+
BytesBuilder bb = new BytesBuilder();
17+
late StreamSubscription<List<int>> subscription;
18+
subscription = stdin.listen((List<int> data) {
19+
bb.add(data);
20+
}, onDone: () {
21+
subscription.cancel();
22+
completer.complete();
23+
}, onError: (_) {
24+
subscription.cancel();
25+
completer.complete();
26+
});
27+
await completer.future;
28+
GCInfo gcInfo = parseVerboseGcText(utf8.decode(bb.takeBytes()).split("\n"));
29+
print(gcInfo.combinedTime);
30+
}

0 commit comments

Comments
 (0)