Skip to content

Commit a82aa2f

Browse files
jensjohaCommit Queue
authored andcommitted
[CFE] More options in benchmarker script
* Adds a "ruler" at the start of a run to make it easier to gauge progress. * Adds option `--no-gc` which will make the new space very big thus avoiding gc in most cases. In practise it is slower, but the number of instructions will be less. * Adds option `--sarguments=` which adds an argument only to the latest mentioned snapshot. This way one can use the same snapshot, but pass different options. Change-Id: I30d8bdb21556b38ce6a52e7ce3e6ee46fa8ad2c5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/453060 Commit-Queue: Jens Johansen <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
1 parent 906a62c commit a82aa2f

File tree

2 files changed

+112
-13
lines changed

2 files changed

+112
-13
lines changed

pkg/front_end/test/spell_checking_list_tests.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,7 @@ ruin
742742
runtimes
743743
rv
744744
sanitize
745+
sarguments
745746
saves
746747
scaled
747748
scaling

pkg/front_end/tool/benchmarker.dart

Lines changed: 111 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ void main(List<String> args) {
1313
if (args.contains("--help")) return _help();
1414
_checkEnvironment();
1515
bool doCacheBenchmarkingToo = false;
16+
bool doDisabledGcBenchmarkToo = false;
1617
bool silent = false;
1718
int iterations = 5;
1819
int core = 7;
1920
int gcRuns = 1;
2021
String? aotRuntime;
2122
String? checkFileSize;
2223
List<String> snapshots = [];
24+
List<List<String>> snapshotSpecificArguments = [];
2325
List<String> arguments = [];
2426
for (String arg in args) {
2527
if (arg.startsWith("--iterations=")) {
@@ -34,10 +36,20 @@ void main(List<String> args) {
3436
snapshots.add(arg.substring("--snapshot=".length));
3537
} else if (arg.startsWith("--arguments=")) {
3638
arguments.add(arg.substring("--arguments=".length));
39+
} else if (arg.startsWith("--sarguments=")) {
40+
// "specific arguments" or "snapshot arguments".
41+
while (snapshotSpecificArguments.length < snapshots.length) {
42+
snapshotSpecificArguments.add([]);
43+
}
44+
snapshotSpecificArguments[snapshotSpecificArguments.length - 1].add(
45+
arg.substring("--sarguments=".length),
46+
);
3747
} else if (arg.startsWith("--filesize=")) {
3848
checkFileSize = arg.substring("--filesize=".length);
3949
} else if (arg == "--cache") {
4050
doCacheBenchmarkingToo = true;
51+
} else if (arg == "--no-gc") {
52+
doDisabledGcBenchmarkToo = true;
4153
} else if (arg == "--silent") {
4254
silent = true;
4355
} else {
@@ -52,31 +64,59 @@ void main(List<String> args) {
5264
if (arguments.isEmpty) {
5365
print("Note: Running without any arguments to the snapshots.");
5466
}
67+
while (snapshotSpecificArguments.length < snapshots.length) {
68+
snapshotSpecificArguments.add([]);
69+
}
5570

5671
_doRun(
5772
iterations,
5873
snapshots,
5974
aotRuntime,
6075
core,
6176
arguments,
77+
snapshotSpecificArguments,
6278
checkFileSize,
6379
cacheBenchmarking: false,
6480
silent: silent,
6581
gcRuns: gcRuns,
6682
);
6783
if (doCacheBenchmarkingToo) {
84+
print("");
6885
_doRun(
6986
iterations,
7087
snapshots,
7188
aotRuntime,
7289
core,
7390
arguments,
91+
snapshotSpecificArguments,
7492
checkFileSize,
7593
cacheBenchmarking: true,
7694
silent: silent,
7795
gcRuns: gcRuns,
7896
);
7997
}
98+
if (doDisabledGcBenchmarkToo) {
99+
print("");
100+
_doRun(
101+
iterations,
102+
snapshots,
103+
aotRuntime,
104+
core,
105+
arguments,
106+
snapshotSpecificArguments,
107+
checkFileSize,
108+
cacheBenchmarking: false,
109+
silent: silent,
110+
gcRuns: 0,
111+
extraVmArguments: [
112+
"--new_gen_semi_initial_size=10000",
113+
"--new_gen_semi_max_size=20000",
114+
],
115+
);
116+
117+
// TODO(jensj): Should we do a (number of) run(s) where we measure memory
118+
// usage?
119+
}
80120
}
81121

82122
void _doRun(
@@ -85,34 +125,66 @@ void _doRun(
85125
String aotRuntime,
86126
int core,
87127
List<String> arguments,
128+
List<List<String>> snapshotSpecificArguments,
88129
String? checkFileSize, {
89130
required bool cacheBenchmarking,
90131
required bool silent,
91132
required int gcRuns,
133+
List<String>? extraVmArguments,
92134
}) {
93135
print(
94-
"Will now run $iterations iterations with "
136+
"Will now run $iterations+$gcRuns iterations with "
95137
"${snapshots.length} snapshots.",
96138
);
97139

140+
if (extraVmArguments != null && extraVmArguments.isNotEmpty) {
141+
print("Running with extra vm arguments: ${extraVmArguments.join(" ")}");
142+
}
143+
144+
int lines;
145+
{
146+
try {
147+
lines = stdout.terminalLines;
148+
} catch (_) {
149+
lines = 80;
150+
}
151+
152+
if (lines > 80) lines = 80;
153+
int totalNumberOfRuns = (iterations + gcRuns) * snapshots.length;
154+
if (totalNumberOfRuns < lines) lines = totalNumberOfRuns;
155+
List<int> charCodes = List.filled(lines, ".".codeUnitAt(0));
156+
for (int i = 9; i < charCodes.length; i += 10) {
157+
charCodes[i] = "|".codeUnitAt(0);
158+
}
159+
print(new String.fromCharCodes(charCodes));
160+
}
161+
98162
List<List<Map<String, num>>> runResults = [];
99163
List<List<GCInfo>> gcInfos = [];
100164
Warnings warnings = new Warnings();
101-
for (String snapshot in snapshots) {
165+
int writes = 0;
166+
for (int snapshotNum = 0; snapshotNum < snapshots.length; snapshotNum++) {
167+
String snapshot = snapshots[snapshotNum];
168+
List<String> usedArguments = [
169+
...arguments,
170+
...snapshotSpecificArguments[snapshotNum],
171+
];
102172
List<GCInfo> gcInfo = [];
103173
gcInfos.add(gcInfo);
104174
List<Map<String, num>> snapshotResults = [];
105175
runResults.add(snapshotResults);
106176
for (int iteration = 0; iteration < iterations; iteration++) {
107177
// We want this silent to mean no stdout print, but still want progress
108178
// info which is what the dot provides.
109-
if (silent) stdout.write(".");
179+
if (silent) {
180+
writes = _silentWrite(writes, lines);
181+
}
110182
Map<String, num> benchmarkRun = _benchmark(
111183
aotRuntime,
112184
core,
113185
snapshot,
114-
[],
115-
arguments,
186+
extraVmArguments ?? [],
187+
usedArguments,
116188
warnings: warnings,
117189
cacheBenchmarking: cacheBenchmarking,
118190
silent: silent,
@@ -128,37 +200,52 @@ void _doRun(
128200

129201
// Do GC runs too.
130202
for (int i = 0; i < gcRuns; i++) {
131-
if (silent) stdout.write(".");
203+
if (silent) {
204+
writes = _silentWrite(writes, lines);
205+
}
132206
gcInfo.add(
133-
_verboseGcRun(aotRuntime, snapshot, [], arguments, silent: true),
207+
_verboseGcRun(aotRuntime, snapshot, [], usedArguments, silent: true),
134208
);
135209
}
136210
}
137211
stdout.write("\n\n");
138212

139213
List<Map<String, num>> firstSnapshotResults = runResults.first;
214+
String snapshot1Name = _getName(snapshots[0]);
215+
if (snapshotSpecificArguments[0].isNotEmpty) {
216+
snapshot1Name += " ${snapshotSpecificArguments[0].join(" ")}";
217+
}
140218
for (int i = 1; i < runResults.length; i++) {
141219
if (i > 1) print("");
220+
String comparedToSnapshotName = _getName(snapshots[i]);
221+
if (snapshotSpecificArguments[i].isNotEmpty) {
222+
comparedToSnapshotName += " ${snapshotSpecificArguments[i].join(" ")}";
223+
}
142224
print(
143-
"Comparing snapshot #1 (${_getName(snapshots[0])}) with "
144-
"snapshot #${i + 1} (${_getName(snapshots[i])})",
225+
"Comparing snapshot #1 ($snapshot1Name) with "
226+
"snapshot #${i + 1} ($comparedToSnapshotName)",
145227
);
146228
List<Map<String, num>> compareToResults = runResults[i];
147229
if (!_compare(firstSnapshotResults, compareToResults)) {
148230
print("No change.");
149231
}
150-
print("Comparing GC:");
151232
if (gcRuns >= 3) {
233+
print("\nComparing GC runtimes:");
152234
if (!_compareSingle(
153235
gcInfos[i].map((gcInfo) => gcInfo.combinedTime).toList(),
154236
gcInfos[0].map((gcInfo) => gcInfo.combinedTime).toList(),
155237
"Combined GC time",
156238
)) {
157239
print("No change in combined time.");
158240
}
159-
} else {
241+
} else if (gcRuns > 0) {
242+
print("\nComparing GC data:");
243+
bool printedAnything = false;
160244
for (int gcNum = 0; gcNum < gcRuns; gcNum++) {
161-
printGcDiff(gcInfos[0][gcNum], gcInfos[i][gcNum]);
245+
printedAnything |= printGcDiff(gcInfos[0][gcNum], gcInfos[i][gcNum]);
246+
}
247+
if (!printedAnything) {
248+
print("'No' GC change.");
162249
}
163250
}
164251
}
@@ -173,6 +260,16 @@ void _doRun(
173260
}
174261
}
175262

263+
int _silentWrite(int previousWriteCount, int lines) {
264+
if (previousWriteCount >= lines) {
265+
stdout.write("\n");
266+
previousWriteCount = 0;
267+
}
268+
stdout.write(".");
269+
previousWriteCount++;
270+
return previousWriteCount;
271+
}
272+
176273
String _getName(String urlIsh) {
177274
return Uri.parse(urlIsh).pathSegments.last;
178275
}
@@ -499,7 +596,7 @@ void combinedGcDiff(List<GCInfo> prev, List<GCInfo> current) {
499596
prev.map((gcInfo) => gcInfo.combinedTime).toList();
500597
}
501598

502-
void printGcDiff(GCInfo prev, GCInfo current) {
599+
bool printGcDiff(GCInfo prev, GCInfo current) {
503600
Set<String> allKeys = {...prev.countWhat.keys, ...current.countWhat.keys};
504601
bool printedAnything = false;
505602
for (String key in allKeys) {
@@ -517,6 +614,7 @@ void printGcDiff(GCInfo prev, GCInfo current) {
517614
"(notice only 1 run each).",
518615
);
519616
}
617+
return printedAnything;
520618
}
521619

522620
class GCInfo {

0 commit comments

Comments
 (0)