OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /// This tool gives a breakdown of code size by deferred part in the program. | 5 /// This tool gives a breakdown of code size by deferred part in the program. |
6 library dart2js_info.bin.deferred_library_size; | 6 library dart2js_info.bin.deferred_library_size; |
7 | 7 |
8 import 'dart:math'; | 8 import 'dart:math'; |
9 | 9 |
10 import 'package:dart2js_info/info.dart'; | 10 import 'package:dart2js_info/info.dart'; |
(...skipping 17 matching lines...) Expand all Loading... |
28 } | 28 } |
29 } | 29 } |
30 | 30 |
31 void printSizes(Map<String, int> sizeByImport, int programSize) { | 31 void printSizes(Map<String, int> sizeByImport, int programSize) { |
32 var importSizes = <ImportSize>[]; | 32 var importSizes = <ImportSize>[]; |
33 sizeByImport.forEach((import, size) { | 33 sizeByImport.forEach((import, size) { |
34 importSizes.add(new ImportSize(import, size)); | 34 importSizes.add(new ImportSize(import, size)); |
35 }); | 35 }); |
36 // Sort by size, largest first. | 36 // Sort by size, largest first. |
37 importSizes.sort((a, b) => b.size - a.size); | 37 importSizes.sort((a, b) => b.size - a.size); |
38 var longest = importSizes.fold('Percent of code deferred'.length, | 38 int longest = importSizes.fold('Percent of code deferred'.length, |
39 (longest, importSize) => max(longest, importSize.import.length)); | 39 (longest, importSize) => max(longest, importSize.import.length)); |
40 | 40 |
41 _printRow(label, data, {int width: 15}) { | 41 _printRow(label, data, {int width: 15}) { |
42 print('${label.toString().padRight(longest + 1)}' | 42 print('${label.toString().padRight(longest + 1)}' |
43 '${data.toString().padLeft(width)}'); | 43 '${data.toString().padLeft(width)}'); |
44 } | 44 } |
45 | 45 |
46 print(''); | 46 print(''); |
47 print('Size by library'); | 47 print('Size by library'); |
48 print('-' * (longest + 16)); | 48 print('-' * (longest + 16)); |
(...skipping 18 matching lines...) Expand all Loading... |
67 sizeByImport['main'] = outputUnit.size; | 67 sizeByImport['main'] = outputUnit.size; |
68 } else { | 68 } else { |
69 for (var import in outputUnit.imports) { | 69 for (var import in outputUnit.imports) { |
70 sizeByImport.putIfAbsent(import, () => 0); | 70 sizeByImport.putIfAbsent(import, () => 0); |
71 sizeByImport[import] += outputUnit.size; | 71 sizeByImport[import] += outputUnit.size; |
72 } | 72 } |
73 } | 73 } |
74 } | 74 } |
75 return sizeByImport; | 75 return sizeByImport; |
76 } | 76 } |
OLD | NEW |