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

Unified Diff: pkg/compiler/tool/library_size_split.dart

Issue 1287543002: dart2js: add an example script that shows the distribution of code among (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 months 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
« no previous file with comments | « pkg/compiler/pubspec.yaml ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/tool/library_size_split.dart
diff --git a/pkg/compiler/tool/library_size_split.dart b/pkg/compiler/tool/library_size_split.dart
new file mode 100644
index 0000000000000000000000000000000000000000..1812a1e041a4a385a6fa6fbf09f92ac2aa72a79e
--- /dev/null
+++ b/pkg/compiler/tool/library_size_split.dart
@@ -0,0 +1,80 @@
+// Copyright (c) 2015, 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.
+
+/// Command-line tool to show the size distribution of generated code among
+/// libraries. Libraries can be grouped using regular expressions. See
+/// [defaultGrouping] for an example.
+library compiler.tool.library_size_split;
+
+import 'dart:convert';
+import 'dart:io';
+import 'dart:math' show max;
+
+import 'package:compiler/src/info/info.dart';
+import 'package:yaml/yaml.dart';
+
+main(args) {
+ if (args.length < 1) {
+ print('usage: dart tool/library_size_split.dart '
+ 'path-to-info.json [grouping.yaml]');
+ exit(1);
+ }
+
+ var filename = args[0];
+ var json = JSON.decode(new File(filename).readAsStringSync());
+ var info = AllInfo.parseFromJson(json);
+
+ var groupingText = args.length > 1
+ ? new File(args[1]).readAsStringSync() : defaultGrouping;
+ var groupingYaml = loadYaml(groupingText);
+ var groups = {};
+ for (var group in groupingYaml['groups']) {
+ var name = group['name'];
Harry Terkelsen 2015/08/11 01:43:39 so you can only omit the name for one group?
Siggi Cherem (dart-lang) 2015/08/11 21:08:00 Good catch, that was not intentional. I changed th
+ groups[name] = new RegExp(group['regexp']);
+ }
+
+ var sizes = {};
+ for (LibraryInfo lib in info.libraries) {
+ groups.forEach((name, RegExp regexp) {
+ var m = regexp.firstMatch('${lib.uri}');
+ if (m != null) {
+ if (name == null) name = m.group(1);
+ if (name == null) name = m.group(0);
+ sizes.putIfAbsent(name, () => 0);
+ sizes[name] += lib.size;
+ }
+ });
+ }
+
+ var all = sizes.keys.toList();
+ all.sort((a, b) => sizes[a] - sizes[b]);
+ var realTotal = info.program.size;
+ var longest = all.fold(0, (count, value) => max(count, value.length));
+ for (var name in all) {
+ var size = sizes[name];
+ var percent = (size * 100 / realTotal).toStringAsFixed(2);
+ print(' ${_pad(name, longest + 1, right: true)}'
+ ' ${_pad(size, 8)} ${_pad(percent, 6)}%');
+ }
+}
+
+_pad(value, n, {bool right: false}) {
+ var s = '$value';
+ if (s.length >= n) return s;
+ var pad = ' ' * (n - s.length);
+ return right ? '$s$pad' : '$pad$s';
+}
+
+/// Example grouping specification: a yaml format containing a list of
+/// name/regexp pairs. If the name is omitted, it is assume to be group(1) of
Harry Terkelsen 2015/08/11 01:43:39 or group(0) if there is only 1 group
Siggi Cherem (dart-lang) 2015/08/11 21:08:00 Done.
+/// the regexp.
+const defaultGrouping = r"""
+groups:
+- { name: "TOTAL", regexp: ".*" }
+- { name: "Loose files", regexp: "file://.*" }
+- { name: "All packages", regexp: "package:.*" }
+- { name: "Core libs", regexp: "dart:.*" }
+# We omitted `name` to extract the package name from the regexp directly.
+- { regexp: "package:([^/]*)" }
+""";
« no previous file with comments | « pkg/compiler/pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698