| 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' | 7 import 'dart:convert' |
| 8 show ChunkedConversionSink, JsonEncoder, StringConversionSink; | 8 show ChunkedConversionSink, JsonEncoder, StringConversionSink; |
| 9 | 9 |
| 10 import 'package:dart2js_info/info.dart'; | 10 import 'package:dart2js_info/info.dart'; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 import 'universe/world_builder.dart' show ReceiverConstraint; | 25 import 'universe/world_builder.dart' show ReceiverConstraint; |
| 26 import 'universe/world_impact.dart' | 26 import 'universe/world_impact.dart' |
| 27 show ImpactUseCase, WorldImpact, WorldImpactVisitorImpl; | 27 show ImpactUseCase, WorldImpact, WorldImpactVisitorImpl; |
| 28 import 'world.dart' show ClosedWorld; | 28 import 'world.dart' show ClosedWorld; |
| 29 | 29 |
| 30 class ElementInfoCollector extends BaseElementVisitor<Info, dynamic> { | 30 class ElementInfoCollector extends BaseElementVisitor<Info, dynamic> { |
| 31 final Compiler compiler; | 31 final Compiler compiler; |
| 32 final ClosedWorld closedWorld; | 32 final ClosedWorld closedWorld; |
| 33 | 33 |
| 34 final AllInfo result = new AllInfo(); | 34 final AllInfo result = new AllInfo(); |
| 35 final Map<Element, Info> _elementToInfo = <Element, Info>{}; | 35 final Map<Entity, Info> _elementToInfo = <Entity, Info>{}; |
| 36 final Map<ConstantValue, Info> _constantToInfo = <ConstantValue, Info>{}; | 36 final Map<ConstantValue, Info> _constantToInfo = <ConstantValue, Info>{}; |
| 37 final Map<OutputUnit, OutputUnitInfo> _outputToInfo = {}; | 37 final Map<OutputUnit, OutputUnitInfo> _outputToInfo = {}; |
| 38 | 38 |
| 39 ElementInfoCollector(this.compiler, this.closedWorld); | 39 ElementInfoCollector(this.compiler, this.closedWorld); |
| 40 | 40 |
| 41 void run() { | 41 void run() { |
| 42 compiler.dumpInfoTask._constantToNode.forEach((constant, node) { | 42 compiler.dumpInfoTask._constantToNode.forEach((constant, node) { |
| 43 // TODO(sigmund): add dependencies on other constants | 43 // TODO(sigmund): add dependencies on other constants |
| 44 var size = compiler.dumpInfoTask._nodeToSize[node]; | 44 var size = compiler.dumpInfoTask._nodeToSize[node]; |
| 45 var code = jsAst.prettyPrint(node, compiler.options); | 45 var code = jsAst.prettyPrint(node, compiler.options); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 58 /// | 58 /// |
| 59 /// By default we emit information for any element that contributes to the | 59 /// By default we emit information for any element that contributes to the |
| 60 /// output size. Either because the it is a function being emitted or inlined, | 60 /// output size. Either because the it is a function being emitted or inlined, |
| 61 /// or because it is an element that holds dependencies to other elements. | 61 /// or because it is an element that holds dependencies to other elements. |
| 62 bool shouldKeep(Element element) { | 62 bool shouldKeep(Element element) { |
| 63 return compiler.dumpInfoTask.impacts.containsKey(element) || | 63 return compiler.dumpInfoTask.impacts.containsKey(element) || |
| 64 compiler.dumpInfoTask.inlineCount.containsKey(element); | 64 compiler.dumpInfoTask.inlineCount.containsKey(element); |
| 65 } | 65 } |
| 66 | 66 |
| 67 /// Visits [element] and produces it's corresponding info. | 67 /// Visits [element] and produces it's corresponding info. |
| 68 Info process(Element element) { | 68 Info process(Entity element) { |
| 69 // TODO(sigmund): change the visit order to eliminate the need to check | 69 // TODO(sigmund): change the visit order to eliminate the need to check |
| 70 // whether or not an element has been processed. | 70 // whether or not an element has been processed. |
| 71 return _elementToInfo.putIfAbsent(element, () => visit(element)); | 71 return _elementToInfo.putIfAbsent(element, () => visit(element)); |
| 72 } | 72 } |
| 73 | 73 |
| 74 Info visitElement(Element element, _) => null; | 74 Info visitElement(Element element, _) => null; |
| 75 | 75 |
| 76 FunctionInfo visitConstructorBodyElement(ConstructorBodyElement e, _) { | 76 FunctionInfo visitConstructorBodyElement(ConstructorBodyElement e, _) { |
| 77 return visitFunctionElement(e.constructor, _); | 77 return visitFunctionElement(e.constructor, _); |
| 78 } | 78 } |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 return classInfo; | 207 return classInfo; |
| 208 } | 208 } |
| 209 | 209 |
| 210 ClosureInfo visitClosureClassElement(ClosureClassElement element, _) { | 210 ClosureInfo visitClosureClassElement(ClosureClassElement element, _) { |
| 211 ClosureInfo closureInfo = new ClosureInfo( | 211 ClosureInfo closureInfo = new ClosureInfo( |
| 212 name: element.name, | 212 name: element.name, |
| 213 outputUnit: _unitInfoForElement(element), | 213 outputUnit: _unitInfoForElement(element), |
| 214 size: compiler.dumpInfoTask.sizeOf(element)); | 214 size: compiler.dumpInfoTask.sizeOf(element)); |
| 215 _elementToInfo[element] = closureInfo; | 215 _elementToInfo[element] = closureInfo; |
| 216 | 216 |
| 217 ClosureClassMap closureMap = compiler.closureToClassMapper | 217 ClosureRepresentationInfo closureRepresentation = compiler |
| 218 .getClosureToClassMapping(element.methodElement); | 218 .closureToClassMapper |
| 219 assert(closureMap != null && closureMap.closureClassElement == element); | 219 .getClosureRepresentationInfo(element.methodElement); |
| 220 assert(closureRepresentation.closureClassEntity == element); |
| 220 | 221 |
| 221 FunctionInfo functionInfo = this.process(closureMap.callElement); | 222 FunctionInfo functionInfo = this.process(closureRepresentation.callMethod); |
| 222 if (functionInfo == null) return null; | 223 if (functionInfo == null) return null; |
| 223 closureInfo.function = functionInfo; | 224 closureInfo.function = functionInfo; |
| 224 functionInfo.parent = closureInfo; | 225 functionInfo.parent = closureInfo; |
| 225 | 226 |
| 226 result.closures.add(closureInfo); | 227 result.closures.add(closureInfo); |
| 227 return closureInfo; | 228 return closureInfo; |
| 228 } | 229 } |
| 229 | 230 |
| 230 FunctionInfo visitFunctionElement(FunctionElement element, _) { | 231 FunctionInfo visitFunctionElement(FunctionElement element, _) { |
| 231 int size = compiler.dumpInfoTask.sizeOf(element); | 232 int size = compiler.dumpInfoTask.sizeOf(element); |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 | 613 |
| 613 ChunkedConversionSink<Object> sink = encoder.startChunkedConversion( | 614 ChunkedConversionSink<Object> sink = encoder.startChunkedConversion( |
| 614 new StringConversionSink.fromStringSink(buffer)); | 615 new StringConversionSink.fromStringSink(buffer)); |
| 615 sink.add(new AllInfoJsonCodec().encode(result)); | 616 sink.add(new AllInfoJsonCodec().encode(result)); |
| 616 compiler.reporter.reportInfo(NO_LOCATION_SPANNABLE, MessageKind.GENERIC, { | 617 compiler.reporter.reportInfo(NO_LOCATION_SPANNABLE, MessageKind.GENERIC, { |
| 617 'text': "View the dumped .info.json file at " | 618 'text': "View the dumped .info.json file at " |
| 618 "https://dart-lang.github.io/dump-info-visualizer" | 619 "https://dart-lang.github.io/dump-info-visualizer" |
| 619 }); | 620 }); |
| 620 } | 621 } |
| 621 } | 622 } |
| OLD | NEW |