Skip to content

Commit 2d21f21

Browse files
authored
Add json size to benchmark. (#3969)
1 parent 7bb331e commit 2d21f21

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

_benchmark/lib/commands.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ class MeasureCommand extends Command<void> {
8989
await Future<void>.delayed(const Duration(seconds: 1));
9090

9191
final update = StringBuffer('${config.generator.packageName}\n');
92-
update.write('shape,libraries,clean/ms,no changes/ms,incremental/ms\n');
92+
update.write(
93+
'shape,libraries,clean/ms,no changes/ms,incremental/ms,'
94+
'json/KiB\n',
95+
);
9396
for (final shape in config.shapes) {
9497
for (final size in config.sizes) {
9598
final pendingResult = pendingResults[(shape, size)]!;
@@ -104,6 +107,7 @@ class MeasureCommand extends Command<void> {
104107
pendingResult.cleanBuildTime.renderFailed,
105108
pendingResult.noChangesBuildTime.renderFailed,
106109
pendingResult.incrementalBuildTime.renderFailed,
110+
pendingResult.graphSize.renderFailed,
107111
].join(','),
108112
);
109113
} else {
@@ -114,6 +118,7 @@ class MeasureCommand extends Command<void> {
114118
pendingResult.cleanBuildTime.render,
115119
pendingResult.noChangesBuildTime.render,
116120
pendingResult.incrementalBuildTime.render,
121+
pendingResult.graphSize.render,
117122
].join(','),
118123
);
119124
}
@@ -138,3 +143,11 @@ extension DurationExtension on Duration? {
138143
String get renderFailed =>
139144
this == null ? 'X' : this!.inMilliseconds.toString();
140145
}
146+
147+
extension IntExtension on int? {
148+
/// Renders with `---` for `null`, to mean "pending".
149+
String get render => this == null ? '---' : (this! / 1024).round().toString();
150+
151+
/// Renders with X` for `null`, to mean "failed".
152+
String get renderFailed => this == null ? 'X' : this!.toString();
153+
}

_benchmark/lib/workspace.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ class Workspace {
7272
return;
7373
}
7474

75+
result.graphSize = _readGraphSize();
76+
7577
// Build with no changes.
7678
stopwatch.reset();
7779
process = await Process.start('dart', [
@@ -111,6 +113,17 @@ class Workspace {
111113
return;
112114
}
113115
}
116+
117+
/// Returns the `build_runner` asset graph size, or `null` if not found.
118+
int? _readGraphSize() {
119+
for (final entry in Directory.fromUri(
120+
directory.uri.resolve('.dart_tool/build'),
121+
).listSync(recursive: true)) {
122+
if (entry is! File) continue;
123+
if (entry.path.endsWith('asset_graph.json')) return entry.lengthSync();
124+
}
125+
return null;
126+
}
114127
}
115128

116129
/// Benchmark results.
@@ -120,6 +133,7 @@ class PendingResult {
120133
Duration? cleanBuildTime;
121134
Duration? noChangesBuildTime;
122135
Duration? incrementalBuildTime;
136+
int? graphSize;
123137
String? failure;
124138

125139
bool get isFailure => failure != null;

0 commit comments

Comments
 (0)