Skip to content

Commit dfcbd59

Browse files
author
Harry Terkelsen
authored
add diff tool (flutter#19)
* add diff tool
1 parent bd163f4 commit dfcbd59

File tree

6 files changed

+339
-36
lines changed

6 files changed

+339
-36
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.5.5
2+
3+
- Added `diff` tool.
4+
15
## 0.5.4+2
26

37
- Updated minimum SDK dependency to align with package dependencies.

README.md

Lines changed: 65 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ The following tools are a available today:
6363
dependency between functions and fields in your program. Currently it only
6464
supports the `some_path` query, which shows a dependency path from one
6565
function to another.
66+
67+
* [`diff`][diff]: a tool that diffs two info files and reports which
68+
program elements have been added, removed, or changed size. This also
69+
tells which elements are no longer deferred or have become deferred.
6670

6771
* [`library_size_split`][lib_split]: a tool that shows how much code was
6872
attributed to each library. This tool is configurable so it can group data
@@ -102,10 +106,10 @@ this tool only supports the `some_path` query, which gives you the shortest path
102106
for how one function depends on another.
103107

104108
Run this tool as follows:
105-
```bash
109+
```console
106110
# activate is only needed once to install the dart2js_info* executables
107-
pub global activate dart2js_info
108-
dart2js_info_code_deps out.js.info.json some_path main foo
111+
$ pub global activate dart2js_info
112+
$ dart2js_info_code_deps out.js.info.json some_path main foo
109113
```
110114

111115
The arguments to the query are regular expressions that can be used to
@@ -120,22 +124,58 @@ a fully qualified element name, which includes the library and class name
120124
If the name of a function your are looking for is unique enough, it might be
121125
sufficient to just write that name as your regular expression.
122126

127+
### Diff tool
128+
129+
This command-line tool shows a diff between two info files. It can be run
130+
as follows:
131+
132+
```console
133+
$ pub global activate dart2js_info # only needed once
134+
$ dart2js_info_diff old.js.info.json new.js.info.json
135+
```
136+
137+
The tool gives a breakdown of the difference between the two info files.
138+
Here's an example output:
139+
140+
```
141+
OVERALL SIZE DIFFERENCE
142+
========================================================================
143+
3 bytes
144+
145+
ADDED
146+
========================================================================
147+
148+
REMOVED
149+
========================================================================
150+
file:///home/het/Code/foo/foo.dart::A.y: 0 bytes
151+
152+
CHANGED SIZE
153+
========================================================================
154+
155+
BECAME DEFERRED
156+
========================================================================
157+
158+
NO LONGER DEFERRED
159+
========================================================================
160+
161+
```
162+
123163
### Library size split tool
124164

125165
This command-line tool shows the size distribution of generated code among
126166
libraries. It can be run as follows:
127167

128-
```bash
129-
pub global activate dart2js_info # only needed once
130-
dart2js_info_library_size_split out.js.info.json
168+
```console
169+
$ pub global activate dart2js_info # only needed once
170+
$ dart2js_info_library_size_split out.js.info.json
131171
```
132172

133173

134174
Libraries can be grouped using regular expressions. You can
135175
specify what regular expressions to use by providing a `grouping.yaml` file:
136176

137-
```bash
138-
dart2js_info_library_size_split out.js.info.json grouping.yaml
177+
```console
178+
$ dart2js_info_library_size_split out.js.info.json grouping.yaml
139179
```
140180

141181
The format of the `grouping.yaml` file is as follows:
@@ -205,9 +245,9 @@ bootstrapping code and lazy static initializers are missing.
205245
This tool checks that the output from dart2js meets a given specification,
206246
given in a YAML file. It can be run as follows:
207247

208-
```bash
209-
pub global activate dart2js_info # only needed once
210-
dart2js_info_deferred_library_check out.js.info.json manifest.yaml
248+
```console
249+
$ pub global activate dart2js_info # only needed once
250+
$ dart2js_info_deferred_library_check out.js.info.json manifest.yaml
211251
```
212252

213253
The format of the YAML file is:
@@ -253,7 +293,7 @@ This tool gives a breakdown of all of the deferred code in the program by size.
253293
It can show how much of the total code size is deferred. It can be run as
254294
follows:
255295

256-
```bash
296+
```console
257297
pub global activate dart2js_info # only needed once
258298
dart2js_info_deferred_library_size out.js.info.json
259299
```
@@ -278,9 +318,9 @@ Percent of code deferred 41.86%
278318
This tool reports which code is included in each output unit. It can be run as
279319
follows:
280320

281-
```bash
282-
pub global activate dart2js_info # only needed once
283-
dart2js_info_deferred_library_layout out.js.info.json
321+
```console
322+
$ pub global activate dart2js_info # only needed once
323+
$ dart2js_info_deferred_library_layout out.js.info.json
284324
```
285325

286326
The tool will output a table listing all of the deferred output units or chunks,
@@ -322,9 +362,9 @@ code of your application. We use dependency information to compute dominance
322362
and reachability data as well.
323363

324364
When you run:
325-
```bash
326-
pub global activate dart2js_info # only needed once
327-
dart2js_info_function_size_analysis out.js.info.json
365+
```console
366+
$ pub global activate dart2js_info # only needed once
367+
$ dart2js_info_function_size_analysis out.js.info.json
328368
```
329369

330370
the tool produces a table output with lots of entries. Here is an example entry
@@ -355,8 +395,8 @@ steps are as follows:
355395
* Compile an app with dart2js using `--dump-info` and defining the
356396
Dart environment `traceCalls=post`:
357397

358-
```
359-
DART_VM_OPTIONS="-DtraceCalls=post" dart2js --dump-info main.dart
398+
```console
399+
$ DART_VM_OPTIONS="-DtraceCalls=post" dart2js --dump-info main.dart
360400
```
361401

362402
Because coverage/tracing data is currently experimental, the feature is
@@ -365,8 +405,8 @@ DART_VM_OPTIONS="-DtraceCalls=post" dart2js --dump-info main.dart
365405

366406
* Launch the coverage server tool to serve up the JS code of your app:
367407

368-
```bash
369-
dart2js_info_coverage_log_server main.dart.js
408+
```console
409+
$ dart2js_info_coverage_log_server main.dart.js
370410
```
371411

372412
* (optional) If you have a complex application setup, you may need to serve an
@@ -382,8 +422,8 @@ dart2js_info_coverage_log_server main.dart.js
382422
* Finally, run the live code analysis tool given it both the info and
383423
coverage json files:
384424

385-
```bash
386-
dart2js_info_live_code_size_analysis main.dart.info.json main.dart.coverage.json
425+
```console
426+
$ dart2js_info_live_code_size_analysis main.dart.info.json main.dart.coverage.json
387427
```
388428

389429
## Code location, features and bugs
@@ -394,6 +434,7 @@ bugs at the [issue tracker][tracker].
394434
[repo]: https://github.com/dart-lang/dart2js_info/
395435
[tracker]: https://github.com/dart-lang/dart2js_info/issues
396436
[code_deps]: https://github.com/dart-lang/dart2js_info/blob/master/bin/code_deps.dart
437+
[diff]: https://github.com/dart-lang/dart2js_info/blob/master/bin/diff.dart
397438
[lib_split]: https://github.com/dart-lang/dart2js_info/blob/master/bin/library_size_split.dart
398439
[deferred_lib]: https://github.com/dart-lang/dart2js_info/blob/master/bin/deferred_library_check.dart
399440
[deferred_size]: https://github.com/dart-lang/dart2js_info/blob/master/bin/deferred_library_size.dart

bin/diff.dart

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:dart2js_info/src/diff.dart';
6+
import 'package:dart2js_info/src/util.dart';
7+
8+
/// A command-line tool that computes the diff between two info files.
9+
main(List<String> args) async {
10+
if (args.length != 2) {
11+
print('usage: dart2js_info_diff old.info.json new.info.json');
12+
return;
13+
}
14+
var oldInfo = await infoFromFile(args[0]);
15+
var newInfo = await infoFromFile(args[1]);
16+
17+
var diffs = diff(oldInfo, newInfo);
18+
19+
// Categorize the diffs
20+
var adds = <AddDiff>[];
21+
var removals = <RemoveDiff>[];
22+
var sizeChanges = <SizeDiff>[];
23+
var becameDeferred = <DeferredStatusDiff>[];
24+
var becameUndeferred = <DeferredStatusDiff>[];
25+
26+
for (var diff in diffs) {
27+
switch (diff.kind) {
28+
case DiffKind.add:
29+
adds.add(diff as AddDiff);
30+
break;
31+
case DiffKind.remove:
32+
removals.add(diff as RemoveDiff);
33+
break;
34+
case DiffKind.size:
35+
sizeChanges.add(diff as SizeDiff);
36+
break;
37+
case DiffKind.deferred:
38+
var deferredDiff = diff as DeferredStatusDiff;
39+
if (deferredDiff.wasDeferredBefore) {
40+
becameUndeferred.add(deferredDiff);
41+
} else {
42+
becameDeferred.add(deferredDiff);
43+
}
44+
break;
45+
}
46+
}
47+
48+
// TODO(het): Improve this output. Siggi has good suggestions in
49+
// https://github.com/dart-lang/dart2js_info/pull/19
50+
var overallSizeDiff = newInfo.program.size - oldInfo.program.size;
51+
_section('OVERALL SIZE DIFFERENCE');
52+
print('$overallSizeDiff bytes');
53+
print('');
54+
55+
_section('ADDED');
56+
for (var add in adds) {
57+
print('${longName(add.info, useLibraryUri: true)}: ${add.info.size} bytes');
58+
}
59+
print('');
60+
61+
_section('REMOVED');
62+
for (var removal in removals) {
63+
print('${longName(removal.info, useLibraryUri: true)}: '
64+
'${removal.info.size} bytes');
65+
}
66+
print('');
67+
68+
_section('CHANGED SIZE');
69+
for (var sizeChange in sizeChanges) {
70+
print('${longName(sizeChange.info, useLibraryUri: true)}: '
71+
'${sizeChange.sizeDifference} bytes');
72+
}
73+
print('');
74+
75+
_section('BECAME DEFERRED');
76+
for (var diff in becameDeferred) {
77+
print('${longName(diff.info, useLibraryUri: true)}: '
78+
'${diff.info.size} bytes');
79+
}
80+
print('');
81+
82+
_section('NO LONGER DEFERRED');
83+
for (var diff in becameUndeferred) {
84+
print('${longName(diff.info, useLibraryUri: true)}: '
85+
'${diff.info.size} bytes');
86+
}
87+
}
88+
89+
void _section(String title) {
90+
print(title);
91+
print('=' * 72);
92+
}

lib/info.dart

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ abstract class Info {
4646
/// Info of the enclosing element.
4747
Info parent;
4848

49-
dynamic accept(InfoVisitor visitor);
49+
T accept<T>(InfoVisitor<T> visitor);
5050
}
5151

5252
/// Common information used for most kind of elements.
@@ -171,7 +171,7 @@ class AllInfo {
171171

172172
AllInfo();
173173

174-
dynamic accept(InfoVisitor visitor) => visitor.visitAll(this);
174+
T accept<T>(InfoVisitor<T> visitor) => visitor.visitAll(this);
175175
}
176176

177177
class ProgramInfo {
@@ -196,7 +196,7 @@ class ProgramInfo {
196196
this.noSuchMethodEnabled,
197197
this.minified});
198198

199-
dynamic accept(InfoVisitor visitor) => visitor.visitProgram(this);
199+
T accept<T>(InfoVisitor<T> visitor) => visitor.visitProgram(this);
200200
}
201201

202202
/// Info associated with a library element.
@@ -229,7 +229,7 @@ class LibraryInfo extends BasicInfo {
229229

230230
LibraryInfo._(String serializedId) : super._fromId(serializedId);
231231

232-
dynamic accept(InfoVisitor visitor) => visitor.visitLibrary(this);
232+
T accept<T>(InfoVisitor<T> visitor) => visitor.visitLibrary(this);
233233
}
234234

235235
/// Information about an output unit. Normally there is just one for the entire
@@ -244,7 +244,7 @@ class OutputUnitInfo extends BasicInfo {
244244

245245
OutputUnitInfo._(String serializedId) : super._fromId(serializedId);
246246

247-
dynamic accept(InfoVisitor visitor) => visitor.visitOutput(this);
247+
T accept<T>(InfoVisitor<T> visitor) => visitor.visitOutput(this);
248248
}
249249

250250
/// Information about a class element.
@@ -267,7 +267,7 @@ class ClassInfo extends BasicInfo {
267267

268268
ClassInfo._(String serializedId) : super._fromId(serializedId);
269269

270-
dynamic accept(InfoVisitor visitor) => visitor.visitClass(this);
270+
T accept<T>(InfoVisitor<T> visitor) => visitor.visitClass(this);
271271
}
272272

273273
/// Information about a constant value.
@@ -282,7 +282,7 @@ class ConstantInfo extends BasicInfo {
282282

283283
ConstantInfo._(String serializedId) : super._fromId(serializedId);
284284

285-
dynamic accept(InfoVisitor visitor) => visitor.visitConstant(this);
285+
T accept<T>(InfoVisitor<T> visitor) => visitor.visitConstant(this);
286286
}
287287

288288
/// Information about a field element.
@@ -319,7 +319,7 @@ class FieldInfo extends BasicInfo with CodeInfo {
319319

320320
FieldInfo._(String serializedId) : super._fromId(serializedId);
321321

322-
dynamic accept(InfoVisitor visitor) => visitor.visitField(this);
322+
T accept<T>(InfoVisitor<T> visitor) => visitor.visitField(this);
323323
}
324324

325325
/// Information about a typedef declaration.
@@ -332,7 +332,7 @@ class TypedefInfo extends BasicInfo {
332332

333333
TypedefInfo._(String serializedId) : super._fromId(serializedId);
334334

335-
dynamic accept(InfoVisitor visitor) => visitor.visitTypedef(this);
335+
T accept<T>(InfoVisitor<T> visitor) => visitor.visitTypedef(this);
336336
}
337337

338338
/// Information about a function or method.
@@ -396,7 +396,7 @@ class FunctionInfo extends BasicInfo with CodeInfo {
396396

397397
FunctionInfo._(String serializedId) : super._fromId(serializedId);
398398

399-
dynamic accept(InfoVisitor visitor) => visitor.visitFunction(this);
399+
T accept<T>(InfoVisitor<T> visitor) => visitor.visitFunction(this);
400400
}
401401

402402
/// Information about a closure, also known as a local function.
@@ -410,7 +410,7 @@ class ClosureInfo extends BasicInfo {
410410

411411
ClosureInfo._(String serializedId) : super._fromId(serializedId);
412412

413-
dynamic accept(InfoVisitor visitor) => visitor.visitClosure(this);
413+
T accept<T>(InfoVisitor<T> visitor) => visitor.visitClosure(this);
414414
}
415415

416416
/// Information about how a dependency is used.

0 commit comments

Comments
 (0)