33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Repo deprecation notice
2 |
3 | **NOTE**: This repository has been deprecated; for information and tooling related to
4 | understanding the size of your compiled web applications, see instead
5 | [dart.dev/go/dart2js-info](https://dart.dev/go/dart2js-info).
6 |
7 | ## Dump-Info visualizer
8 |
9 | A web based visualizer for the dart2js `--dump-info` option.
10 |
11 | [Live Website](https://dart-lang.github.io/dump-info-visualizer/)
12 |
13 | ## Screenshot
14 |
15 | 
16 |
17 | ## How to Build
18 |
19 | The dump-info-visualizer is a Pub project, so running `pub build` will
20 | generate all the files for the viewer.
21 |
22 | This repository also hosts the public version of the viewer which is located
23 | on the `gh-pages` branch. Any files pushed to `gh-pages` will be made public.
24 |
25 | In order to make your changes public, follow these instructions.
26 |
27 | * `git checkout master` Your changes should already be on the master branch
28 | when you deploy.
29 | * `pub build` Build all of the javascript and HTML files.
30 | * `mv build ../` Copy built files out of the project structure.
31 | * `git checkout gh-pages` The destination branch.
32 | * `rm -rf build` Remove old build.
33 | * `mv ../build ./` Copy new build in.
34 | * `git commit -a -m "your message here"` Commit the new build.
35 | * `git push origin gh-pages` Deploy to gh-pages.
36 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2014, the Dart project authors.
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are
5 | met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above
10 | copyright notice, this list of conditions and the following
11 | disclaimer in the documentation and/or other materials provided
12 | with the distribution.
13 | * Neither the name of Google LLC nor the names of its
14 | contributors may be used to endorse or promote products derived
15 | from this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/lib/src/drag_drop_view.dart:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014, 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 | library dump_viz.dragdrop;
6 |
7 | import 'dart:async';
8 | import 'dart:html';
9 |
10 | import 'package:polymer/polymer.dart';
11 |
12 | @CustomTag('drag-drop-view')
13 | class DragDropView extends PolymerElement {
14 | Element get _dropZone => $['drag-target'];
15 | Element get _fileUpload => $['file_upload'];
16 |
17 | DragDropView.created() : super.created();
18 |
19 | final StreamController _streamController =
20 | new StreamController();
21 |
22 | Stream get onFile => _streamController.stream;
23 |
24 | void ready() {
25 | _fileUpload.onChange.listen((event) {
26 | var file = (event.target as InputElement).files.first;
27 | _loadFile(file);
28 | });
29 |
30 | _dropZone.onDragOver.listen((e) {
31 | e.stopPropagation();
32 | e.preventDefault();
33 | _dropZone.style.backgroundColor = 'rgb(200,200,200)';
34 | });
35 |
36 | _dropZone.onDrop.listen((e) {
37 | e.stopPropagation();
38 | e.preventDefault();
39 | File file = e.dataTransfer.files.first;
40 | _loadFile(file);
41 | });
42 | }
43 |
44 | void hide() {
45 | _dropZone.style.display = 'none';
46 | }
47 |
48 | void show() {
49 | _dropZone.style.display = 'block';
50 | }
51 |
52 | void _loadFile(File file) {
53 | FileReader reader = new FileReader();
54 |
55 | reader.onLoad.first.then((_) {
56 | String fileContents = reader.result;
57 | // Substring because fileContents contains the mime type
58 | var contents =
59 | window.atob(fileContents.substring(fileContents.indexOf(',') + 1));
60 | _dropZone.style.backgroundColor = '';
61 | _streamController.add(contents);
62 | });
63 | reader.readAsDataUrl(file);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/test/diff_test.dart:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014, 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 | library dump_viz.test.diff_test;
5 |
6 | import 'package:dump_viz/src/info_helper.dart';
7 | import 'package:dump_viz/src/diff_alg.dart';
8 |
9 | import 'package:test/test.dart';
10 |
11 | class FakeInfoHelper {
12 | InfoHelper info;
13 | FakeInfoHelper() {
14 | info = new InfoHelper(3, {}, {}, {});
15 | }
16 | FakeInfoHelper.fromFuncs(List funcs) {
17 | int i = 0;
18 | Map>> elements = {};
19 | Map> functions = {};
20 | Map> libraries = {};
21 |
22 | elements['function'] = functions;
23 | elements['library'] = libraries;
24 |
25 | Map liba = {'name': "LibA"};
26 | libraries['0'] = liba;
27 | List children = [];
28 | liba['children'] = children;
29 |
30 | for (var func in funcs) {
31 | functions['$i'] = func;
32 | children.add('function/$i');
33 | func['id'] = 'function/$i';
34 | i++;
35 | }
36 | info = new InfoHelper(3, elements, {}, {});
37 | }
38 | }
39 |
40 | void main() {
41 | test('empty', () {
42 | var d = diff(new FakeInfoHelper().info, new FakeInfoHelper().info);
43 | expect(d, equals([]));
44 | });
45 | test('change', () {
46 | var one = [{'name': 'foo', 'size': 10}];
47 | var two = [{'name': 'foo', 'size': 20}];
48 | expect(diff(new FakeInfoHelper.fromFuncs(one).info,
49 | new FakeInfoHelper.fromFuncs(two).info),
50 | equals([new DiffItem('partial-add', 'LibA.foo', 10)]));
51 | });
52 | test('add/remove', () {
53 | var one = [{'name': 'foo', 'size': 10}];
54 | var two = [{'name': 'bar', 'size': 20}];
55 | expect(diff(new FakeInfoHelper.fromFuncs(one).info,
56 | new FakeInfoHelper.fromFuncs(two).info), equals([
57 | new DiffItem('full-add', 'LibA.bar', 20),
58 | new DiffItem('full-remove', 'LibA.foo', -10)
59 | ]));
60 | });
61 | }
62 |
--------------------------------------------------------------------------------
/lib/src/diff_alg.dart:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014, 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 | library dump_viz.diff_alg;
6 |
7 | import 'info_helper.dart';
8 |
9 | class DiffItem {
10 | final String kind;
11 | final String path;
12 | final int diff;
13 |
14 | DiffItem(this.kind, this.path, this.diff);
15 | bool operator ==(other) {
16 | return other.kind == kind && other.path == path && other.diff == diff;
17 | }
18 | int get hashCode {
19 | int result = 17;
20 | result = 37 * result + kind.hashCode;
21 | result = 37 * result + path.hashCode;
22 | result = 37 * result + diff.hashCode;
23 | return result;
24 | }
25 | }
26 |
27 | List diff(InfoHelper before, InfoHelper after) {
28 | List changedElements = [];
29 | for (String path in before.joinedPaths) {
30 | String beforeId = before.idFromJoinedPath(path);
31 | int beforeSize = before.sizeOf(beforeId);
32 | if (beforeSize == null) continue;
33 | if (after.idFromJoinedPath(path) != null) {
34 | String afterId = after.idFromJoinedPath(path);
35 | int afterSize = after.sizeOf(afterId);
36 | if (afterSize == null) continue;
37 | int diff = afterSize - beforeSize;
38 | if (diff == 0) {
39 | continue;
40 | } else if (diff > 0) {
41 | changedElements.add(new DiffItem('partial-add', path, diff));
42 | } else {
43 | changedElements.add(new DiffItem('partial-remove', path, diff));
44 | }
45 | } else {
46 | changedElements.add(new DiffItem("full-remove", path, -beforeSize));
47 | }
48 | }
49 |
50 | for (String path in after.joinedPaths) {
51 | String afterId = after.idFromJoinedPath(path);
52 | int afterSize = after.sizeOf(afterId);
53 | if (afterSize == null) continue;
54 | if (before.idFromJoinedPath(path) == null) {
55 | changedElements.add(new DiffItem("full-add", path, afterSize));
56 | }
57 | }
58 |
59 | changedElements.sort((a, b) => -a.diff.abs().compareTo(b.diff.abs()));
60 | return changedElements;
61 | }
62 |
--------------------------------------------------------------------------------
/lib/src/dependency_view.html:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
51 |
52 | In order to use the dependency view, first find an element to focus on
53 | in the hierarchy view and click on the symbol.
54 |
55 |
56 |
57 |
58 |
59 |
Uses Current Element
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
Current Element
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
Current Element Uses
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
--------------------------------------------------------------------------------
/lib/src/program_info_view.dart:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014, 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 | library dump_viz.program_info_view;
6 |
7 | import 'dart:html';
8 |
9 | import 'package:polymer/polymer.dart';
10 |
11 | import 'info_helper.dart';
12 |
13 | @CustomTag('program-info-view')
14 | class ProgramInfoView extends PolymerElement {
15 | InfoHelper _model;
16 |
17 | ProgramInfoView.created() : super.created();
18 |
19 | TableElement get _treeTable => $['prog-info'];
20 |
21 | set dumpInfo(InfoHelper dumpInfo) {
22 | _model = dumpInfo;
23 | _setupProgramwideInfo();
24 | }
25 |
26 | void _extractClick(_) {
27 | String text =
28 | _model.allOfType('function').map((a) => "${a['name']}").join(', ');
29 | text = Uri.encodeComponent('[$text]');
30 | String encoded = 'data:text/plain;charset=utf-8,$text';
31 |
32 | AnchorElement downloadLink = new AnchorElement(href: encoded);
33 | downloadLink.text = 'download file';
34 | downloadLink.setAttribute('download', 'functions.txt');
35 | downloadLink.click();
36 | }
37 |
38 | void _setupProgramwideInfo() {
39 | _treeTable.children.clear();
40 | var map = {
41 | 'Program Size': '${_model.size} bytes',
42 | 'Compile Time': _model.compilationMoment,
43 | 'Compile Duration': _model.compilationDuration,
44 | 'noSuchMethod Enabled': new SpanElement()
45 | ..text = _model.noSuchMethodEnabled.toString()
46 | ..style.background = _model.noSuchMethodEnabled ? "red" : "white",
47 | // TODO(tyoverby): add support for loading files generated by
48 | // TRACE_CALLS and compare them to the functions that are produced
49 | // by dart2js.
50 | 'Extract Function Names': new ButtonElement()
51 | ..text = 'extract'
52 | ..onClick.listen(_extractClick)
53 | };
54 |
55 | map.forEach((k, v) {
56 | var row = _treeTable.addRow();
57 | row.addCell()..text = k;
58 | if (v is String) {
59 | row.addCell()..text = v;
60 | } else if (v is Element) {
61 | row.addCell()..children.add(v);
62 | } else {
63 | throw new ArgumentError("Unexpected value in map: $v");
64 | }
65 | });
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/lib/src/tree_table.html:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
27 |