| OLD | NEW |
| 1 # Dart2js Info | 1 # Dart2js Info |
| 2 | 2 |
| 3 This package contains libraries and tools you can use to process `.info.json` | 3 This package contains libraries and tools you can use to process `.info.json` |
| 4 files, which are produced when running dart2js with `--dump-info`. | 4 files, which are produced when running dart2js with `--dump-info`. |
| 5 | 5 |
| 6 The `.info.json` files contain data about each element included in | 6 The `.info.json` files contain data about each element included in |
| 7 the output of your program. The data includes information such as: | 7 the output of your program. The data includes information such as: |
| 8 | 8 |
| 9 * the size that each function adds to the `.dart.js` output, | 9 * the size that each function adds to the `.dart.js` output, |
| 10 * dependencies between functions, | 10 * dependencies between functions, |
| 11 * how the code is clustered when using deferred libraries, and | 11 * how the code is clustered when using deferred libraries, and |
| 12 * the declared and inferred type of each function argument. | 12 * the declared and inferred type of each function argument. |
| 13 | 13 |
| 14 All of this information can help you understand why some piece of code is | 14 All of this information can help you understand why some piece of code is |
| 15 included in your compiled application, and how far was dart2js able to | 15 included in your compiled application, and how far was dart2js able to |
| 16 understand your code. This data can help you make changes to improve the quality | 16 understand your code. This data can help you make changes to improve the quality |
| 17 and size of your framework or app. | 17 and size of your framework or app. |
| 18 | 18 |
| 19 This package focuses on gathering libraries and tools that summarize all of that | 19 This package focuses on gathering libraries and tools that summarize all of that |
| 20 information. Bear in mind that even with all these tools, it is not trivial to | 20 information. Bear in mind that even with all these tools, it is not trivial to |
| 21 isolate code-size issues. We just hope that these tools make things a bit | 21 isolate code-size issues. We just hope that these tools make things a bit |
| 22 earier. | 22 easier. |
| 23 | 23 |
| 24 ## Status | 24 ## Status |
| 25 | 25 |
| 26 [](https://trav
is-ci.org/dart-lang/dart2js_info) | 26 [](https://trav
is-ci.org/dart-lang/dart2js_info) |
| 27 | 27 |
| 28 Currently, most tools available here can be used to analyze code-size and | 28 Currently, most tools available here can be used to analyze code-size and |
| 29 attibution of code-size to different parts of your app. With time, we hope to | 29 attribution of code-size to different parts of your app. With time, we hope to |
| 30 add more data to the `.info.json` files, and include better tools to help | 30 add more data to the `.info.json` files, and include better tools to help |
| 31 understand the results of type inference. | 31 understand the results of type inference. |
| 32 | 32 |
| 33 This package is still in flux and we might make breaking changes at any time. | 33 This package is still in flux and we might make breaking changes at any time. |
| 34 Our current goal is not to provide a stable API, we mainly want to expose the | 34 Our current goal is not to provide a stable API, we mainly want to expose the |
| 35 functionality and iterate on it. We recommend that you pin a specific version | 35 functionality and iterate on it. We recommend that you pin a specific version |
| 36 of this package and update when needed. | 36 of this package and update when needed. |
| 37 | 37 |
| 38 ## Info API | 38 ## Info API |
| 39 | 39 |
| 40 [AllInfo][AllInfo] exposes a Dart representation of the `.info.json` files. | 40 [AllInfo][AllInfo] exposes a Dart representation of the `.info.json` files. |
| 41 You can parse the information using `AllInfo.parseFromJson`. For example: | 41 You can parse the information using `AllInfo.fromJson`. For example: |
| 42 | 42 |
| 43 ```dart | 43 ```dart |
| 44 import 'dart:convert'; | 44 import 'dart:convert'; |
| 45 import 'dart:io'; | 45 import 'dart:io'; |
| 46 | 46 |
| 47 import 'package:dart2js_info/info.dart'; | 47 import 'package:dart2js_info/info.dart'; |
| 48 | 48 |
| 49 main(args) { | 49 main(args) { |
| 50 var infoPath = args[0]; | 50 var infoPath = args[0]; |
| 51 var json = JSON.decode(new File(infoPath).readAsStringSync()); | 51 var json = JSON.decode(new File(infoPath).readAsStringSync()); |
| 52 var info = AllInfo.parseFromJson(json); | 52 var info = new AllInfo.fromJson(json); |
| 53 ... | 53 ... |
| 54 } |
| 54 ``` | 55 ``` |
| 55 | 56 |
| 56 ## Available tools | 57 ## Available tools |
| 57 | 58 |
| 58 The following tools are a available today: | 59 The following tools are a available today: |
| 59 | 60 |
| 60 * [`code_deps.dart`][code_deps]: simple tool that can answer queries about the | 61 * [`code_deps.dart`][code_deps]: simple tool that can answer queries about the |
| 61 dependency between functions and fields in your program. Currently it only | 62 dependency between functions and fields in your program. Currently it only |
| 62 supports the `some_path` query, which shows a dependency path from one | 63 supports the `some_path` query, which shows a dependency path from one |
| 63 function to another. | 64 function to another. |
| 64 | 65 |
| 65 * [`library_size_split`][lib_split]: a tool that shows how much code was | 66 * [`library_size_split`][lib_split]: a tool that shows how much code was |
| 66 attributed to each library. This tool is configurable so it can group data | 67 attributed to each library. This tool is configurable so it can group data |
| 67 in many ways (e.g. to tally together all libraries that belong to a package, | 68 in many ways (e.g. to tally together all libraries that belong to a package, |
| 68 or all libraries that match certain name pattern). | 69 or all libraries that match certain name pattern). |
| 69 | 70 |
| 70 * [`function_size_analysis`][function_analysis]: a tool that shows how much | 71 * [`function_size_analysis`][function_analysis]: a tool that shows how much |
| 71 code was attributed to each function. This tool also uses depedency | 72 code was attributed to each function. This tool also uses dependency |
| 72 information to compute dominance and reachability data. This information can | 73 information to compute dominance and reachability data. This information can |
| 73 sometimes help determine how much savings could come if the function was not | 74 sometimes help determine how much savings could come if the function was not |
| 74 included in the program. | 75 included in the program. |
| 75 | 76 |
| 76 * [`coverage_log_server`][coverage] and [`live_code_size_analysis`][live]: | 77 * [`coverage_log_server`][coverage] and [`live_code_size_analysis`][live]: |
| 77 dart2js has an experimental feature to gather coverage data of your | 78 dart2js has an experimental feature to gather coverage data of your |
| 78 application. The `coverage_log_server` can record this data, and | 79 application. The `coverage_log_server` can record this data, and |
| 79 `live_code_size_analysis` can correlate that with the `.info.json`, so you | 80 `live_code_size_analysis` can correlate that with the `.info.json`, so you |
| 80 determine why code that is not used is being included in your app. | 81 determine why code that is not used is being included in your app. |
| 81 | 82 |
| 83 * [`verify_deps`][verify_deps]: a tool that verifies that all elements are |
| 84 reachable from the program's entrypoint. If there are unreachable elements, |
| 85 this indicates that the dependency information is incomplete. |
| 86 |
| 82 Next we describe in detail how to use each of these tools. | 87 Next we describe in detail how to use each of these tools. |
| 83 | 88 |
| 84 ### Code deps tool | 89 ### Code deps tool |
| 85 | 90 |
| 86 This command-line tool can be used to query for code dependencies. Currently | 91 This command-line tool can be used to query for code dependencies. Currently |
| 87 this tool only supports the `some_path` query, which gives you the shortest path | 92 this tool only supports the `some_path` query, which gives you the shortest path |
| 88 for how one function depends on another. | 93 for how one function depends on another. |
| 89 | 94 |
| 90 Run this tool as follows: | 95 Run this tool as follows: |
| 91 ```bash | 96 ```bash |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 # If your code lives under /my/project/dir, this will match any file loaded | 182 # If your code lives under /my/project/dir, this will match any file loaded |
| 178 from a file:// url, and we use as a name the relative path to it. | 183 from a file:// url, and we use as a name the relative path to it. |
| 179 - regexp: "file:///my/project/dir/(.*)" | 184 - regexp: "file:///my/project/dir/(.*)" |
| 180 ``` | 185 ``` |
| 181 | 186 |
| 182 Regardless of the grouping configuration, the tool will display the total code | 187 Regardless of the grouping configuration, the tool will display the total code |
| 183 size attributed of all libraries, constants, and the program size. | 188 size attributed of all libraries, constants, and the program size. |
| 184 | 189 |
| 185 **Note**: eventually you should expect all numbers to add up to the program | 190 **Note**: eventually you should expect all numbers to add up to the program |
| 186 size. Currently dart2js's `--dump-info` is not complete, so numbers for | 191 size. Currently dart2js's `--dump-info` is not complete, so numbers for |
| 187 bootstraping code and lazy static initializers are missing. | 192 bootstrapping code and lazy static initializers are missing. |
| 188 | 193 |
| 189 ### Function size analysis tool | 194 ### Function size analysis tool |
| 190 | 195 |
| 191 This command-line tool presents how much each function contributes to the total | 196 This command-line tool presents how much each function contributes to the total |
| 192 code of your application. We use dependency information to compute dominance | 197 code of your application. We use dependency information to compute dominance |
| 193 and reachability data as well. | 198 and reachability data as well. |
| 194 | 199 |
| 195 When you run: | 200 When you run: |
| 196 ```bash | 201 ```bash |
| 197 pub global activate dart2js_info # only needed once | 202 pub global activate dart2js_info # only needed once |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 html file or integrate your application server to proxy to the log server | 249 html file or integrate your application server to proxy to the log server |
| 245 any GET request for the .dart.js file and /coverage POST requests that send | 250 any GET request for the .dart.js file and /coverage POST requests that send |
| 246 coverage data. | 251 coverage data. |
| 247 | 252 |
| 248 * Load your app and use it to exercise the entire code. | 253 * Load your app and use it to exercise the entire code. |
| 249 | 254 |
| 250 * Shut down the coverage server (Ctrl-C). This will emit a file named | 255 * Shut down the coverage server (Ctrl-C). This will emit a file named |
| 251 `mail.dart.js.coverage.json` | 256 `mail.dart.js.coverage.json` |
| 252 | 257 |
| 253 * Finally, run the live code analysis tool given it both the info and | 258 * Finally, run the live code analysis tool given it both the info and |
| 254 converage json files: | 259 coverage json files: |
| 255 | 260 |
| 256 ```bash | 261 ```bash |
| 257 dart2js_info_live_code_size_analysis main.dart.info.json main.dart.coverage.json | 262 dart2js_info_live_code_size_analysis main.dart.info.json main.dart.coverage.json |
| 258 ``` | 263 ``` |
| 259 | 264 |
| 265 ### Verifying dependencies |
| 266 |
| 267 Coverage of dependency information may be incomplete. If there are elements that |
| 268 are live in the output that are unreachable through dependencies from the |
| 269 program's entrypoint, then we have incomplete dependency information. Note, |
| 270 however, that all elements may be reachable from the entrypoint even if there |
| 271 is missing dependency information. In order to verify that all elements are |
| 272 reachable from the app's entrypoint, simply run the tool as so: |
| 273 |
| 274 ```bash |
| 275 dart2js_info_verify_deps foo.info.json |
| 276 ``` |
| 277 |
| 278 If all elements are reachable from the entrypoint, then the tool will return |
| 279 with exitcode 0. Otherwise, the tool will output the list of all functions that |
| 280 are not reachable from the entrypoint and return with exitcode 1. |
| 281 |
| 260 ## Code location, features and bugs | 282 ## Code location, features and bugs |
| 261 | 283 |
| 262 This package is developed in [github][repo]. Please file feature requests and | 284 This package is developed in [github][repo]. Please file feature requests and |
| 263 bugs at the [issue tracker][tracker]. | 285 bugs at the [issue tracker][tracker]. |
| 264 | 286 |
| 265 [repo]: https://github.com/dart-lang/dart2js_info/ | 287 [repo]: https://github.com/dart-lang/dart2js_info/ |
| 266 [tracker]: https://github.com/dart-lang/dart2js_info/issues | 288 [tracker]: https://github.com/dart-lang/dart2js_info/issues |
| 267 [code_deps]: https://github.com/dart-lang/dart2js_info/blob/master/bin/code_deps
.dart | 289 [code_deps]: https://github.com/dart-lang/dart2js_info/blob/master/bin/code_deps
.dart |
| 268 [lib_split]: https://github.com/dart-lang/dart2js_info/blob/master/bin/library_s
ize_split.dart | 290 [lib_split]: https://github.com/dart-lang/dart2js_info/blob/master/bin/library_s
ize_split.dart |
| 269 [coverage]: https://github.com/dart-lang/dart2js_info/blob/master/bin/coverage_l
og_server.dart | 291 [coverage]: https://github.com/dart-lang/dart2js_info/blob/master/bin/coverage_l
og_server.dart |
| 270 [live]: https://github.com/dart-lang/dart2js_info/blob/master/bin/live_code_size
_analysis.dart | 292 [live]: https://github.com/dart-lang/dart2js_info/blob/master/bin/live_code_size
_analysis.dart |
| 271 [function_analysis]: https://github.com/dart-lang/dart2js_info/blob/master/bin/f
unction_size_analysis.dart | 293 [function_analysis]: https://github.com/dart-lang/dart2js_info/blob/master/bin/f
unction_size_analysis.dart |
| 294 [verify_deps]: https://github.com/dart-lang/dart2js_info/blob/master/bin/verify_
deps.dart |
| 272 [AllInfo]: http://dart-lang.github.io/dart2js_info/doc/api/dart2js_info.info/All
Info-class.html | 295 [AllInfo]: http://dart-lang.github.io/dart2js_info/doc/api/dart2js_info.info/All
Info-class.html |
| OLD | NEW |