| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 tracer; | 5 library tracer; |
| 6 | 6 |
| 7 import 'dart:async' show EventSink; | 7 import '../compiler_new.dart' as api; |
| 8 | 8 import 'compiler.dart' show Compiler; |
| 9 import '../compiler.dart' as api; | |
| 10 import 'js_backend/namer.dart' show Namer; | 9 import 'js_backend/namer.dart' show Namer; |
| 11 import 'ssa/nodes.dart' as ssa show HGraph; | 10 import 'ssa/nodes.dart' as ssa show HGraph; |
| 12 import 'ssa/ssa_tracer.dart' show HTracer; | 11 import 'ssa/ssa_tracer.dart' show HTracer; |
| 13 import 'util/util.dart' show Indentation; | 12 import 'util/util.dart' show Indentation; |
| 14 import 'world.dart' show ClosedWorld; | 13 import 'world.dart' show ClosedWorld; |
| 15 | 14 |
| 16 /** | 15 /** |
| 17 * If non-null, we only trace methods whose name match the regexp defined by the | 16 * If non-null, we only trace methods whose name match the regexp defined by the |
| 18 * given pattern. | 17 * given pattern. |
| 19 */ | 18 */ |
| 20 String get TRACE_FILTER_PATTERN => | 19 String get TRACE_FILTER_PATTERN => |
| 21 TRACE_FILTER_PATTERN_FROM_ENVIRONMENT ?? TRACE_FILTER_PATTERN_FOR_TEST; | 20 TRACE_FILTER_PATTERN_FROM_ENVIRONMENT ?? TRACE_FILTER_PATTERN_FOR_TEST; |
| 22 | 21 |
| 23 const String TRACE_FILTER_PATTERN_FROM_ENVIRONMENT = | 22 const String TRACE_FILTER_PATTERN_FROM_ENVIRONMENT = |
| 24 const String.fromEnvironment("DUMP_IR"); | 23 const String.fromEnvironment("DUMP_IR"); |
| 25 String TRACE_FILTER_PATTERN_FOR_TEST; | 24 String TRACE_FILTER_PATTERN_FOR_TEST; |
| 26 | 25 |
| 27 /** | 26 /** |
| 28 * Dumps the intermediate representation after each phase in a format | 27 * Dumps the intermediate representation after each phase in a format |
| 29 * readable by IR Hydra. | 28 * readable by IR Hydra. |
| 30 */ | 29 */ |
| 31 class Tracer extends TracerUtil { | 30 class Tracer extends TracerUtil { |
| 32 final ClosedWorld closedWorld; | 31 final ClosedWorld closedWorld; |
| 33 final Namer namer; | 32 final Namer namer; |
| 34 bool traceActive = false; | 33 bool traceActive = false; |
| 35 final EventSink<String> output; | 34 final api.OutputSink output; |
| 36 final RegExp traceFilter; | 35 final RegExp traceFilter; |
| 37 | 36 |
| 38 Tracer( | 37 Tracer(this.closedWorld, this.namer, Compiler compiler) |
| 39 this.closedWorld, this.namer, api.CompilerOutputProvider outputProvider) | |
| 40 : traceFilter = TRACE_FILTER_PATTERN == null | 38 : traceFilter = TRACE_FILTER_PATTERN == null |
| 41 ? null | 39 ? null |
| 42 : new RegExp(TRACE_FILTER_PATTERN), | 40 : new RegExp(TRACE_FILTER_PATTERN), |
| 43 output = | 41 output = TRACE_FILTER_PATTERN != null |
| 44 TRACE_FILTER_PATTERN != null ? outputProvider('dart', 'cfg') : null; | 42 ? compiler.outputProvider('dart', 'cfg', api.OutputType.debug) |
| 43 : null; |
| 45 | 44 |
| 46 bool get isEnabled => traceFilter != null; | 45 bool get isEnabled => traceFilter != null; |
| 47 | 46 |
| 48 void traceCompilation(String methodName) { | 47 void traceCompilation(String methodName) { |
| 49 if (!isEnabled) return; | 48 if (!isEnabled) return; |
| 50 traceActive = traceFilter.hasMatch(methodName); | 49 traceActive = traceFilter.hasMatch(methodName); |
| 51 if (!traceActive) return; | 50 if (!traceActive) return; |
| 52 tag("compilation", () { | 51 tag("compilation", () { |
| 53 printProperty("name", methodName); | 52 printProperty("name", methodName); |
| 54 printProperty("method", methodName); | 53 printProperty("method", methodName); |
| 55 printProperty("date", new DateTime.now().millisecondsSinceEpoch); | 54 printProperty("date", new DateTime.now().millisecondsSinceEpoch); |
| 56 }); | 55 }); |
| 57 } | 56 } |
| 58 | 57 |
| 59 void traceGraph(String name, var irObject) { | 58 void traceGraph(String name, var irObject) { |
| 60 if (!traceActive) return; | 59 if (!traceActive) return; |
| 61 if (irObject is ssa.HGraph) { | 60 if (irObject is ssa.HGraph) { |
| 62 new HTracer(output, closedWorld, namer).traceGraph(name, irObject); | 61 new HTracer(output, closedWorld, namer).traceGraph(name, irObject); |
| 63 } | 62 } |
| 64 } | 63 } |
| 65 | 64 |
| 66 void close() { | 65 void close() { |
| 67 if (output != null) { | 66 if (output != null) { |
| 68 output.close(); | 67 output.close(); |
| 69 } | 68 } |
| 70 } | 69 } |
| 71 } | 70 } |
| 72 | 71 |
| 73 abstract class TracerUtil { | 72 abstract class TracerUtil { |
| 74 EventSink<String> get output; | 73 api.OutputSink get output; |
| 75 final Indentation _ind = new Indentation(); | 74 final Indentation _ind = new Indentation(); |
| 76 | 75 |
| 77 void tag(String tagName, Function f) { | 76 void tag(String tagName, Function f) { |
| 78 println("begin_$tagName"); | 77 println("begin_$tagName"); |
| 79 _ind.indentBlock(f); | 78 _ind.indentBlock(f); |
| 80 println("end_$tagName"); | 79 println("end_$tagName"); |
| 81 } | 80 } |
| 82 | 81 |
| 83 void println(String string) { | 82 void println(String string) { |
| 84 addIndent(); | 83 addIndent(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 107 } | 106 } |
| 108 | 107 |
| 109 void add(String string) { | 108 void add(String string) { |
| 110 output.add(string); | 109 output.add(string); |
| 111 } | 110 } |
| 112 | 111 |
| 113 void addIndent() { | 112 void addIndent() { |
| 114 add(_ind.indentation); | 113 add(_ind.indentation); |
| 115 } | 114 } |
| 116 } | 115 } |
| OLD | NEW |