Timer.cpp revision d3a8d6565ff40fd99533f50a085ace806a9300ee
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 13using namespace lldb_perf; 14 15TimeGauge::TimeType 16TimeGauge::Now () 17{ 18 return high_resolution_clock::now(); 19} 20 21TimeGauge::TimeGauge () : 22m_start(), 23 m_state(TimeGauge::State::eNeverUsed) 24{ 25} 26 27void 28TimeGauge::Start () 29{ 30 m_state = TimeGauge::State::eCounting; 31 m_start = Now(); 32} 33 34double 35TimeGauge::Stop () 36{ 37 auto stop = Now(); 38 assert(m_state == TimeGauge::State::eCounting && "cannot stop a non-started clock"); 39 m_state = TimeGauge::State::eStopped; 40 return (m_value = duration_cast<duration<double>>(stop-m_start).count()); 41} 42 43double 44TimeGauge::GetValue () 45{ 46 assert(m_state == TimeGauge::State::eStopped && "clock must be used before you can evaluate it"); 47 return m_value; 48} 49