Skip to content

Commit

Permalink
Add --summary option to diff tool (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry Terkelsen authored Sep 17, 2018
1 parent 85f0aba commit 3c01003
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.5.11

* Added `--summary` option to `dart2js_info_diff` tool.

## 0.5.10

* Set max SDK version to `<3.0.0`, and adjust other dependencies.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ as follows:

```console
$ pub global activate dart2js_info # only needed once
$ dart2js_info_diff old.js.info.json new.js.info.json
$ dart2js_info_diff old.js.info.json new.js.info.json [--summary]
```

The tool gives a breakdown of the difference between the two info files.
Expand Down
62 changes: 60 additions & 2 deletions bin/diff.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,28 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:dart2js_info/info.dart';
import 'package:dart2js_info/src/diff.dart';
import 'package:dart2js_info/src/util.dart';

/// A command-line tool that computes the diff between two info files.
main(List<String> args) async {
if (args.length != 2) {
print('usage: dart2js_info_diff old.info.json new.info.json');
if (args.length < 2 || args.length > 3) {
print('usage: dart2js_info_diff old.info.json new.info.json [--summary]');
return;
}

var oldInfo = await infoFromFile(args[0]);
var newInfo = await infoFromFile(args[1]);
var summary = false;
if (args.length == 3) {
if (args[2] == "--summary") {
summary = true;
} else {
print('Unrecognized argument: ${args[2]}');
return;
}
}

var diffs = diff(oldInfo, newInfo);

Expand Down Expand Up @@ -45,6 +56,53 @@ main(List<String> args) async {
}
}

if (summary) {
reportSummary(oldInfo, newInfo, adds, removals, sizeChanges, becameDeferred,
becameUndeferred);
} else {
reportFull(oldInfo, newInfo, adds, removals, sizeChanges, becameDeferred,
becameUndeferred);
}
}

void reportSummary(
AllInfo oldInfo,
AllInfo newInfo,
List<AddDiff> adds,
List<RemoveDiff> removals,
List<SizeDiff> sizeChanges,
List<DeferredStatusDiff> becameDeferred,
List<DeferredStatusDiff> becameUndeferred) {
var overallSizeDiff = newInfo.program.size - oldInfo.program.size;
print('total_size_difference $overallSizeDiff');

var noLongerDeferred = 0;
for (var diff in becameUndeferred) {
noLongerDeferred += diff.info.size;
}
print('no_longer_deferred $noLongerDeferred');

var totalAdded = 0;
for (var diff in adds) {
totalAdded += diff.info.size;
}
print('total_added $totalAdded');

var totalRemoved = 0;
for (var diff in removals) {
totalRemoved += diff.info.size;
}
print('total_removed $totalRemoved');
}

void reportFull(
AllInfo oldInfo,
AllInfo newInfo,
List<AddDiff> adds,
List<RemoveDiff> removals,
List<SizeDiff> sizeChanges,
List<DeferredStatusDiff> becameDeferred,
List<DeferredStatusDiff> becameUndeferred) {
// TODO(het): Improve this output. Siggi has good suggestions in
// https://github.com/dart-lang/dart2js_info/pull/19
var overallSizeDiff = newInfo.program.size - oldInfo.program.size;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: dart2js_info
version: 0.5.10
version: 0.5.11

description: >
Libraries and tools to process data produced when running dart2js with
Expand Down

0 comments on commit 3c01003

Please sign in to comment.