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

Unified Diff: runtime/vm/scope_timer.h

Issue 864173008: Split profiler.cc into profiler.cc and profiler_service.cc (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 | « runtime/vm/profiler_service.cc ('k') | runtime/vm/service.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/scope_timer.h
diff --git a/runtime/vm/scope_timer.h b/runtime/vm/scope_timer.h
new file mode 100644
index 0000000000000000000000000000000000000000..b90270b52a122067e46741e83d69d2363afc4bce
--- /dev/null
+++ b/runtime/vm/scope_timer.h
@@ -0,0 +1,44 @@
+// Copyright (c) 2015, 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.
+
+#ifndef VM_SCOPE_TIMER_H_
+#define VM_SCOPE_TIMER_H_
+
+namespace dart {
+
+// Simple utility class for timing a block of code.
+class ScopeTimer : public ValueObject {
+ public:
+ explicit ScopeTimer(const char* name, bool enabled = true)
siva 2015/02/09 23:19:59 constructor has two params, is 'explicit' still ne
Cutch 2015/02/09 23:22:07 Acknowledged.
+ : enabled_(enabled),
+ name_(name) {
+ if (!enabled_) {
+ return;
+ }
+ start_ = OS::GetCurrentTimeMicros();
+ }
+
+ int64_t GetElapsed() const {
+ int64_t end = OS::GetCurrentTimeMicros();
+ ASSERT(end >= start_);
+ return end - start_;
+ }
+
+ ~ScopeTimer() {
+ if (!enabled_) {
+ return;
+ }
+ int64_t elapsed = GetElapsed();
+ OS::Print("%s took %" Pd64 " micros.\n", name_, elapsed);
+ }
+
+ private:
+ const bool enabled_;
+ const char* name_;
+ int64_t start_;
siva 2015/02/09 23:19:59 Missing the boiler plate DISALLOW stuff.
Cutch 2015/02/09 23:22:07 Acknowledged.
+};
+
+} // namespace dart
+
+#endif // VM_SCOPE_TIMER_H_
« no previous file with comments | « runtime/vm/profiler_service.cc ('k') | runtime/vm/service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698