| 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 'dart:async' show EventSink; |
| 8 | 8 |
| 9 import '../compiler.dart' as api; | 9 import '../compiler.dart' as api; |
| 10 import 'js_backend/namer.dart' show Namer; | 10 import 'js_backend/namer.dart' show Namer; |
| 11 import 'ssa/nodes.dart' as ssa show HGraph; | 11 import 'ssa/nodes.dart' as ssa show HGraph; |
| 12 import 'ssa/ssa_tracer.dart' show HTracer; | 12 import 'ssa/ssa_tracer.dart' show HTracer; |
| 13 import 'util/util.dart' show Indentation; | 13 import 'util/util.dart' show Indentation; |
| 14 import 'world.dart' show ClosedWorld; | 14 import 'world.dart' show ClosedWorld; |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * If non-null, we only trace methods whose name match the regexp defined by the | 17 * If non-null, we only trace methods whose name match the regexp defined by the |
| 18 * given pattern. | 18 * given pattern. |
| 19 */ | 19 */ |
| 20 const String TRACE_FILTER_PATTERN = const String.fromEnvironment("DUMP_IR"); | 20 String get TRACE_FILTER_PATTERN => |
| 21 TRACE_FILTER_PATTERN_FROM_ENVIRONMENT ?? TRACE_FILTER_PATTERN_FOR_TEST; |
| 21 | 22 |
| 22 final RegExp TRACE_FILTER = | 23 const String TRACE_FILTER_PATTERN_FROM_ENVIRONMENT = |
| 23 TRACE_FILTER_PATTERN == null ? null : new RegExp(TRACE_FILTER_PATTERN); | 24 const String.fromEnvironment("DUMP_IR"); |
| 25 String TRACE_FILTER_PATTERN_FOR_TEST; |
| 24 | 26 |
| 25 /** | 27 /** |
| 26 * Dumps the intermediate representation after each phase in a format | 28 * Dumps the intermediate representation after each phase in a format |
| 27 * readable by IR Hydra. | 29 * readable by IR Hydra. |
| 28 */ | 30 */ |
| 29 class Tracer extends TracerUtil { | 31 class Tracer extends TracerUtil { |
| 30 final ClosedWorld closedWorld; | 32 final ClosedWorld closedWorld; |
| 31 final Namer namer; | 33 final Namer namer; |
| 32 bool traceActive = false; | 34 bool traceActive = false; |
| 33 final EventSink<String> output; | 35 final EventSink<String> output; |
| 34 final bool isEnabled = TRACE_FILTER != null; | 36 final RegExp traceFilter; |
| 35 | 37 |
| 36 Tracer( | 38 Tracer( |
| 37 this.closedWorld, this.namer, api.CompilerOutputProvider outputProvider) | 39 this.closedWorld, this.namer, api.CompilerOutputProvider outputProvider) |
| 38 : output = TRACE_FILTER != null ? outputProvider('dart', 'cfg') : null; | 40 : traceFilter = TRACE_FILTER_PATTERN == null |
| 41 ? null |
| 42 : new RegExp(TRACE_FILTER_PATTERN), |
| 43 output = |
| 44 TRACE_FILTER_PATTERN != null ? outputProvider('dart', 'cfg') : null; |
| 45 |
| 46 bool get isEnabled => traceFilter != null; |
| 39 | 47 |
| 40 void traceCompilation(String methodName) { | 48 void traceCompilation(String methodName) { |
| 41 if (!isEnabled) return; | 49 if (!isEnabled) return; |
| 42 traceActive = TRACE_FILTER.hasMatch(methodName); | 50 traceActive = traceFilter.hasMatch(methodName); |
| 43 if (!traceActive) return; | 51 if (!traceActive) return; |
| 44 tag("compilation", () { | 52 tag("compilation", () { |
| 45 printProperty("name", methodName); | 53 printProperty("name", methodName); |
| 46 printProperty("method", methodName); | 54 printProperty("method", methodName); |
| 47 printProperty("date", new DateTime.now().millisecondsSinceEpoch); | 55 printProperty("date", new DateTime.now().millisecondsSinceEpoch); |
| 48 }); | 56 }); |
| 49 } | 57 } |
| 50 | 58 |
| 51 void traceGraph(String name, var irObject) { | 59 void traceGraph(String name, var irObject) { |
| 52 if (!traceActive) return; | 60 if (!traceActive) return; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 } | 107 } |
| 100 | 108 |
| 101 void add(String string) { | 109 void add(String string) { |
| 102 output.add(string); | 110 output.add(string); |
| 103 } | 111 } |
| 104 | 112 |
| 105 void addIndent() { | 113 void addIndent() { |
| 106 add(_ind.indentation); | 114 add(_ind.indentation); |
| 107 } | 115 } |
| 108 } | 116 } |
| OLD | NEW |