6d313d3797
R=johnmccutchan@google.com, turnidge@google.com Review URL: https://codereview.chromium.org//137483010 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@32930 260f80e4-7a28-3924-810f-c04153c831b5
127 lines
3.4 KiB
C++
127 lines
3.4 KiB
C++
// Copyright (c) 2011, 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_TIMER_H_
|
|
#define VM_TIMER_H_
|
|
|
|
#include "vm/allocation.h"
|
|
#include "vm/flags.h"
|
|
#include "vm/os.h"
|
|
|
|
namespace dart {
|
|
|
|
class JSONObject;
|
|
|
|
// Timer class allows timing of specific operations in the VM.
|
|
class Timer : public ValueObject {
|
|
public:
|
|
Timer(bool report, const char* message)
|
|
: start_(0), stop_(0), total_(0),
|
|
report_(report), running_(false), message_(message) {}
|
|
~Timer() {}
|
|
|
|
// Start timer.
|
|
void Start() {
|
|
start_ = OS::GetCurrentTimeMicros();
|
|
running_ = true;
|
|
}
|
|
|
|
// Stop timer.
|
|
void Stop() {
|
|
ASSERT(start_ != 0);
|
|
ASSERT(running());
|
|
stop_ = OS::GetCurrentTimeMicros();
|
|
total_ += ElapsedMicros();
|
|
running_ = false;
|
|
}
|
|
|
|
// Get total cummulative elapsed time in micros.
|
|
int64_t TotalElapsedTime() const {
|
|
int64_t result = total_;
|
|
if (running_) {
|
|
int64_t now = OS::GetCurrentTimeMicros();
|
|
result += (now - start_);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
void Reset() {
|
|
start_ = 0;
|
|
stop_ = 0;
|
|
total_ = 0;
|
|
running_ = false;
|
|
}
|
|
|
|
// Accessors.
|
|
bool report() const { return report_; }
|
|
bool running() const { return running_; }
|
|
const char* message() const { return message_; }
|
|
|
|
private:
|
|
int64_t ElapsedMicros() const {
|
|
ASSERT(start_ != 0);
|
|
ASSERT(stop_ != 0);
|
|
return stop_ - start_;
|
|
}
|
|
|
|
int64_t start_;
|
|
int64_t stop_;
|
|
int64_t total_;
|
|
bool report_;
|
|
bool running_;
|
|
const char* message_;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(Timer);
|
|
};
|
|
|
|
// List of per isolate timers.
|
|
#define TIMER_LIST(V) \
|
|
V(time_script_loading, "Script Loading") \
|
|
V(time_creating_snapshot, "Snapshot Creation") \
|
|
V(time_isolate_initialization, "Isolate initialization") \
|
|
V(time_compilation, "Function compilation") \
|
|
V(time_bootstrap, "Bootstrap of core classes") \
|
|
V(time_dart_execution, "Dart execution") \
|
|
V(time_native_execution, "Native code execution") \
|
|
V(time_total_runtime, "Total runtime for isolate") \
|
|
|
|
// Maintains a list of timers per isolate.
|
|
class TimerList : public ValueObject {
|
|
public:
|
|
TimerList();
|
|
~TimerList() {}
|
|
|
|
// Accessors.
|
|
#define TIMER_FIELD_ACCESSOR(name, msg) \
|
|
Timer& name() { return name##_; }
|
|
TIMER_LIST(TIMER_FIELD_ACCESSOR)
|
|
#undef TIMER_FIELD_ACCESSOR
|
|
|
|
void ReportTimers();
|
|
void ReportTimerState(const char* prefix);
|
|
|
|
void PrintTimersToJSONProperty(JSONObject* jsobj);
|
|
|
|
private:
|
|
#define TIMER_FIELD(name, msg) Timer name##_;
|
|
TIMER_LIST(TIMER_FIELD)
|
|
#undef TIMER_FIELD
|
|
bool padding_;
|
|
DISALLOW_COPY_AND_ASSIGN(TimerList);
|
|
};
|
|
|
|
// Timer Usage.
|
|
#define START_TIMER(isolate, name) \
|
|
isolate->timer_list().name().Start();
|
|
|
|
#define STOP_TIMER(isolate, name) \
|
|
isolate->timer_list().name().Stop();
|
|
|
|
#define TIMER_STATE(isolate, prefix) \
|
|
isolate->timer_list().ReportTimerState(prefix);
|
|
|
|
} // namespace dart
|
|
|
|
#endif // VM_TIMER_H_
|