Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library dart.profiler; | |
| 6 | |
| 7 /// A UserTag can be used to group samples in the Observatory profiler. | |
| 8 abstract class UserTag { | |
| 9 /// The maximum number of UserTag instances that can be created by a program. | |
| 10 static const MAX_USER_TAGS = 64; | |
| 11 | |
| 12 factory UserTag(String label) => new _FakeUserTag(label); | |
| 13 | |
| 14 /// Label of [this]. | |
| 15 String get label; | |
| 16 | |
| 17 /// 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.
| |
| 18 makeCurrent(); | |
| 19 } | |
| 20 | |
| 21 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.
| |
| 22 static List _instances = []; | |
| 23 | |
| 24 _FakeUserTag.real(this.label); | |
| 25 | |
| 26 factory _FakeUserTag(String label) { | |
| 27 // Canonicalize by name. | |
| 28 for (var tag in _instances) { | |
| 29 if (tag.label == label) { | |
| 30 return tag; | |
| 31 } | |
| 32 } | |
| 33 // Throw an exception if we've reached the maximum number of user tags. | |
| 34 if (_instances.length == UserTag.MAX_USER_TAGS) { | |
| 35 throw new UnsupportedError( | |
| 36 'UserTag instance limit (${UserTag.MAX_USER_TAGS}) reached.'); | |
| 37 } | |
| 38 // Create a new instance and add it to the instance list. | |
| 39 var instance = new _FakeUserTag.real(label); | |
| 40 _instances.add(instance); | |
| 41 return instance; | |
| 42 } | |
| 43 | |
| 44 final String label; | |
| 45 | |
| 46 makeCurrent() { | |
| 47 _currentTag = this; | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 var _currentTag = null; | |
| 52 | |
| 53 /// Returns the current [UserTag] for the isolate. | |
| 54 UserTag getCurrentTag() { | |
| 55 return _currentTag; | |
| 56 } | |
| 57 | |
| 58 /// Sets the current [UserTag] for the isolate to null. Returns current tag | |
| 59 /// before clearing. | |
| 60 UserTag clearCurrentTag() { | |
| 61 var old = _currentTag; | |
| 62 _currentTag = null; | |
| 63 return old; | |
| 64 } | |
| OLD | NEW |