Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(896)

Unified Diff: bin/deferred_library_layout.dart

Issue 2469963002: Add defer-layout tool. (Closed)
Patch Set: Support code split in multiple chunks Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« README.md ('K') | « README.md ('k') | pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bin/deferred_library_layout.dart
diff --git a/bin/deferred_library_layout.dart b/bin/deferred_library_layout.dart
new file mode 100644
index 0000000000000000000000000000000000000000..12090bce3d90f63589f70c4608fcc18e139f8d13
--- /dev/null
+++ b/bin/deferred_library_layout.dart
@@ -0,0 +1,65 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+/// This tool reports how code is divided among deferred chunks.
+library dart2js_info.bin.deferred_library_size;
+
+import 'dart:io';
+import 'package:dart2js_info/info.dart';
+import 'package:dart2js_info/src/util.dart';
+
+main(args) async {
+ AllInfo info = await infoFromFile(args.first);
+
+ 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
+ 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.
+ void register(BasicInfo info) {
+ 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.
+ var unit = info.outputUnit;
+ var lib = _libOf(info);
+ if (lib == null) return;
+ libToHunks.putIfAbsent(lib, () => new Set()).add(unit);
+ hunkMembers.putIfAbsent(unit, () => {})
+ .putIfAbsent(lib, () => []).add(info);
+ }
+
+ info.libraries.forEach(register);
+ info.functions.forEach(register);
+ info.typedefs.forEach(register);
+ info.classes.forEach(register);
+ info.fields.forEach(register);
+ info.closures.forEach(register);
+
+ var dir = Directory.current.path;
+ hunkMembers.forEach((unit, map) {
+ print('Output unit ${unit.name ?? "main"}:');
+ if (unit.name == null || unit.name == 'main') {
+ print(' loaded by default');
+ } else {
+ print(' loaded by importing: ${unit.imports}');
+ }
+
+ print(' contains:');
+ map.forEach((lib, elements) {
+ var uri = lib.uri;
+ var shortUri = (uri.scheme == 'file' && uri.path.startsWith(dir))
+ ? uri.path.substring(dir.length + 1)
+ : '$uri';
+
+ // If the entire library is in one chunk, just report the library name
+ // otherwise report which functions are on this chunk.
+ if (libToHunks[lib].length == 1) {
+ print(' - $shortUri');
+ } else {
+ print(' - $shortUri:');
+ for (var e in elements) {
+ print(' - ${kindToString(e.kind)} ${e.name}');
+ }
+ }
+ });
+ print('');
+ });
+}
+
+_libOf(e) => e is LibraryInfo || e == null ? e : _libOf(e.parent);
« README.md ('K') | « README.md ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698