1 //===-- Timer.cpp -----------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "Timer.h"
11 #include <assert.h>
12 
13 using namespace lldb_perf;
14 
15 TimeGauge::TimeType
Now()16 TimeGauge::Now ()
17 {
18 	return high_resolution_clock::now();
19 }
20 
TimeGauge()21 TimeGauge::TimeGauge () :
22     m_start(),
23     m_state(TimeGauge::State::eNeverUsed)
24 {
25 }
26 
27 void
Start()28 TimeGauge::Start ()
29 {
30 	m_state = TimeGauge::State::eCounting;
31 	m_start = Now();
32 }
33 
34 double
Stop()35 TimeGauge::Stop ()
36 {
37 	m_stop = Now();
38 	assert(m_state == TimeGauge::State::eCounting && "cannot stop a non-started clock");
39 	m_state = TimeGauge::State::eStopped;
40     m_delta = duration_cast<duration<double>>(m_stop-m_start).count();
41 	return m_delta;
42 }
43 
44 double
GetStartValue() const45 TimeGauge::GetStartValue () const
46 {
47     return (double)m_start.time_since_epoch().count() * (double)system_clock::period::num / (double)system_clock::period::den;
48 }
49 
50 double
GetStopValue() const51 TimeGauge::GetStopValue () const
52 {
53     return (double)m_stop.time_since_epoch().count() * (double)system_clock::period::num / (double)system_clock::period::den;
54 }
55 
56 double
GetDeltaValue() const57 TimeGauge::GetDeltaValue () const
58 {
59 	assert(m_state == TimeGauge::State::eStopped && "clock must be used before you can evaluate it");
60 	return m_delta;
61 }
62