| 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 combined information from dump-info and | 5 /// Command-line tool presenting combined information from dump-info and |
| 6 /// coverage data. | 6 /// coverage data. |
| 7 /// | 7 /// |
| 8 /// This tool requires two input files an `.info.json` and a | 8 /// This tool requires two input files an `.info.json` and a |
| 9 /// `.coverage.json` file. To produce these files you need to follow these | 9 /// `.coverage.json` file. To produce these files you need to follow these |
| 10 /// steps: | 10 /// steps: |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 /// * Shut down the coverage server (Ctrl-C) | 32 /// * Shut down the coverage server (Ctrl-C) |
| 33 /// | 33 /// |
| 34 /// * Finally, run this tool. | 34 /// * Finally, run this tool. |
| 35 library compiler.tool.live_code_size_analysis; | 35 library compiler.tool.live_code_size_analysis; |
| 36 | 36 |
| 37 import 'dart:convert'; | 37 import 'dart:convert'; |
| 38 import 'dart:io'; | 38 import 'dart:io'; |
| 39 | 39 |
| 40 import 'package:dart2js_info/info.dart'; | 40 import 'package:dart2js_info/info.dart'; |
| 41 import 'package:dart2js_info/src/util.dart'; | 41 import 'package:dart2js_info/src/util.dart'; |
| 42 |
| 42 import 'function_size_analysis.dart'; | 43 import 'function_size_analysis.dart'; |
| 43 | 44 |
| 44 main(args) { | 45 main(args) async { |
| 45 if (args.length < 2) { | 46 if (args.length < 2) { |
| 46 print('usage: dart tool/live_code_size_analysis.dart path-to-info.json ' | 47 print('usage: dart tool/live_code_size_analysis.dart path-to-info.json ' |
| 47 'path-to-coverage.json [-v]'); | 48 'path-to-coverage.json [-v]'); |
| 48 exit(1); | 49 exit(1); |
| 49 } | 50 } |
| 50 | 51 |
| 51 var json = JSON.decode(new File(args[0]).readAsStringSync()); | 52 var info = await infoFromFile(args.first); |
| 52 var info = new AllInfoJsonCodec().decode(json); | |
| 53 var coverage = JSON.decode(new File(args[1]).readAsStringSync()); | 53 var coverage = JSON.decode(new File(args[1]).readAsStringSync()); |
| 54 var verbose = args.length > 2 && args[2] == '-v'; | 54 var verbose = args.length > 2 && args[2] == '-v'; |
| 55 | 55 |
| 56 int realTotal = info.program.size; | 56 int realTotal = info.program.size; |
| 57 int totalLib = info.libraries.fold(0, (n, lib) => n + lib.size); | 57 int totalLib = info.libraries.fold(0, (n, lib) => n + lib.size); |
| 58 | 58 |
| 59 int totalCode = 0; | 59 int totalCode = 0; |
| 60 int reachableCode = 0; | 60 int reachableCode = 0; |
| 61 List<Info> unused = []; | 61 List<Info> unused = []; |
| 62 | 62 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 } | 110 } |
| 111 | 111 |
| 112 _showHeader(String msg, String header1, String header2) { | 112 _showHeader(String msg, String header1, String header2) { |
| 113 print(' ${pad(msg, 30, right: true)} ${pad(header1, 8)} ${pad(header2, 6)}'); | 113 print(' ${pad(msg, 30, right: true)} ${pad(header1, 8)} ${pad(header2, 6)}'); |
| 114 } | 114 } |
| 115 | 115 |
| 116 _show(String msg, int size, int total) { | 116 _show(String msg, int size, int total) { |
| 117 var percent = (size * 100 / total).toStringAsFixed(2); | 117 var percent = (size * 100 / total).toStringAsFixed(2); |
| 118 print(' ${pad(msg, 30, right: true)} ${pad(size, 8)} ${pad(percent, 6)}%'); | 118 print(' ${pad(msg, 30, right: true)} ${pad(size, 8)} ${pad(percent, 6)}%'); |
| 119 } | 119 } |
| OLD | NEW |