Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
scope_timer.h
Go to the documentation of this file.
1// Copyright (c) 2015, 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#ifndef RUNTIME_VM_SCOPE_TIMER_H_
6#define RUNTIME_VM_SCOPE_TIMER_H_
7
9#include "platform/globals.h"
10
11#include "vm/os.h"
12
13namespace dart {
14
15// Simple utility class for timing a block of code.
16class ScopeTimer : public ValueObject {
17 public:
18 explicit ScopeTimer(const char* name, bool enabled = true)
19 : enabled_(enabled), name_(name), start_(0) {
20 if (!enabled_) {
21 return;
22 }
24 }
25
26 int64_t GetElapsed() const {
28 ASSERT(end >= start_);
29 return end - start_;
30 }
31
33 if (!enabled_) {
34 return;
35 }
36 int64_t elapsed = GetElapsed();
37 double seconds = MicrosecondsToSeconds(elapsed);
38 OS::PrintErr("%s: %.2f seconds (%" Pd64 " \u00B5s)\n", name_, seconds,
39 elapsed);
40 }
41
42 private:
43 const bool enabled_;
44 const char* name_;
45 int64_t start_;
46};
47
48} // namespace dart
49
50#endif // RUNTIME_VM_SCOPE_TIMER_H_
static int64_t GetCurrentMonotonicMicros()
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
ScopeTimer(const char *name, bool enabled=true)
Definition scope_timer.h:18
int64_t GetElapsed() const
Definition scope_timer.h:26
#define ASSERT(E)
glong glong end
const char *const name
constexpr double MicrosecondsToSeconds(int64_t micros)
Definition globals.h:571
#define Pd64
Definition globals.h:416