2013-03-21 11:39:51 +08:00
|
|
|
//===-- Timer.cpp -----------------------------------------------*- C++ -*-===//
|
2013-03-09 04:29:13 +08:00
|
|
|
//
|
2013-03-21 11:39:51 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
2013-03-09 04:29:13 +08:00
|
|
|
//
|
2013-03-21 11:39:51 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2013-03-09 04:29:13 +08:00
|
|
|
//
|
2013-03-21 11:39:51 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2013-03-09 04:29:13 +08:00
|
|
|
|
|
|
|
#include "Timer.h"
|
|
|
|
#include <assert.h>
|
|
|
|
|
2013-03-19 06:34:00 +08:00
|
|
|
using namespace lldb_perf;
|
2013-03-09 04:29:13 +08:00
|
|
|
|
2013-03-21 11:32:24 +08:00
|
|
|
TimeGauge::TimeType
|
|
|
|
TimeGauge::Now ()
|
2013-03-09 04:29:13 +08:00
|
|
|
{
|
|
|
|
return high_resolution_clock::now();
|
|
|
|
}
|
|
|
|
|
|
|
|
TimeGauge::TimeGauge () :
|
2013-03-22 10:31:35 +08:00
|
|
|
m_start(),
|
2013-03-21 11:32:24 +08:00
|
|
|
m_state(TimeGauge::State::eNeverUsed)
|
2013-03-09 04:29:13 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-03-21 11:32:24 +08:00
|
|
|
TimeGauge::Start ()
|
2013-03-09 04:29:13 +08:00
|
|
|
{
|
2013-03-21 11:32:24 +08:00
|
|
|
m_state = TimeGauge::State::eCounting;
|
|
|
|
m_start = Now();
|
2013-03-09 04:29:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
2013-03-21 11:32:24 +08:00
|
|
|
TimeGauge::Stop ()
|
2013-03-09 04:29:13 +08:00
|
|
|
{
|
2013-03-22 10:31:35 +08:00
|
|
|
m_stop = Now();
|
2013-03-21 11:32:24 +08:00
|
|
|
assert(m_state == TimeGauge::State::eCounting && "cannot stop a non-started clock");
|
|
|
|
m_state = TimeGauge::State::eStopped;
|
2013-03-22 10:31:35 +08:00
|
|
|
m_delta = duration_cast<duration<double>>(m_stop-m_start).count();
|
|
|
|
return m_delta;
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
TimeGauge::GetStartValue () const
|
|
|
|
{
|
|
|
|
return (double)m_start.time_since_epoch().count() * (double)system_clock::period::num / (double)system_clock::period::den;
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
TimeGauge::GetStopValue () const
|
|
|
|
{
|
|
|
|
return (double)m_stop.time_since_epoch().count() * (double)system_clock::period::num / (double)system_clock::period::den;
|
2013-03-09 04:29:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
2013-03-22 10:31:35 +08:00
|
|
|
TimeGauge::GetDeltaValue () const
|
2013-03-09 04:29:13 +08:00
|
|
|
{
|
2013-03-21 11:32:24 +08:00
|
|
|
assert(m_state == TimeGauge::State::eStopped && "clock must be used before you can evaluate it");
|
2013-03-22 10:31:35 +08:00
|
|
|
return m_delta;
|
2013-03-09 04:29:13 +08:00
|
|
|
}
|