Index: pkg/compiler/lib/src/helpers/helpers.dart |
diff --git a/pkg/compiler/lib/src/helpers/helpers.dart b/pkg/compiler/lib/src/helpers/helpers.dart |
index bcfa12c9b5ff6b0d3ce3f92cb1f66d4ddd3bbc8d..9f7e2848fe6aab78a3b36e62fb9aa52c9d37f32e 100644 |
--- a/pkg/compiler/lib/src/helpers/helpers.dart |
+++ b/pkg/compiler/lib/src/helpers/helpers.dart |
@@ -93,3 +93,52 @@ _reportHere(Compiler compiler, Spannable node, String debugMessage) { |
compiler.reportInfo(node, |
MessageKind.GENERIC, {'text': 'HERE: $debugMessage'}); |
} |
+ |
+/// Set of tracked objects used by [track] and [ifTracked]. |
+var _trackedObjects = new Set(); |
+ |
+/// Global default value for the `printTrace` option of [track] and [ifTracked]. |
+bool trackWithTrace = false; |
+ |
+/// If [doTrack] is `true`, add [object] to the set of tracked objects. |
+/// |
+/// If tracked, [message] is printed along the hash code and toString of |
+/// [object]. If [printTrace] is `true` a trace printed additionally. |
+/// If [printTrace] is `null`, [trackWithTrace] determines whether a trace is |
+/// printed. |
+/// |
+/// [object] is returned as the result of the method. |
+track(bool doTrack, Object object, String message, {bool printTrace}) { |
+ if (!doTrack) return object; |
+ _trackedObjects.add(object); |
+ String msg = 'track: ${object.hashCode}:$object:$message'; |
+ if (printTrace == null) printTrace = trackWithTrace; |
+ if (printTrace) { |
+ trace(msg); |
+ } else { |
+ debugPrint(msg); |
+ } |
+ return object; |
+} |
+ |
+/// Returns `true` if [object] is in the set of tracked objects. |
+/// |
+/// If [message] is provided it is printed along the hash code and toString of |
+/// [object]. If [printTrace] is `true` a trace printed additionally. If |
+/// [printTrace] is `null`, [trackWithTrace] determines whether a trace is |
+/// printed. |
+bool ifTracked(Object object, {String message, bool printTrace}) { |
+ if (_trackedObjects.contains(object)) { |
+ if (message != null) { |
+ String msg = 'tracked: ${object.hashCode}:$object:$message'; |
+ if (printTrace == null) printTrace = trackWithTrace; |
+ if (printTrace) { |
+ trace(msg); |
+ } else { |
+ debugPrint(msg); |
+ } |
+ } |
+ return true; |
+ } |
+ return false; |
+} |