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

Unified Diff: pkg/analyzer/lib/src/generated/utilities_general.dart

Issue 918383002: Rework analysis server performance measurement code. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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 | « pkg/analyzer/lib/src/generated/source_io.dart ('k') | pkg/analyzer/lib/src/services/lint.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/utilities_general.dart
diff --git a/pkg/analyzer/lib/src/generated/utilities_general.dart b/pkg/analyzer/lib/src/generated/utilities_general.dart
index 927f6d6d3a7bbba003d08e30b3e1613a36b1c0c0..158a3cc82afddc769ab2a23550a2374d15236cd7 100644
--- a/pkg/analyzer/lib/src/generated/utilities_general.dart
+++ b/pkg/analyzer/lib/src/generated/utilities_general.dart
@@ -7,64 +7,110 @@
library engine.utilities.general;
+import 'dart:profiler';
+
/**
- * Helper for measuring how much time is spent doing some operation.
+ * Helper class for gathering performance statistics. This class is modeled on
+ * the UserTag class in dart:profiler so that it can interoperate easily with
+ * it.
*/
-class TimeCounter {
- static final int NANOS_PER_MILLI = 1000 * 1000;
- static final int NANOS_PER_MICRO = 1000;
- static TimeCounter _current = null;
- final Stopwatch _sw = new Stopwatch();
+abstract class PerformanceTag {
+ /**
+ * Return the [PerformanceTag] that is initially current. This is intended
+ * to track time when the system is performing unknown operations.
+ */
+ static PerformanceTag get UNKNOWN => _PerformanceTagImpl.UNKNOWN;
+
+ /**
+ * Return the current [PerformanceTag] for the isolate.
+ */
+ static PerformanceTag get current => _PerformanceTagImpl.current;
/**
- * @return the number of milliseconds spent between [start] and [stop].
+ * Create a [PerformanceTag] having the given [label]. A [UserTag] will also
+ * be created, having the same [label], so that performance information can
+ * be queried using the observatory.
*/
- int get result => _sw.elapsedMilliseconds;
+ factory PerformanceTag(String label) = _PerformanceTagImpl;
/**
- * Starts counting time.
+ * Return the label for this [PerformanceTag].
+ */
+ String get label;
+
+ /**
+ * Return a list of all [PerformanceTag]s which have been created.
+ */
+ static List<PerformanceTag> get all => _PerformanceTagImpl.all.toList();
+
+ /**
+ * Return the total number of milliseconds that this [PerformanceTag] has
+ * been the current [PerformanceTag] for the isolate.
*
- * @return the [TimeCounterHandle] that should be used to stop counting.
+ * This call is safe even if this [PerformanceTag] is current.
*/
- TimeCounter_TimeCounterHandle start() {
- return new TimeCounter_TimeCounterHandle(this);
- }
-}
+ int get elapsedMs;
-/**
- * The handle object that should be used to stop and update counter.
- */
-class TimeCounter_TimeCounterHandle {
- final TimeCounter _counter;
- int _startMicros;
- TimeCounter _prev;
-
- TimeCounter_TimeCounterHandle(this._counter) {
- // if there is some counter running, pause it
- _prev = TimeCounter._current;
- if (_prev != null) {
- _prev._sw.stop();
+ /**
+ * Make this the current tag for the isolate, and return the previous tag.
+ */
+ PerformanceTag makeCurrent();
+
+ /**
+ * Reset the total time tracked by all [PerformanceTag]s to zero.
+ */
+ static void reset() {
+ for (_PerformanceTagImpl tag in _PerformanceTagImpl.all) {
+ tag.stopwatch.reset();
}
- TimeCounter._current = _counter;
- // start this counter
- _startMicros = _counter._sw.elapsedMicroseconds;
- _counter._sw.start();
}
+}
+
+class _PerformanceTagImpl implements PerformanceTag {
+ /**
+ * The current performance tag for the isolate.
+ */
+ static _PerformanceTagImpl current = UNKNOWN;
+
+ static final _PerformanceTagImpl UNKNOWN = new _PerformanceTagImpl('unknown');
+
+ /**
+ * A list of all performance tags that have been created so far.
+ */
+ static List<_PerformanceTagImpl> all = <_PerformanceTagImpl>[];
+
+ @override
+ String get label => userTag.label;
+
+ /**
+ * The [UserTag] associated with this [PerformanceTag].
+ */
+ final UserTag userTag;
/**
- * Stops counting time and updates counter.
+ * Stopwatch tracking the amount of time this [PerformanceTag] has been the
+ * current tag for the isolate.
*/
- int stop() {
- _counter._sw.stop();
- int elapsed =
- (_counter._sw.elapsedMicroseconds - _startMicros) *
- TimeCounter.NANOS_PER_MICRO;
- // restore previous counter and resume it
- TimeCounter._current = _prev;
- if (_prev != null) {
- _prev._sw.start();
+ final Stopwatch stopwatch;
+
+ _PerformanceTagImpl(String label)
+ : userTag = new UserTag(label), stopwatch = new Stopwatch() {
+ all.add(this);
+ }
+
+ @override
+ PerformanceTag makeCurrent() {
+ if (identical(this, current)) {
+ return current;
}
- // done
- return elapsed;
+ _PerformanceTagImpl previous = current;
+ previous.stopwatch.stop();
+ stopwatch.start();
+ current = this;
+ userTag.makeCurrent();
+ return previous;
}
+
+ @override
+ int get elapsedMs => stopwatch.elapsedMilliseconds;
}
« no previous file with comments | « pkg/analyzer/lib/src/generated/source_io.dart ('k') | pkg/analyzer/lib/src/services/lint.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698