Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Unified Diff: sdk/lib/profiler/profiler.dart

Issue 230863005: Initial UserTag and dart:profiler library (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/_internal/libraries.dart ('k') | sdk/lib/profiler/profiler_sources.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/profiler/profiler.dart
diff --git a/sdk/lib/profiler/profiler.dart b/sdk/lib/profiler/profiler.dart
new file mode 100644
index 0000000000000000000000000000000000000000..56614ddec0c5cc7fb4db5bee186b9b692463b43d
--- /dev/null
+++ b/sdk/lib/profiler/profiler.dart
@@ -0,0 +1,66 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library dart.profiler;
+
+/// A UserTag can be used to group samples in the Observatory profiler.
+abstract class UserTag {
+ /// The maximum number of UserTag instances that can be created by a program.
+ static const MAX_USER_TAGS = 64;
+
+ factory UserTag(String label) => new _FakeUserTag(label);
+
+ /// Label of [this].
+ String get label;
+
+ /// Make [this] the current tag for the isolate.
+ makeCurrent();
+}
+
+// This is a fake implementation of UserTag so that code can compile and run
+// in dart2js.
+class _FakeUserTag implements UserTag {
+ static List _instances = [];
+
+ _FakeUserTag.real(this.label);
+
+ factory _FakeUserTag(String label) {
+ // Canonicalize by name.
+ for (var tag in _instances) {
+ if (tag.label == label) {
+ return tag;
+ }
+ }
+ // Throw an exception if we've reached the maximum number of user tags.
+ if (_instances.length == UserTag.MAX_USER_TAGS) {
+ throw new UnsupportedError(
+ 'UserTag instance limit (${UserTag.MAX_USER_TAGS}) reached.');
+ }
+ // Create a new instance and add it to the instance list.
+ var instance = new _FakeUserTag.real(label);
+ _instances.add(instance);
+ return instance;
+ }
+
+ final String label;
+
+ makeCurrent() {
+ _currentTag = this;
+ }
+}
+
+var _currentTag = null;
+
+/// Returns the current [UserTag] for the isolate.
+UserTag getCurrentTag() {
+ return _currentTag;
+}
+
+/// Sets the current [UserTag] for the isolate to null. Returns current tag
+/// before clearing.
+UserTag clearCurrentTag() {
+ var old = _currentTag;
+ _currentTag = null;
+ return old;
+}
« no previous file with comments | « sdk/lib/_internal/libraries.dart ('k') | sdk/lib/profiler/profiler_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698