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

Unified Diff: pkg/fasta/lib/src/ticker.dart

Issue 2634453004: Fasta infrastructure. (Closed)
Patch Set: Created 3 years, 11 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
Index: pkg/fasta/lib/src/ticker.dart
diff --git a/pkg/fasta/lib/src/ticker.dart b/pkg/fasta/lib/src/ticker.dart
new file mode 100644
index 0000000000000000000000000000000000000000..ffa94366efed4edbcc29aac4345fe12aae104128
--- /dev/null
+++ b/pkg/fasta/lib/src/ticker.dart
@@ -0,0 +1,32 @@
+// Copyright (c) 2016, 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 fasta.ticker;
+
+class Ticker {
+ final Stopwatch sw = new Stopwatch()..start();
+
+ bool isVerbose;
+
+ Duration previousTick;
+
+ Ticker({this.isVerbose: true}) {
+ previousTick = sw.elapsed;
+ }
+
+ void logMs(Object message) {
+ log((Duration elapsed, Duration sinceStart) {
+ print("$sinceStart: $message in ${elapsed.inMilliseconds}ms.");
+ });
+ }
+
+ void log(void f(Duration elapsed, Duration sinceStart)) {
+ Duration elapsed = sw.elapsed;
+ try {
+ if (isVerbose) f(elapsed - previousTick, elapsed);
+ } finally {
+ previousTick = sw.elapsed;
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698