OLD | NEW |
(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 reports how code is divided among deferred chunks. |
| 6 library dart2js_info.bin.deferred_library_size; |
| 7 |
| 8 import 'dart:io'; |
| 9 import 'package:dart2js_info/info.dart'; |
| 10 import 'package:dart2js_info/src/util.dart'; |
| 11 |
| 12 main(args) async { |
| 13 AllInfo info = await infoFromFile(args.first); |
| 14 |
| 15 Map<OutputUnitInfo, Map<LibraryInfo, List<BasicInfo>>> hunkMembers = {}; |
| 16 Map<LibraryInfo, Set<OutputUnitInfo>> libToHunks = {}; |
| 17 void register(BasicInfo info) { |
| 18 var unit = info.outputUnit; |
| 19 var lib = _libOf(info); |
| 20 if (lib == null) return; |
| 21 libToHunks.putIfAbsent(lib, () => new Set()).add(unit); |
| 22 hunkMembers.putIfAbsent(unit, () => {}) |
| 23 .putIfAbsent(lib, () => []).add(info); |
| 24 } |
| 25 |
| 26 info.functions.forEach(register); |
| 27 info.classes.forEach(register); |
| 28 info.fields.forEach(register); |
| 29 info.closures.forEach(register); |
| 30 |
| 31 var dir = Directory.current.path; |
| 32 hunkMembers.forEach((unit, map) { |
| 33 print('Output unit ${unit.name ?? "main"}:'); |
| 34 if (unit.name == null || unit.name == 'main') { |
| 35 print(' loaded by default'); |
| 36 } else { |
| 37 print(' loaded by importing: ${unit.imports}'); |
| 38 } |
| 39 |
| 40 print(' contains:'); |
| 41 map.forEach((lib, elements) { |
| 42 var uri = lib.uri; |
| 43 var shortUri = (uri.scheme == 'file' && uri.path.startsWith(dir)) |
| 44 ? uri.path.substring(dir.length + 1) |
| 45 : '$uri'; |
| 46 |
| 47 // If the entire library is in one chunk, just report the library name |
| 48 // otherwise report which functions are on this chunk. |
| 49 if (libToHunks[lib].length == 1) { |
| 50 print(' - $shortUri'); |
| 51 } else { |
| 52 print(' - $shortUri:'); |
| 53 for (var e in elements) { |
| 54 print(' - ${kindToString(e.kind)} ${e.name}'); |
| 55 } |
| 56 } |
| 57 }); |
| 58 print(''); |
| 59 }); |
| 60 } |
| 61 |
| 62 _libOf(e) => e is LibraryInfo || e == null ? e : _libOf(e.parent); |
OLD | NEW |