Timer.cpp revision 75fc5a74d95804e2ddc87bcade177640521147e0
1//
2//  Timer.cpp
3//  PerfTestDriver
4//
5//  Created by Enrico Granata on 3/6/13.
6//  Copyright (c) 2013 Apple Inc. All rights reserved.
7//
8
9#include "Timer.h"
10#include <assert.h>
11
12using namespace lldb_perf;
13
14TimeGauge::TimeType
15TimeGauge::Now ()
16{
17	return high_resolution_clock::now();
18}
19
20TimeGauge::TimeGauge () :
21m_start(),
22    m_state(TimeGauge::State::eNeverUsed)
23{
24}
25
26void
27TimeGauge::Start ()
28{
29	m_state = TimeGauge::State::eCounting;
30	m_start = Now();
31}
32
33double
34TimeGauge::Stop ()
35{
36	auto stop = Now();
37	assert(m_state == TimeGauge::State::eCounting && "cannot stop a non-started clock");
38	m_state = TimeGauge::State::eStopped;
39	return (m_value = duration_cast<duration<double>>(stop-m_start).count());
40}
41
42double
43TimeGauge::GetValue ()
44{
45	assert(m_state == TimeGauge::State::eStopped && "clock must be used before you can evaluate it");
46	return m_value;
47}
48