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

Side by Side Diff: bin/code_deps.dart

Issue 2201903004: add tool to get breakdown of deferred libraries by size (Closed) Base URL: git@github.com:dart-lang/dart2js_info.git@master
Patch Set: Created 4 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /// Command-line tool to query for code dependencies. Currently this tool only 5 /// Command-line tool to query for code dependencies. Currently this tool only
6 /// supports the `some_path` query, which gives you the shortest path for how 6 /// supports the `some_path` query, which gives you the shortest path for how
7 /// one function depends on another. 7 /// one function depends on another.
8 /// 8 ///
9 /// You can run this tool as follows: 9 /// You can run this tool as follows:
10 /// ```bash 10 /// ```bash
11 /// pub global activate dart2js_info 11 /// pub global activate dart2js_info
12 /// dart2js_info_code_deps out.js.info.json some_path main foo 12 /// dart2js_info_code_deps out.js.info.json some_path main foo
13 /// ``` 13 /// ```
14 /// 14 ///
15 /// The arguments to the query are regular expressions that can be used to 15 /// The arguments to the query are regular expressions that can be used to
16 /// select a single element in your program. If your regular expression is too 16 /// select a single element in your program. If your regular expression is too
17 /// general and has more than one match, this tool will pick 17 /// general and has more than one match, this tool will pick
18 /// the first match and ignore the rest. Regular expressions are matched against 18 /// the first match and ignore the rest. Regular expressions are matched against
19 /// a fully qualified element name, which includes the library and class name 19 /// a fully qualified element name, which includes the library and class name
20 /// (if any) that contains it. A typical qualified name is of this form: 20 /// (if any) that contains it. A typical qualified name is of this form:
21 /// 21 ///
22 /// libraryName::ClassName.elementName 22 /// libraryName::ClassName.elementName
23 /// 23 ///
24 /// If the name of a function your are looking for is unique enough, it might be 24 /// If the name of a function your are looking for is unique enough, it might be
25 /// sufficient to just write that name as your regular expression. 25 /// sufficient to just write that name as your regular expression.
26 library dart2js_info.bin.code_deps; 26 library dart2js_info.bin.code_deps;
27 27
28 import 'dart:collection'; 28 import 'dart:collection';
29 import 'dart:convert';
30 import 'dart:io'; 29 import 'dart:io';
31 30
32 import 'package:dart2js_info/info.dart'; 31 import 'package:dart2js_info/info.dart';
33 import 'package:dart2js_info/src/graph.dart'; 32 import 'package:dart2js_info/src/graph.dart';
34 import 'package:dart2js_info/src/util.dart'; 33 import 'package:dart2js_info/src/util.dart';
35 34
36 main(args) { 35 main(args) async {
37 if (args.length < 2) { 36 if (args.length < 2) {
38 print('usage: dart2js_info_code_deps path-to.info.json <query>'); 37 print('usage: dart2js_info_code_deps path-to.info.json <query>');
39 print(' where <query> can be:'); 38 print(' where <query> can be:');
40 print(' - some_path <element-regexp-1> <element-regexp-2>'); 39 print(' - some_path <element-regexp-1> <element-regexp-2>');
41 // TODO(sigmund): add other queries, such as 'all_paths'. 40 // TODO(sigmund): add other queries, such as 'all_paths'.
42 exit(1); 41 exit(1);
43 } 42 }
44 43
45 var json; 44 var info = await infoFromFile(args.first);
46 try {
47 json = JSON.decode(new File(args[0]).readAsStringSync());
48 } catch (e) {
49 print('error: could not read ${args[0]}');
50 exit(1);
51 }
52 var info = new AllInfoJsonCodec().decode(json);
53 var graph = graphFromInfo(info); 45 var graph = graphFromInfo(info);
54 46
55 var queryName = args[1]; 47 var queryName = args[1];
56 if (queryName == 'some_path') { 48 if (queryName == 'some_path') {
57 if (args.length < 4) { 49 if (args.length < 4) {
58 print('missing arguments for `some_path`'); 50 print('missing arguments for `some_path`');
59 exit(1); 51 exit(1);
60 } 52 }
61 var source = info.functions 53 var source = info.functions
62 .firstWhere(_longNameMatcher(new RegExp(args[2])), orElse: () => null); 54 .firstWhere(_longNameMatcher(new RegExp(args[2])), orElse: () => null);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 if (seen.containsKey(neighbor)) continue; 112 if (seen.containsKey(neighbor)) continue;
121 seen[neighbor] = node; 113 seen[neighbor] = node;
122 queue.addLast(neighbor); 114 queue.addLast(neighbor);
123 } 115 }
124 } 116 }
125 return []; 117 return [];
126 } 118 }
127 } 119 }
128 120
129 _longNameMatcher(RegExp regexp) => (e) => regexp.hasMatch(longName(e)); 121 _longNameMatcher(RegExp regexp) => (e) => regexp.hasMatch(longName(e));
OLDNEW
« no previous file with comments | « README.md ('k') | bin/coverage_log_server.dart » ('j') | bin/deferred_library_size.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698