Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(324)

Unified Diff: bin/deferred_library_size.dart

Issue 2201903004: add tool to get breakdown of deferred libraries by size (Closed) Base URL: git@github.com:dart-lang/dart2js_info.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « bin/deferred_library_check.dart ('k') | bin/function_size_analysis.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bin/deferred_library_size.dart
diff --git a/bin/deferred_library_size.dart b/bin/deferred_library_size.dart
new file mode 100644
index 0000000000000000000000000000000000000000..7c83f1173e57161b9a85156a88e031780f3efedd
--- /dev/null
+++ b/bin/deferred_library_size.dart
@@ -0,0 +1,75 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// 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.
+
+/// This tool gives a breakdown of code size by deferred part in the program.
+library dart2js_info.bin.deferred_library_size;
+
+import 'dart:math';
+
+import 'package:dart2js_info/info.dart';
+import 'package:dart2js_info/src/util.dart';
+
+main(args) async {
+ // TODO(het): Would be faster to only parse the 'outputUnits' part
+ var info = await infoFromFile(args.first);
+ var sizeByImport = getSizeByImport(info);
+ printSizes(sizeByImport, info.program.size);
+}
+
+class ImportSize {
+ final String import;
+ final int size;
+
+ const ImportSize(this.import, this.size);
+
+ String toString() {
+ return '$import: $size';
+ }
+}
+
+void printSizes(Map<String, int> sizeByImport, int programSize) {
+ var importSizes = <ImportSize>[];
+ sizeByImport.forEach((import, size) {
+ importSizes.add(new ImportSize(import, size));
+ });
+ // Sort by size, largest first.
+ importSizes.sort((a, b) => b.size - a.size);
+ var longest = importSizes.fold('Percent of code deferred'.length,
+ (longest, importSize) => max(longest, importSize.import.length));
+
+ _printRow(label, data, {int width: 15}) {
+ print('${label.toString().padRight(longest + 1)}'
+ '${data.toString().padLeft(width)}');
+ }
+
+ print('');
+ print('Size by library');
+ print('-' * (longest + 16));
+ for (var importSize in importSizes) {
+ _printRow(importSize.import, importSize.size);
Siggi Cherem (dart-lang) 2016/08/02 21:50:26 were you also going to print out the transitive-si
Harry Terkelsen 2016/08/02 21:57:49 Done.
+ }
+ print('-' * (longest + 16));
+
+ var mainChunkSize = sizeByImport['main'];
+ var deferredSize = programSize - mainChunkSize;
+ var percentDeferred = (deferredSize * 100 / programSize).toStringAsFixed(2);
+ _printRow('Main chunk size', mainChunkSize);
+ _printRow('Deferred code size', deferredSize);
+ _printRow('Percent of code deferred', '$percentDeferred%');
+}
+
+Map<String, int> getSizeByImport(AllInfo info) {
+ var sizeByImport = <String, int>{};
+ for (var outputUnit in info.outputUnits) {
+ if (outputUnit.name == 'main' || outputUnit.name == null) {
+ sizeByImport['main'] = outputUnit.size;
+ } else {
+ for (var import in outputUnit.imports) {
+ sizeByImport.putIfAbsent(import, () => 0);
+ sizeByImport[import] += outputUnit.size;
+ }
+ }
+ }
+ return sizeByImport;
+}
« no previous file with comments | « bin/deferred_library_check.dart ('k') | bin/function_size_analysis.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698