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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « pkg/compiler/pubspec.yaml ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 /// Command-line tool to show the size distribution of generated code among
6 /// libraries. Libraries can be grouped using regular expressions. See
7 /// [defaultGrouping] for an example.
8 library compiler.tool.library_size_split;
9
10 import 'dart:convert';
11 import 'dart:io';
12 import 'dart:math' show max;
13
14 import 'package:compiler/src/info/info.dart';
15 import 'package:yaml/yaml.dart';
16
17 main(args) {
18 if (args.length < 1) {
19 print('usage: dart tool/library_size_split.dart '
20 'path-to-info.json [grouping.yaml]');
21 exit(1);
22 }
23
24 var filename = args[0];
25 var json = JSON.decode(new File(filename).readAsStringSync());
26 var info = AllInfo.parseFromJson(json);
27
28 var groupingText = args.length > 1
29 ? new File(args[1]).readAsStringSync() : defaultGrouping;
30 var groupingYaml = loadYaml(groupingText);
31 var groups = {};
32 for (var group in groupingYaml['groups']) {
33 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
34 groups[name] = new RegExp(group['regexp']);
35 }
36
37 var sizes = {};
38 for (LibraryInfo lib in info.libraries) {
39 groups.forEach((name, RegExp regexp) {
40 var m = regexp.firstMatch('${lib.uri}');
41 if (m != null) {
42 if (name == null) name = m.group(1);
43 if (name == null) name = m.group(0);
44 sizes.putIfAbsent(name, () => 0);
45 sizes[name] += lib.size;
46 }
47 });
48 }
49
50 var all = sizes.keys.toList();
51 all.sort((a, b) => sizes[a] - sizes[b]);
52 var realTotal = info.program.size;
53 var longest = all.fold(0, (count, value) => max(count, value.length));
54 for (var name in all) {
55 var size = sizes[name];
56 var percent = (size * 100 / realTotal).toStringAsFixed(2);
57 print(' ${_pad(name, longest + 1, right: true)}'
58 ' ${_pad(size, 8)} ${_pad(percent, 6)}%');
59 }
60 }
61
62 _pad(value, n, {bool right: false}) {
63 var s = '$value';
64 if (s.length >= n) return s;
65 var pad = ' ' * (n - s.length);
66 return right ? '$s$pad' : '$pad$s';
67 }
68
69 /// Example grouping specification: a yaml format containing a list of
70 /// 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.
71 /// the regexp.
72 const defaultGrouping = r"""
73 groups:
74 - { name: "TOTAL", regexp: ".*" }
75 - { name: "Loose files", regexp: "file://.*" }
76 - { name: "All packages", regexp: "package:.*" }
77 - { name: "Core libs", regexp: "dart:.*" }
78 # We omitted `name` to extract the package name from the regexp directly.
79 - { regexp: "package:([^/]*)" }
80 """;
OLDNEW
« 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