Timer.cpp revision 9de4dec874148d30cc1d4c498d38cd048a8164ca
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#include "CFCMutableDictionary.h" 14#include "CFCString.h" 15 16using namespace lldb_perf; 17 18TimeGauge::TimeType 19TimeGauge::Now () 20{ 21 return high_resolution_clock::now(); 22} 23 24TimeGauge::TimeGauge () : 25 m_start(), 26 m_state(TimeGauge::State::eNeverUsed) 27{ 28} 29 30void 31TimeGauge::Start () 32{ 33 m_state = TimeGauge::State::eCounting; 34 m_start = Now(); 35} 36 37double 38TimeGauge::Stop () 39{ 40 m_stop = Now(); 41 assert(m_state == TimeGauge::State::eCounting && "cannot stop a non-started clock"); 42 m_state = TimeGauge::State::eStopped; 43 m_delta = duration_cast<duration<double>>(m_stop-m_start).count(); 44 return m_delta; 45} 46 47double 48TimeGauge::GetStartValue () const 49{ 50 return (double)m_start.time_since_epoch().count() * (double)system_clock::period::num / (double)system_clock::period::den; 51} 52 53double 54TimeGauge::GetStopValue () const 55{ 56 return (double)m_stop.time_since_epoch().count() * (double)system_clock::period::num / (double)system_clock::period::den; 57} 58 59double 60TimeGauge::GetDeltaValue () const 61{ 62 assert(m_state == TimeGauge::State::eStopped && "clock must be used before you can evaluate it"); 63 return m_delta; 64} 65