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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « bin/deferred_library_check.dart ('k') | bin/function_size_analysis.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016, 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 /// This tool gives a breakdown of code size by deferred part in the program.
6 library dart2js_info.bin.deferred_library_size;
7
8 import 'dart:math';
9
10 import 'package:dart2js_info/info.dart';
11 import 'package:dart2js_info/src/util.dart';
12
13 main(args) async {
14 // TODO(het): Would be faster to only parse the 'outputUnits' part
15 var info = await infoFromFile(args.first);
16 var sizeByImport = getSizeByImport(info);
17 printSizes(sizeByImport, info.program.size);
18 }
19
20 class ImportSize {
21 final String import;
22 final int size;
23
24 const ImportSize(this.import, this.size);
25
26 String toString() {
27 return '$import: $size';
28 }
29 }
30
31 void printSizes(Map<String, int> sizeByImport, int programSize) {
32 var importSizes = <ImportSize>[];
33 sizeByImport.forEach((import, size) {
34 importSizes.add(new ImportSize(import, size));
35 });
36 // Sort by size, largest first.
37 importSizes.sort((a, b) => b.size - a.size);
38 var longest = importSizes.fold('Percent of code deferred'.length,
39 (longest, importSize) => max(longest, importSize.import.length));
40
41 _printRow(label, data, {int width: 15}) {
42 print('${label.toString().padRight(longest + 1)}'
43 '${data.toString().padLeft(width)}');
44 }
45
46 print('');
47 print('Size by library');
48 print('-' * (longest + 16));
49 for (var importSize in importSizes) {
50 _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.
51 }
52 print('-' * (longest + 16));
53
54 var mainChunkSize = sizeByImport['main'];
55 var deferredSize = programSize - mainChunkSize;
56 var percentDeferred = (deferredSize * 100 / programSize).toStringAsFixed(2);
57 _printRow('Main chunk size', mainChunkSize);
58 _printRow('Deferred code size', deferredSize);
59 _printRow('Percent of code deferred', '$percentDeferred%');
60 }
61
62 Map<String, int> getSizeByImport(AllInfo info) {
63 var sizeByImport = <String, int>{};
64 for (var outputUnit in info.outputUnits) {
65 if (outputUnit.name == 'main' || outputUnit.name == null) {
66 sizeByImport['main'] = outputUnit.size;
67 } else {
68 for (var import in outputUnit.imports) {
69 sizeByImport.putIfAbsent(import, () => 0);
70 sizeByImport[import] += outputUnit.size;
71 }
72 }
73 }
74 return sizeByImport;
75 }
OLDNEW
« 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