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

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

Issue 824103005: Revert "Remove Compiler.assembledCode." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 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
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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 return json; 79 return json;
80 } 80 }
81 } 81 }
82 82
83 class ElementToJsonVisitor extends ElementVisitor<Map<String, dynamic>> { 83 class ElementToJsonVisitor extends ElementVisitor<Map<String, dynamic>> {
84 final GroupedIdMapper mapper = new GroupedIdMapper(); 84 final GroupedIdMapper mapper = new GroupedIdMapper();
85 final Compiler compiler; 85 final Compiler compiler;
86 86
87 final Map<Element, Map<String, dynamic>> jsonCache = {}; 87 final Map<Element, Map<String, dynamic>> jsonCache = {};
88 88
89 int programSize;
89 String dart2jsVersion; 90 String dart2jsVersion;
90 91
91 ElementToJsonVisitor(this.compiler); 92 ElementToJsonVisitor(this.compiler);
92 93
93 void run() { 94 void run() {
94 Backend backend = compiler.backend; 95 Backend backend = compiler.backend;
96 if (backend is JavaScriptBackend) {
97 // Add up the sizes of all output-buffers.
98 programSize = backend.emitter.oldEmitter.outputBuffers.values.fold(0,
99 (a, b) => a + b.length);
100 } else {
101 programSize = compiler.assembledCode.length;
102 }
95 103
96 dart2jsVersion = compiler.hasBuildId ? compiler.buildId : null; 104 dart2jsVersion = compiler.hasBuildId ? compiler.buildId : null;
97 105
98 for (var library in compiler.libraryLoader.libraries.toList()) { 106 for (var library in compiler.libraryLoader.libraries.toList()) {
99 library.accept(this); 107 library.accept(this);
100 } 108 }
101 } 109 }
102 110
103 // If keeping the element is in question (like if a function has a size 111 // If keeping the element is in question (like if a function has a size
104 // of zero), only keep it if it holds dependencies to elsewhere. 112 // of zero), only keep it if it holds dependencies to elsewhere.
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 } 398 }
391 399
392 class DumpInfoTask extends CompilerTask { 400 class DumpInfoTask extends CompilerTask {
393 DumpInfoTask(Compiler compiler) 401 DumpInfoTask(Compiler compiler)
394 : super(compiler); 402 : super(compiler);
395 403
396 String name = "Dump Info"; 404 String name = "Dump Info";
397 405
398 ElementToJsonVisitor infoCollector; 406 ElementToJsonVisitor infoCollector;
399 407
400 /// The size of the generated output.
401 int _programSize;
402
403 // A set of javascript AST nodes that we care about the size of. 408 // A set of javascript AST nodes that we care about the size of.
404 // This set is automatically populated when registerElementAst() 409 // This set is automatically populated when registerElementAst()
405 // is called. 410 // is called.
406 final Set<jsAst.Node> _tracking = new Set<jsAst.Node>(); 411 final Set<jsAst.Node> _tracking = new Set<jsAst.Node>();
407 // A mapping from Dart Elements to Javascript AST Nodes. 412 // A mapping from Dart Elements to Javascript AST Nodes.
408 final Map<Element, List<jsAst.Node>> _elementToNodes = 413 final Map<Element, List<jsAst.Node>> _elementToNodes =
409 <Element, List<jsAst.Node>>{}; 414 <Element, List<jsAst.Node>>{};
410 // A mapping from Javascript AST Nodes to the size of their 415 // A mapping from Javascript AST Nodes to the size of their
411 // pretty-printed contents. 416 // pretty-printed contents.
412 final Map<jsAst.Node, int> _nodeToSize = <jsAst.Node, int>{}; 417 final Map<jsAst.Node, int> _nodeToSize = <jsAst.Node, int>{};
413 final Map<jsAst.Node, int> _nodeBeforeSize = <jsAst.Node, int>{}; 418 final Map<jsAst.Node, int> _nodeBeforeSize = <jsAst.Node, int>{};
414 final Map<Element, int> _fieldNameToSize = <Element, int>{}; 419 final Map<Element, int> _fieldNameToSize = <Element, int>{};
415 420
416 final Map<Element, Set<Selector>> selectorsFromElement = {}; 421 final Map<Element, Set<Selector>> selectorsFromElement = {};
417 final Map<Element, int> inlineCount = <Element, int>{}; 422 final Map<Element, int> inlineCount = <Element, int>{};
418 // A mapping from an element to a list of elements that are 423 // A mapping from an element to a list of elements that are
419 // inlined inside of it. 424 // inlined inside of it.
420 final Map<Element, List<Element>> inlineMap = <Element, List<Element>>{}; 425 final Map<Element, List<Element>> inlineMap = <Element, List<Element>>{};
421 426
422 /// Register the size of the generated output.
423 void reportSize(int programSize) {
424 _programSize = programSize;
425 }
426
427 void registerInlined(Element element, Element inlinedFrom) { 427 void registerInlined(Element element, Element inlinedFrom) {
428 inlineCount.putIfAbsent(element, () => 0); 428 inlineCount.putIfAbsent(element, () => 0);
429 inlineCount[element] += 1; 429 inlineCount[element] += 1;
430 inlineMap.putIfAbsent(inlinedFrom, () => new List<Element>()); 430 inlineMap.putIfAbsent(inlinedFrom, () => new List<Element>());
431 inlineMap[inlinedFrom].add(element); 431 inlineMap[inlinedFrom].add(element);
432 } 432 }
433 433
434 /** 434 /**
435 * Registers that a function uses a selector in the 435 * Registers that a function uses a selector in the
436 * function body 436 * function body
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 Map<String, dynamic> outJson = { 637 Map<String, dynamic> outJson = {
638 'elements': infoCollector.toJson(), 638 'elements': infoCollector.toJson(),
639 'holding': holding, 639 'holding': holding,
640 'outputUnits': outputUnits, 640 'outputUnits': outputUnits,
641 'dump_version': 3, 641 'dump_version': 3,
642 }; 642 };
643 643
644 Duration toJsonDuration = new DateTime.now().difference(startToJsonTime); 644 Duration toJsonDuration = new DateTime.now().difference(startToJsonTime);
645 645
646 Map<String, dynamic> generalProgramInfo = <String, dynamic> { 646 Map<String, dynamic> generalProgramInfo = <String, dynamic> {
647 'size': _programSize, 647 'size': infoCollector.programSize,
648 'dart2jsVersion': infoCollector.dart2jsVersion, 648 'dart2jsVersion': infoCollector.dart2jsVersion,
649 'compilationMoment': new DateTime.now().toString(), 649 'compilationMoment': new DateTime.now().toString(),
650 'compilationDuration': compiler.totalCompileTime.elapsed.toString(), 650 'compilationDuration': compiler.totalCompileTime.elapsed.toString(),
651 'toJsonDuration': 0, 651 'toJsonDuration': 0,
652 'dumpInfoDuration': this.timing.toString(), 652 'dumpInfoDuration': this.timing.toString(),
653 'noSuchMethodEnabled': compiler.enabledNoSuchMethod 653 'noSuchMethodEnabled': compiler.enabledNoSuchMethod
654 }; 654 };
655 655
656 outJson['program'] = generalProgramInfo; 656 outJson['program'] = generalProgramInfo;
657 657
658 ChunkedConversionSink<Object> sink = 658 ChunkedConversionSink<Object> sink =
659 encoder.startChunkedConversion( 659 encoder.startChunkedConversion(
660 new StringConversionSink.fromStringSink(buffer)); 660 new StringConversionSink.fromStringSink(buffer));
661 sink.add(outJson); 661 sink.add(outJson);
662 compiler.reportInfo(NO_LOCATION_SPANNABLE, 662 compiler.reportInfo(NO_LOCATION_SPANNABLE,
663 const MessageKind( 663 const MessageKind(
664 "View the dumped .info.json file at " 664 "View the dumped .info.json file at "
665 "https://dart-lang.github.io/dump-info-visualizer")); 665 "https://dart-lang.github.io/dump-info-visualizer"));
666 } 666 }
667 } 667 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/dart_backend/outputter.dart ('k') | pkg/compiler/lib/src/js_backend/backend.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698