| OLD | NEW |
| 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 Loading... |
| 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 final int programSize; |
| 90 String dart2jsVersion; | 90 String dart2jsVersion; |
| 91 | 91 |
| 92 ElementToJsonVisitor(this.compiler); | 92 ElementToJsonVisitor(this.compiler, this.programSize); |
| 93 | 93 |
| 94 void run() { | 94 void run() { |
| 95 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 } | |
| 103 | 96 |
| 104 dart2jsVersion = compiler.hasBuildId ? compiler.buildId : null; | 97 dart2jsVersion = compiler.hasBuildId ? compiler.buildId : null; |
| 105 | 98 |
| 106 for (var library in compiler.libraryLoader.libraries.toList()) { | 99 for (var library in compiler.libraryLoader.libraries.toList()) { |
| 107 library.accept(this); | 100 library.accept(this); |
| 108 } | 101 } |
| 109 } | 102 } |
| 110 | 103 |
| 111 // If keeping the element is in question (like if a function has a size | 104 // If keeping the element is in question (like if a function has a size |
| 112 // of zero), only keep it if it holds dependencies to elsewhere. | 105 // of zero), only keep it if it holds dependencies to elsewhere. |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 List<jsAst.Node> code = _elementToNodes[element]; | 541 List<jsAst.Node> code = _elementToNodes[element]; |
| 549 if (code == null) return null; | 542 if (code == null) return null; |
| 550 // Concatenate rendered ASTs. | 543 // Concatenate rendered ASTs. |
| 551 StringBuffer sb = new StringBuffer(); | 544 StringBuffer sb = new StringBuffer(); |
| 552 for (jsAst.Node ast in code) { | 545 for (jsAst.Node ast in code) { |
| 553 sb.writeln(jsAst.prettyPrint(ast, compiler).getText()); | 546 sb.writeln(jsAst.prettyPrint(ast, compiler).getText()); |
| 554 } | 547 } |
| 555 return sb; | 548 return sb; |
| 556 } | 549 } |
| 557 | 550 |
| 558 void collectInfo() { | 551 void collectInfo(int programSize) { |
| 559 infoCollector = new ElementToJsonVisitor(compiler)..run(); | 552 infoCollector = new ElementToJsonVisitor(compiler, programSize)..run(); |
| 560 } | 553 } |
| 561 | 554 |
| 562 void dumpInfo() { | 555 void dumpInfo(int programSize) { |
| 563 measure(() { | 556 measure(() { |
| 564 if (infoCollector == null) { | 557 if (infoCollector == null) { |
| 565 collectInfo(); | 558 collectInfo(programSize); |
| 566 } | 559 } |
| 567 | 560 |
| 568 StringBuffer jsonBuffer = new StringBuffer(); | 561 StringBuffer jsonBuffer = new StringBuffer(); |
| 569 dumpInfoJson(jsonBuffer); | 562 dumpInfoJson(jsonBuffer); |
| 570 compiler.outputProvider('', 'info.json') | 563 compiler.outputProvider('', 'info.json') |
| 571 ..add(jsonBuffer.toString()) | 564 ..add(jsonBuffer.toString()) |
| 572 ..close(); | 565 ..close(); |
| 573 }); | 566 }); |
| 574 } | 567 } |
| 575 | 568 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 ChunkedConversionSink<Object> sink = | 651 ChunkedConversionSink<Object> sink = |
| 659 encoder.startChunkedConversion( | 652 encoder.startChunkedConversion( |
| 660 new StringConversionSink.fromStringSink(buffer)); | 653 new StringConversionSink.fromStringSink(buffer)); |
| 661 sink.add(outJson); | 654 sink.add(outJson); |
| 662 compiler.reportInfo(NO_LOCATION_SPANNABLE, | 655 compiler.reportInfo(NO_LOCATION_SPANNABLE, |
| 663 const MessageKind( | 656 const MessageKind( |
| 664 "View the dumped .info.json file at " | 657 "View the dumped .info.json file at " |
| 665 "https://dart-lang.github.io/dump-info-visualizer")); | 658 "https://dart-lang.github.io/dump-info-visualizer")); |
| 666 } | 659 } |
| 667 } | 660 } |
| OLD | NEW |