Files
sdk/runtime/vm/scope_timer.h
T
Ryan Macnak 9b5a931b06 [vm] Replace most runtime/vm uses of OS::Print with OS::PrintErr.
Leave --print-snapshot-sizes on stdout because it is parsed by Flutter benchmarks.

Replace all runtime/bin uses of OS::Print with Log::Print.

Bug: https://github.com/dart-lang/sdk/issues/32134
Change-Id: I74aacfb410cdfa9270d06e7f6ab0534520c7c7ba
Reviewed-on: https://dart-review.googlesource.com/60021
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Zach Anderson <zra@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2018-06-13 19:51:40 +00:00

48 lines
1.1 KiB
C++

// 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 RUNTIME_VM_SCOPE_TIMER_H_
#define RUNTIME_VM_SCOPE_TIMER_H_
#include "platform/globals.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)
: enabled_(enabled), name_(name), start_(0) {
if (!enabled_) {
return;
}
start_ = OS::GetCurrentMonotonicMicros();
}
int64_t GetElapsed() const {
int64_t end = OS::GetCurrentMonotonicMicros();
ASSERT(end >= start_);
return end - start_;
}
~ScopeTimer() {
if (!enabled_) {
return;
}
int64_t elapsed = GetElapsed();
double seconds = MicrosecondsToSeconds(elapsed);
OS::PrintErr("%s: %f seconds (%" Pd64 " \u00B5s)\n", name_, seconds,
elapsed);
}
private:
const bool enabled_;
const char* name_;
int64_t start_;
};
} // namespace dart
#endif // RUNTIME_VM_SCOPE_TIMER_H_