Skip to content

Commit 5d47c5f

Browse files
mralephcommit-bot@chromium.org
authored andcommitted
[vm_snapshot_analysis] Improve compare command
Add breakdown by node type when this information is available. Change-Id: If2d477d0720aff69e3a168b9520fc3c2ccd153c1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/153767 Commit-Queue: Vyacheslav Egorov <[email protected]> Reviewed-by: Martin Kustermann <[email protected]>
1 parent e253d07 commit 5d47c5f

File tree

4 files changed

+46
-13
lines changed

4 files changed

+46
-13
lines changed

pkg/vm_snapshot_analysis/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 0.5.0
4+
5+
- `compare` command now prints difference breakdown by node type when this
6+
information is available.
7+
38
## 0.4.0
49

510
- Add `buildComparisonTreemap` for constructing treemap representing the diff

pkg/vm_snapshot_analysis/lib/src/commands/compare.dart

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,33 @@ precisely based on their source position (which is included in their name).
144144
print('Comparing ${oldJson.path} (old) to ${newJson.path} (new)');
145145
print('Old : ${totalOld} bytes.');
146146
print('New : ${totalNew} bytes.');
147-
print('Change: ${totalDiff > 0 ? '+' : ''}${totalDiff} bytes.');
147+
print('Change: ${totalDiff > 0 ? '+' : ''}${totalDiff}'
148+
' (${formatPercent(totalDiff, totalOld, withSign: true)}) bytes.');
148149

149150
if (oldSizes.snapshotInfo != null) {
150151
print(bucketLegend);
152+
print('\nBreakdown by object type:');
153+
final oldTypeHistogram =
154+
computeHistogram(oldSizes, HistogramType.byNodeType);
155+
final newTypeHistogram =
156+
computeHistogram(newSizes, HistogramType.byNodeType);
157+
158+
final diffTypeHistogram = Histogram.fromIterable(
159+
Set<String>()
160+
..addAll(oldTypeHistogram.buckets.keys)
161+
..addAll(newTypeHistogram.buckets.keys),
162+
sizeOf: (bucket) =>
163+
(newTypeHistogram.buckets[bucket] ?? 0) -
164+
(oldTypeHistogram.buckets[bucket] ?? 0),
165+
bucketFor: (bucket) => bucket,
166+
bucketInfo: oldTypeHistogram.bucketInfo);
167+
168+
printHistogram(oldSizes, diffTypeHistogram,
169+
prefix: diffTypeHistogram.bySize
170+
.where((bucket) => diffTypeHistogram.buckets[bucket] != 0),
171+
maxWidth: maxWidth);
172+
173+
print(bucketLegend);
151174
}
152175
}
153176
}

pkg/vm_snapshot_analysis/lib/utils.dart

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ Future<Map<String, dynamic>> buildComparisonTreemap(File oldJson, File newJson,
4747
return treemapFromInfo(diff, format: format);
4848
}
4949

50+
String formatPercent(int value, int total, {bool withSign = false}) {
51+
final p = value / total * 100.0;
52+
final sign = (withSign && value > 0) ? '+' : '';
53+
return '${sign}${p.toStringAsFixed(2)}%';
54+
}
55+
5056
void printHistogram(ProgramInfo info, Histogram histogram,
5157
{Iterable<String> prefix = const [],
5258
Iterable<String> suffix = const [],
@@ -61,10 +67,14 @@ void printHistogram(ProgramInfo info, Histogram histogram,
6167
if (wasFiltered) Text.right('Of total'),
6268
], maxWidth: maxWidth);
6369

64-
String formatPercent(int value, int total) {
65-
final p = value / total * 100.0;
66-
return p.toStringAsFixed(2) + "%";
67-
}
70+
final visibleRows = [prefix, suffix].expand((l) => l).toList();
71+
final visibleSize =
72+
visibleRows.fold(0, (sum, key) => sum + histogram.buckets[key]);
73+
final numRestRows = histogram.length - (suffix.length + prefix.length);
74+
final hiddenRows = Set<String>.from(histogram.bySize)
75+
.difference(Set<String>.from(visibleRows));
76+
final interestingHiddenRows =
77+
hiddenRows.any((k) => histogram.buckets[k] != 0);
6878

6979
if (prefix.isNotEmpty) {
7080
for (var key in prefix) {
@@ -76,15 +86,10 @@ void printHistogram(ProgramInfo info, Histogram histogram,
7686
if (wasFiltered) formatPercent(size, totalSize),
7787
]);
7888
}
79-
table.addSeparator(
80-
prefix.length < histogram.length ? Separator.Wave : Separator.Line);
89+
table.addSeparator(interestingHiddenRows ? Separator.Wave : Separator.Line);
8190
}
8291

83-
final visibleSize = [prefix, suffix]
84-
.expand((l) => l)
85-
.fold(0, (sum, key) => sum + histogram.buckets[key]);
86-
final numRestRows = histogram.length - (suffix.length + prefix.length);
87-
if (numRestRows > 0) {
92+
if (interestingHiddenRows) {
8893
final totalRestBytes = histogram.totalSize - visibleSize;
8994
table.addTextSeparator(
9095
'$numRestRows more rows accounting for ${totalRestBytes}'

pkg/vm_snapshot_analysis/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: vm_snapshot_analysis
22
description: Utilities for analysing AOT snapshot size.
3-
version: 0.4.0
3+
version: 0.5.0
44

55
homepage: https://github.com/dart-lang/sdk/tree/master/pkg/vm_snapshot_analysis
66

0 commit comments

Comments
 (0)