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

Side by Side Diff: pkg/compiler/lib/src/dump_info.dart

Issue 1145603002: add library canonicalUri to dart2js dump info (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: also include minify information Created 5 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library dump_info; 5 library dump_info;
6 6
7 import 'dart:convert' show 7 import 'dart:convert' show
8 HtmlEscape, 8 HtmlEscape,
9 JsonEncoder, 9 JsonEncoder,
10 StringConversionSink, 10 StringConversionSink,
(...skipping 13 matching lines...) Expand all
24 import 'js/js.dart' as jsAst; 24 import 'js/js.dart' as jsAst;
25 import 'universe/universe.dart' show Selector; 25 import 'universe/universe.dart' show Selector;
26 import 'util/util.dart' show NO_LOCATION_SPANNABLE; 26 import 'util/util.dart' show NO_LOCATION_SPANNABLE;
27 27
28 /// Maps objects to an id. Supports lookups in 28 /// Maps objects to an id. Supports lookups in
29 /// both directions. 29 /// both directions.
30 class IdMapper<T>{ 30 class IdMapper<T>{
31 Map<int, T> _idToElement = {}; 31 Map<int, T> _idToElement = {};
32 Map<T, int> _elementToId = {}; 32 Map<T, int> _elementToId = {};
33 int _idCounter = 0; 33 int _idCounter = 0;
34 String name; 34 final String name;
35 35
36 IdMapper(this.name); 36 IdMapper(this.name);
37 37
38 Iterable<T> get elements => _elementToId.keys; 38 Iterable<T> get elements => _elementToId.keys;
39 39
40 String add(T e) { 40 String add(T e) {
41 if (_elementToId.containsKey(e)) { 41 if (_elementToId.containsKey(e)) {
42 return name + "/${_elementToId[e]}"; 42 return name + "/${_elementToId[e]}";
43 } 43 }
44 44
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 89
90 String dart2jsVersion; 90 String dart2jsVersion;
91 91
92 ElementToJsonVisitor(this.compiler); 92 ElementToJsonVisitor(this.compiler);
93 93
94 void run() { 94 void run() {
95 Backend backend = compiler.backend; 95 Backend backend = compiler.backend;
96 96
97 dart2jsVersion = compiler.hasBuildId ? compiler.buildId : null; 97 dart2jsVersion = compiler.hasBuildId ? compiler.buildId : null;
98 98
99 for (var library in compiler.libraryLoader.libraries.toList()) { 99 for (LibraryElement library in compiler.libraryLoader.libraries.toList()) {
100 visit(library); 100 visit(library);
101 } 101 }
102 } 102 }
103 103
104 Map<String, dynamic> visit(Element e, [_]) => e.accept(this, null); 104 Map<String, dynamic> visit(Element e, [_]) => e.accept(this, null);
105 105
106 // If keeping the element is in question (like if a function has a size 106 // If keeping the element is in question (like if a function has a size
107 // of zero), only keep it if it holds dependencies to elsewhere. 107 // of zero), only keep it if it holds dependencies to elsewhere.
108 bool shouldKeep(Element element) { 108 bool shouldKeep(Element element) {
109 return compiler.dumpInfoTask.selectorsFromElement.containsKey(element) 109 return compiler.dumpInfoTask.selectorsFromElement.containsKey(element)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 158
159 if (children.length == 0 && !shouldKeep(element)) { 159 if (children.length == 0 && !shouldKeep(element)) {
160 return null; 160 return null;
161 } 161 }
162 162
163 return { 163 return {
164 'kind': 'library', 164 'kind': 'library',
165 'name': libname, 165 'name': libname,
166 'size': size, 166 'size': size,
167 'id': id, 167 'id': id,
168 'children': children 168 'children': children,
169 'canonicalUri': element.canonicalUri.toString()
169 }; 170 };
170 } 171 }
171 172
172 Map<String, dynamic> visitTypedefElement(TypedefElement element, _) { 173 Map<String, dynamic> visitTypedefElement(TypedefElement element, _) {
173 String id = mapper._typedef.add(element); 174 String id = mapper._typedef.add(element);
174 return element.alias == null 175 return element.alias == null
175 ? null 176 ? null
176 : { 177 : {
177 'id': id, 178 'id': id,
178 'type': element.alias.toString(), 179 'type': element.alias.toString(),
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 class Selection { 393 class Selection {
393 final Element selectedElement; 394 final Element selectedElement;
394 final Selector selector; 395 final Selector selector;
395 Selection(this.selectedElement, this.selector); 396 Selection(this.selectedElement, this.selector);
396 } 397 }
397 398
398 class DumpInfoTask extends CompilerTask { 399 class DumpInfoTask extends CompilerTask {
399 DumpInfoTask(Compiler compiler) 400 DumpInfoTask(Compiler compiler)
400 : super(compiler); 401 : super(compiler);
401 402
402 String name = "Dump Info"; 403 String get name => "Dump Info";
403 404
404 ElementToJsonVisitor infoCollector; 405 ElementToJsonVisitor infoCollector;
405 406
406 /// The size of the generated output. 407 /// The size of the generated output.
407 int _programSize; 408 int _programSize;
408 409
409 // A set of javascript AST nodes that we care about the size of. 410 // A set of javascript AST nodes that we care about the size of.
410 // This set is automatically populated when registerElementAst() 411 // This set is automatically populated when registerElementAst()
411 // is called. 412 // is called.
412 final Set<jsAst.Node> _tracking = new Set<jsAst.Node>(); 413 final Set<jsAst.Node> _tracking = new Set<jsAst.Node>();
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 } 618 }
618 619
619 Map<String, dynamic> outJson = { 620 Map<String, dynamic> outJson = {
620 'elements': infoCollector.toJson(), 621 'elements': infoCollector.toJson(),
621 'holding': holding, 622 'holding': holding,
622 'outputUnits': outputUnits, 623 'outputUnits': outputUnits,
623 'dump_version': 3, 624 'dump_version': 3,
624 'deferredFiles': compiler.deferredLoadTask.computeDeferredMap(), 625 'deferredFiles': compiler.deferredLoadTask.computeDeferredMap(),
625 // This increases when new information is added to the map, but the viewer 626 // This increases when new information is added to the map, but the viewer
626 // still is compatible. 627 // still is compatible.
627 'dump_minor_version': '1' 628 'dump_minor_version': '2'
628 }; 629 };
629 630
630 Duration toJsonDuration = new DateTime.now().difference(startToJsonTime); 631 Duration toJsonDuration = new DateTime.now().difference(startToJsonTime);
631 632
632 Map<String, dynamic> generalProgramInfo = <String, dynamic> { 633 Map<String, dynamic> generalProgramInfo = <String, dynamic> {
633 'size': _programSize, 634 'size': _programSize,
634 'dart2jsVersion': infoCollector.dart2jsVersion, 635 'dart2jsVersion': infoCollector.dart2jsVersion,
635 'compilationMoment': new DateTime.now().toString(), 636 'compilationMoment': new DateTime.now().toString(),
636 'compilationDuration': compiler.totalCompileTime.elapsed.toString(), 637 'compilationDuration': compiler.totalCompileTime.elapsed.toString(),
637 'toJsonDuration': 0, 638 'toJsonDuration': 0,
638 'dumpInfoDuration': this.timing.toString(), 639 'dumpInfoDuration': this.timing.toString(),
639 'noSuchMethodEnabled': backend.enabledNoSuchMethod 640 'noSuchMethodEnabled': backend.enabledNoSuchMethod,
641 'minified': compiler.enableMinification
640 }; 642 };
641 643
642 outJson['program'] = generalProgramInfo; 644 outJson['program'] = generalProgramInfo;
643 645
644 ChunkedConversionSink<Object> sink = 646 ChunkedConversionSink<Object> sink =
645 encoder.startChunkedConversion( 647 encoder.startChunkedConversion(
646 new StringConversionSink.fromStringSink(buffer)); 648 new StringConversionSink.fromStringSink(buffer));
647 sink.add(outJson); 649 sink.add(outJson);
648 compiler.reportInfo(NO_LOCATION_SPANNABLE, 650 compiler.reportInfo(NO_LOCATION_SPANNABLE,
649 const MessageKind( 651 const MessageKind(
650 "View the dumped .info.json file at " 652 "View the dumped .info.json file at "
651 "https://dart-lang.github.io/dump-info-visualizer")); 653 "https://dart-lang.github.io/dump-info-visualizer"));
652 } 654 }
653 } 655 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698