| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 innerMapper["$k"] = elementJson; | 68 innerMapper["$k"] = elementJson; |
| 69 } | 69 } |
| 70 }); | 70 }); |
| 71 json[mapper.name] = innerMapper; | 71 json[mapper.name] = innerMapper; |
| 72 } | 72 } |
| 73 return json; | 73 return json; |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 | 76 |
| 77 class ElementToJsonVisitor extends ElementVisitor<Map<String, dynamic>> { | 77 class ElementToJsonVisitor extends ElementVisitor<Map<String, dynamic>> { |
| 78 GroupedIdMapper mapper = new GroupedIdMapper(); | 78 final GroupedIdMapper mapper = new GroupedIdMapper(); |
| 79 Compiler compiler; | 79 final Compiler compiler; |
| 80 | 80 |
| 81 Map<Element, Map<String, dynamic>> jsonCache = {}; | 81 final Map<Element, Map<String, dynamic>> jsonCache = {}; |
| 82 Map<Element, jsAst.Expression> codeCache; | |
| 83 | 82 |
| 84 int programSize; | 83 int programSize; |
| 85 DateTime compilationMoment; | 84 DateTime compilationMoment; |
| 86 String dart2jsVersion; | 85 String dart2jsVersion; |
| 87 Duration compilationDuration; | 86 Duration compilationDuration; |
| 88 Duration dumpInfoDuration; | 87 Duration dumpInfoDuration; |
| 89 | 88 |
| 90 ElementToJsonVisitor(Compiler compiler) { | 89 ElementToJsonVisitor(this.compiler); |
| 91 this.compiler = compiler; | |
| 92 | 90 |
| 91 void run() { |
| 93 Backend backend = compiler.backend; | 92 Backend backend = compiler.backend; |
| 94 if (backend is JavaScriptBackend) { | 93 if (backend is JavaScriptBackend) { |
| 95 // Add up the sizes of all output-buffers. | 94 // Add up the sizes of all output-buffers. |
| 96 programSize = backend.emitter.outputBuffers.values.fold(0, | 95 programSize = backend.emitter.outputBuffers.values.fold(0, |
| 97 (a, b) => a + b.length); | 96 (a, b) => a + b.length); |
| 98 } else { | 97 } else { |
| 99 programSize = compiler.assembledCode.length; | 98 programSize = compiler.assembledCode.length; |
| 100 } | 99 } |
| 101 | 100 |
| 102 | |
| 103 compilationMoment = new DateTime.now(); | 101 compilationMoment = new DateTime.now(); |
| 104 dart2jsVersion = compiler.hasBuildId ? compiler.buildId : null; | 102 dart2jsVersion = compiler.hasBuildId ? compiler.buildId : null; |
| 105 compilationDuration = compiler.totalCompileTime.elapsed; | 103 compilationDuration = compiler.totalCompileTime.elapsed; |
| 106 | 104 |
| 107 for (var library in compiler.libraryLoader.libraries.toList()) { | 105 for (var library in compiler.libraryLoader.libraries.toList()) { |
| 108 library.accept(this); | 106 library.accept(this); |
| 109 } | 107 } |
| 110 | 108 |
| 111 dumpInfoDuration = new DateTime.now().difference(compilationMoment); | 109 dumpInfoDuration = new DateTime.now().difference(compilationMoment); |
| 110 |
| 112 } | 111 } |
| 113 | 112 |
| 114 // If keeping the element is in question (like if a function has a size | 113 // If keeping the element is in question (like if a function has a size |
| 115 // of zero), only keep it if it holds dependencies to elsewhere. | 114 // of zero), only keep it if it holds dependencies to elsewhere. |
| 116 bool shouldKeep(Element element) { | 115 bool shouldKeep(Element element) { |
| 117 return compiler.dumpInfoTask.selectorsFromElement.containsKey(element); | 116 return compiler.dumpInfoTask.selectorsFromElement.containsKey(element); |
| 118 } | 117 } |
| 119 | 118 |
| 120 Map<String, dynamic> toJson() { | 119 Map<String, dynamic> toJson() { |
| 121 return mapper._toJson(this); | 120 return mapper._toJson(this); |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 if (code == null) return null; | 526 if (code == null) return null; |
| 528 // Concatenate rendered ASTs. | 527 // Concatenate rendered ASTs. |
| 529 StringBuffer sb = new StringBuffer(); | 528 StringBuffer sb = new StringBuffer(); |
| 530 for (jsAst.Node ast in code) { | 529 for (jsAst.Node ast in code) { |
| 531 sb.writeln(jsAst.prettyPrint(ast, compiler).getText()); | 530 sb.writeln(jsAst.prettyPrint(ast, compiler).getText()); |
| 532 } | 531 } |
| 533 return sb; | 532 return sb; |
| 534 } | 533 } |
| 535 | 534 |
| 536 void collectInfo() { | 535 void collectInfo() { |
| 537 infoCollector = new ElementToJsonVisitor(compiler); | 536 infoCollector = new ElementToJsonVisitor(compiler)..run(); |
| 538 } | 537 } |
| 539 | 538 |
| 540 void dumpInfo() { | 539 void dumpInfo() { |
| 541 measure(() { | 540 measure(() { |
| 542 if (infoCollector == null) { | 541 if (infoCollector == null) { |
| 543 collectInfo(); | 542 collectInfo(); |
| 544 } | 543 } |
| 545 | 544 |
| 546 StringBuffer jsonBuffer = new StringBuffer(); | 545 StringBuffer jsonBuffer = new StringBuffer(); |
| 547 dumpInfoJson(jsonBuffer); | 546 dumpInfoJson(jsonBuffer); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 }; | 613 }; |
| 615 | 614 |
| 616 outJson['program'] = generalProgramInfo; | 615 outJson['program'] = generalProgramInfo; |
| 617 | 616 |
| 618 ChunkedConversionSink<Object> sink = | 617 ChunkedConversionSink<Object> sink = |
| 619 encoder.startChunkedConversion( | 618 encoder.startChunkedConversion( |
| 620 new StringConversionSink.fromStringSink(buffer)); | 619 new StringConversionSink.fromStringSink(buffer)); |
| 621 sink.add(outJson); | 620 sink.add(outJson); |
| 622 } | 621 } |
| 623 } | 622 } |
| OLD | NEW |