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'; | 9 import 'dart:convert'; |
10 import 'dart:io'; | 10 import 'dart:io'; |
11 import 'dart:math' as math; | 11 import 'dart:math' as math; |
12 | 12 |
13 import 'package:dart2js_info/info.dart'; | 13 import 'package:dart2js_info/info.dart'; |
14 import 'package:dart2js_info/src/graph.dart'; | 14 import 'package:dart2js_info/src/graph.dart'; |
15 import 'package:dart2js_info/src/util.dart'; | 15 import 'package:dart2js_info/src/util.dart'; |
16 | 16 |
17 main(args) { | 17 main(args) { |
18 var json = JSON.decode(new File(args[0]).readAsStringSync()); | 18 var json = JSON.decode(new File(args[0]).readAsStringSync()); |
19 var info = new AllInfo.fromJson(json); | 19 var info = new AllInfoJsonCodec().decode(json); |
20 showCodeDistribution(info); | 20 showCodeDistribution(info); |
21 } | 21 } |
22 | 22 |
23 showCodeDistribution(AllInfo info, | 23 showCodeDistribution(AllInfo info, |
24 {bool filter(Info info), bool showLibrarySizes: false}) { | 24 {bool filter(Info info), bool showLibrarySizes: false}) { |
25 var realTotal = info.program.size; | 25 var realTotal = info.program.size; |
26 if (filter == null) filter = (i) => true; | 26 if (filter == null) filter = (i) => true; |
27 var reported = [] | 27 var reported = [] |
28 ..addAll(info.functions.where(filter)) | 28 ..addAll(info.functions.where(filter)) |
29 ..addAll(info.fields.where(filter)); | 29 ..addAll(info.fields.where(filter)); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 | 157 |
158 _showElement(String name, int size, int dominatedSize, int maxSize, int total) { | 158 _showElement(String name, int size, int dominatedSize, int maxSize, int total) { |
159 var percent = (size * 100 / total).toStringAsFixed(2); | 159 var percent = (size * 100 / total).toStringAsFixed(2); |
160 var minPercent = (dominatedSize * 100 / total).toStringAsFixed(2); | 160 var minPercent = (dominatedSize * 100 / total).toStringAsFixed(2); |
161 var maxPercent = (maxSize * 100 / total).toStringAsFixed(2); | 161 var maxPercent = (maxSize * 100 / total).toStringAsFixed(2); |
162 print('${pad(size, 8)} ${pad(percent, 6)}% ' | 162 print('${pad(size, 8)} ${pad(percent, 6)}% ' |
163 '${pad(dominatedSize, 10)} ${pad(minPercent, 6)}% ' | 163 '${pad(dominatedSize, 10)} ${pad(minPercent, 6)}% ' |
164 '${pad(maxSize, 10)} ${pad(maxPercent, 6)}% ' | 164 '${pad(maxSize, 10)} ${pad(maxPercent, 6)}% ' |
165 '$name'); | 165 '$name'); |
166 } | 166 } |
OLD | NEW |