Chromium Code Reviews| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 final GroupedIdMapper mapper = new GroupedIdMapper(); | 85 final GroupedIdMapper mapper = new GroupedIdMapper(); |
| 86 final Compiler compiler; | 86 final Compiler compiler; |
| 87 | 87 |
| 88 final Map<Element, Map<String, dynamic>> jsonCache = {}; | 88 final Map<Element, Map<String, dynamic>> jsonCache = {}; |
| 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; | |
| 96 | |
| 97 dart2jsVersion = compiler.hasBuildId ? compiler.buildId : null; | 95 dart2jsVersion = compiler.hasBuildId ? compiler.buildId : null; |
| 98 | 96 |
| 99 for (LibraryElement library in compiler.libraryLoader.libraries.toList()) { | 97 for (LibraryElement library in compiler.libraryLoader.libraries.toList()) { |
| 100 visit(library); | 98 visit(library); |
| 101 } | 99 } |
| 102 } | 100 } |
| 103 | 101 |
| 104 Map<String, dynamic> visit(Element e, [_]) => e.accept(this, null); | 102 Map<String, dynamic> visit(Element e, [_]) => e.accept(this, null); |
| 105 | 103 |
| 106 // 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 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 | 287 |
| 290 Map<String, dynamic> visitFunctionElement(FunctionElement element, _) { | 288 Map<String, dynamic> visitFunctionElement(FunctionElement element, _) { |
| 291 String id = mapper._function.add(element); | 289 String id = mapper._function.add(element); |
| 292 String name = element.name; | 290 String name = element.name; |
| 293 String kind = "function"; | 291 String kind = "function"; |
| 294 List<String> children = []; | 292 List<String> children = []; |
| 295 List<Map<String, dynamic>> parameters = []; | 293 List<Map<String, dynamic>> parameters = []; |
| 296 String inferredReturnType = null; | 294 String inferredReturnType = null; |
| 297 String returnType = null; | 295 String returnType = null; |
| 298 String sideEffects = null; | 296 String sideEffects = null; |
| 299 String code = ""; | |
| 300 | 297 |
| 301 StringBuffer emittedCode = compiler.dumpInfoTask.codeOf(element); | 298 StringBuffer emittedCode = compiler.dumpInfoTask.codeOf(element); |
| 302 int size = compiler.dumpInfoTask.sizeOf(element); | 299 int size = compiler.dumpInfoTask.sizeOf(element); |
| 303 | 300 |
| 304 Map<String, dynamic> modifiers = { | 301 Map<String, dynamic> modifiers = { |
| 305 'static': element.isStatic, | 302 'static': element.isStatic, |
| 306 'const': element.isConst, | 303 'const': element.isConst, |
| 307 'factory': element.isFactoryConstructor, | 304 'factory': element.isFactoryConstructor, |
| 308 'external': element.isPatched | 305 'external': element.isPatched |
| 309 }; | 306 }; |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 552 dumpInfoJson(jsonBuffer); | 549 dumpInfoJson(jsonBuffer); |
| 553 compiler.outputProvider('', 'info.json') | 550 compiler.outputProvider('', 'info.json') |
| 554 ..add(jsonBuffer.toString()) | 551 ..add(jsonBuffer.toString()) |
| 555 ..close(); | 552 ..close(); |
| 556 }); | 553 }); |
| 557 } | 554 } |
| 558 | 555 |
| 559 | 556 |
| 560 void dumpInfoJson(StringSink buffer) { | 557 void dumpInfoJson(StringSink buffer) { |
| 561 JsonEncoder encoder = const JsonEncoder.withIndent(' '); | 558 JsonEncoder encoder = const JsonEncoder.withIndent(' '); |
| 562 DateTime startToJsonTime = new DateTime.now(); | 559 var stopwatch = new Stopwatch(); |
|
Johnni Winther
2015/05/22 07:37:57
'var' -> 'Stopwatch'
kevmoo
2015/05/22 15:39:01
Done.
| |
| 560 stopwatch.start(); | |
| 563 | 561 |
| 564 Map<String, List<Map<String, String>>> holding = | 562 Map<String, List<Map<String, String>>> holding = |
| 565 <String, List<Map<String, String>>>{}; | 563 <String, List<Map<String, String>>>{}; |
| 566 for (Element fn in infoCollector.mapper.functions) { | 564 for (Element fn in infoCollector.mapper.functions) { |
| 567 Iterable<Selection> pulling = getRetaining(fn); | 565 Iterable<Selection> pulling = getRetaining(fn); |
| 568 // Don't bother recording an empty list of dependencies. | 566 // Don't bother recording an empty list of dependencies. |
| 569 if (pulling.length > 0) { | 567 if (pulling.length > 0) { |
| 570 String fnId = infoCollector.idOf(fn); | 568 String fnId = infoCollector.idOf(fn); |
| 571 // Some dart2js builtin functions are not | 569 // Some dart2js builtin functions are not |
| 572 // recorded. Don't register these. | 570 // recorded. Don't register these. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 621 'elements': infoCollector.toJson(), | 619 'elements': infoCollector.toJson(), |
| 622 'holding': holding, | 620 'holding': holding, |
| 623 'outputUnits': outputUnits, | 621 'outputUnits': outputUnits, |
| 624 'dump_version': 3, | 622 'dump_version': 3, |
| 625 'deferredFiles': compiler.deferredLoadTask.computeDeferredMap(), | 623 'deferredFiles': compiler.deferredLoadTask.computeDeferredMap(), |
| 626 // This increases when new information is added to the map, but the viewer | 624 // This increases when new information is added to the map, but the viewer |
| 627 // still is compatible. | 625 // still is compatible. |
| 628 'dump_minor_version': '2' | 626 'dump_minor_version': '2' |
| 629 }; | 627 }; |
| 630 | 628 |
| 631 Duration toJsonDuration = new DateTime.now().difference(startToJsonTime); | |
| 632 | |
| 633 Map<String, dynamic> generalProgramInfo = <String, dynamic> { | 629 Map<String, dynamic> generalProgramInfo = <String, dynamic> { |
| 634 'size': _programSize, | 630 'size': _programSize, |
| 635 'dart2jsVersion': infoCollector.dart2jsVersion, | 631 'dart2jsVersion': infoCollector.dart2jsVersion, |
| 636 'compilationMoment': new DateTime.now().toString(), | 632 'compilationMoment': new DateTime.now().toString(), |
| 637 'compilationDuration': compiler.totalCompileTime.elapsed.toString(), | 633 'compilationDuration': compiler.totalCompileTime.elapsed.toString(), |
| 638 'toJsonDuration': 0, | 634 'toJsonDuration': stopwatch.elapsedMilliseconds, |
| 639 'dumpInfoDuration': this.timing.toString(), | 635 'dumpInfoDuration': this.timing.toString(), |
| 640 'noSuchMethodEnabled': backend.enabledNoSuchMethod, | 636 'noSuchMethodEnabled': backend.enabledNoSuchMethod, |
| 641 'minified': compiler.enableMinification | 637 'minified': compiler.enableMinification |
| 642 }; | 638 }; |
| 643 | 639 |
| 644 outJson['program'] = generalProgramInfo; | 640 outJson['program'] = generalProgramInfo; |
| 645 | 641 |
| 646 ChunkedConversionSink<Object> sink = | 642 ChunkedConversionSink<Object> sink = |
| 647 encoder.startChunkedConversion( | 643 encoder.startChunkedConversion( |
| 648 new StringConversionSink.fromStringSink(buffer)); | 644 new StringConversionSink.fromStringSink(buffer)); |
| 649 sink.add(outJson); | 645 sink.add(outJson); |
| 650 compiler.reportInfo(NO_LOCATION_SPANNABLE, | 646 compiler.reportInfo(NO_LOCATION_SPANNABLE, |
| 651 const MessageKind( | 647 const MessageKind( |
| 652 "View the dumped .info.json file at " | 648 "View the dumped .info.json file at " |
| 653 "https://dart-lang.github.io/dump-info-visualizer")); | 649 "https://dart-lang.github.io/dump-info-visualizer")); |
| 654 } | 650 } |
| 655 } | 651 } |
| OLD | NEW |