Chromium Code Reviews| 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<OutputUnifInfo, Map<LibraryInfo, List<BasicInfo>>> hunkMembers = {}; | |
|
Harry Terkelsen
2016/11/01 23:18:29
s/OutputUnifInfo/OutputUnitInfo/
Siggi Cherem (dart-lang)
2016/11/01 23:26:55
ha - checked mode didn't get those because the und
| |
| 16 Map<LibraryInfo, Set<OuputUnitInfo>> libToHunks = {}; | |
|
Harry Terkelsen
2016/11/01 23:18:29
s/OuputUnitInfo/OutputUnitInfo/
Siggi Cherem (dart-lang)
2016/11/01 23:26:55
Done.
| |
| 17 void register(BasicInfo info) { | |
| 18 if (info.outputUnit == null) return; | |
|
Harry Terkelsen
2016/11/01 23:18:29
do you see this in practice? I think all basicinfo
Siggi Cherem (dart-lang)
2016/11/01 23:26:54
Yes, but I think only for library infos. Maybe we
Harry Terkelsen
2016/11/01 23:30:39
I think we should skip libraries and the null chec
Siggi Cherem (dart-lang)
2016/11/01 23:37:42
Done.
| |
| 19 var unit = info.outputUnit; | |
| 20 var lib = _libOf(info); | |
| 21 if (lib == null) return; | |
| 22 libToHunks.putIfAbsent(lib, () => new Set()).add(unit); | |
| 23 hunkMembers.putIfAbsent(unit, () => {}) | |
| 24 .putIfAbsent(lib, () => []).add(info); | |
| 25 } | |
| 26 | |
| 27 info.libraries.forEach(register); | |
| 28 info.functions.forEach(register); | |
| 29 info.typedefs.forEach(register); | |
| 30 info.classes.forEach(register); | |
| 31 info.fields.forEach(register); | |
| 32 info.closures.forEach(register); | |
| 33 | |
| 34 var dir = Directory.current.path; | |
| 35 hunkMembers.forEach((unit, map) { | |
| 36 print('Output unit ${unit.name ?? "main"}:'); | |
| 37 if (unit.name == null || unit.name == 'main') { | |
| 38 print(' loaded by default'); | |
| 39 } else { | |
| 40 print(' loaded by importing: ${unit.imports}'); | |
| 41 } | |
| 42 | |
| 43 print(' contains:'); | |
| 44 map.forEach((lib, elements) { | |
| 45 var uri = lib.uri; | |
| 46 var shortUri = (uri.scheme == 'file' && uri.path.startsWith(dir)) | |
| 47 ? uri.path.substring(dir.length + 1) | |
| 48 : '$uri'; | |
| 49 | |
| 50 // If the entire library is in one chunk, just report the library name | |
| 51 // otherwise report which functions are on this chunk. | |
| 52 if (libToHunks[lib].length == 1) { | |
| 53 print(' - $shortUri'); | |
| 54 } else { | |
| 55 print(' - $shortUri:'); | |
| 56 for (var e in elements) { | |
| 57 print(' - ${kindToString(e.kind)} ${e.name}'); | |
| 58 } | |
| 59 } | |
| 60 }); | |
| 61 print(''); | |
| 62 }); | |
| 63 } | |
| 64 | |
| 65 _libOf(e) => e is LibraryInfo || e == null ? e : _libOf(e.parent); | |
| OLD | NEW |