Chromium Code Reviews| 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..6054b264da3bc5f160827fd0e7984ccad3adcae2 |
| --- /dev/null |
| +++ b/sdk/lib/profiler/profiler.dart |
| @@ -0,0 +1,64 @@ |
| +// 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.c |
|
siva
2014/04/10 21:35:24
isolate.c ??
Cutch
2014/04/10 22:18:30
Done.
|
| + makeCurrent(); |
| +} |
| + |
| +class _FakeUserTag implements UserTag { |
|
siva
2014/04/10 21:35:24
Maybe add a comment on top of this class to indica
Cutch
2014/04/10 22:18:30
Done.
|
| + 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; |
| +} |