OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /// Command-line tool presenting how much each function contributes to the total | 5 /// Command-line tool presenting how much each function contributes to the total |
6 /// code. | 6 /// code. |
7 library compiler.tool.live_code_size_analysis; | 7 library compiler.tool.live_code_size_analysis; |
8 | 8 |
9 import 'dart:convert'; | |
10 import 'dart:io'; | |
11 import 'dart:math' as math; | 9 import 'dart:math' as math; |
12 | 10 |
13 import 'package:dart2js_info/info.dart'; | 11 import 'package:dart2js_info/info.dart'; |
14 import 'package:dart2js_info/src/graph.dart'; | 12 import 'package:dart2js_info/src/graph.dart'; |
15 import 'package:dart2js_info/src/util.dart'; | 13 import 'package:dart2js_info/src/util.dart'; |
16 | 14 |
17 main(args) { | 15 main(args) async { |
18 var json = JSON.decode(new File(args[0]).readAsStringSync()); | 16 var info = await infoFromFile(args.first); |
19 var info = new AllInfoJsonCodec().decode(json); | |
20 showCodeDistribution(info); | 17 showCodeDistribution(info); |
21 } | 18 } |
22 | 19 |
23 showCodeDistribution(AllInfo info, | 20 showCodeDistribution(AllInfo info, |
24 {bool filter(Info info), bool showLibrarySizes: false}) { | 21 {bool filter(Info info), bool showLibrarySizes: false}) { |
25 var realTotal = info.program.size; | 22 var realTotal = info.program.size; |
26 if (filter == null) filter = (i) => true; | 23 if (filter == null) filter = (i) => true; |
27 var reported = [] | 24 var reported = [] |
28 ..addAll(info.functions.where(filter)) | 25 ..addAll(info.functions.where(filter)) |
29 ..addAll(info.fields.where(filter)); | 26 ..addAll(info.fields.where(filter)); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 | 154 |
158 _showElement(String name, int size, int dominatedSize, int maxSize, int total) { | 155 _showElement(String name, int size, int dominatedSize, int maxSize, int total) { |
159 var percent = (size * 100 / total).toStringAsFixed(2); | 156 var percent = (size * 100 / total).toStringAsFixed(2); |
160 var minPercent = (dominatedSize * 100 / total).toStringAsFixed(2); | 157 var minPercent = (dominatedSize * 100 / total).toStringAsFixed(2); |
161 var maxPercent = (maxSize * 100 / total).toStringAsFixed(2); | 158 var maxPercent = (maxSize * 100 / total).toStringAsFixed(2); |
162 print('${pad(size, 8)} ${pad(percent, 6)}% ' | 159 print('${pad(size, 8)} ${pad(percent, 6)}% ' |
163 '${pad(dominatedSize, 10)} ${pad(minPercent, 6)}% ' | 160 '${pad(dominatedSize, 10)} ${pad(minPercent, 6)}% ' |
164 '${pad(maxSize, 10)} ${pad(maxPercent, 6)}% ' | 161 '${pad(maxSize, 10)} ${pad(maxPercent, 6)}% ' |
165 '$name'); | 162 '$name'); |
166 } | 163 } |
OLD | NEW |