summaryrefslogtreecommitdiffstats
path: root/lldb/tools/lldb-perf/lib/Timer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/tools/lldb-perf/lib/Timer.cpp')
-rw-r--r--lldb/tools/lldb-perf/lib/Timer.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/lldb/tools/lldb-perf/lib/Timer.cpp b/lldb/tools/lldb-perf/lib/Timer.cpp
new file mode 100644
index 00000000000..59871aab4ce
--- /dev/null
+++ b/lldb/tools/lldb-perf/lib/Timer.cpp
@@ -0,0 +1,47 @@
+//
+// Timer.cpp
+// PerfTestDriver
+//
+// Created by Enrico Granata on 3/6/13.
+// Copyright (c) 2013 Apple Inc. All rights reserved.
+//
+
+#include "Timer.h"
+#include <assert.h>
+
+using namespace lldb::perf;
+
+TimeGauge::HPTime
+TimeGauge::now ()
+{
+ return high_resolution_clock::now();
+}
+
+TimeGauge::TimeGauge () :
+m_start(),
+m_state(TimeGauge::State::eTSNeverUsed)
+{
+}
+
+void
+TimeGauge::start ()
+{
+ m_state = TimeGauge::State::eTSCounting;
+ m_start = now();
+}
+
+double
+TimeGauge::stop ()
+{
+ auto stop = now();
+ assert(m_state == TimeGauge::State::eTSCounting && "cannot stop a non-started clock");
+ m_state = TimeGauge::State::eTSStopped;
+ return (m_value = duration_cast<duration<double>>(stop-m_start).count());
+}
+
+double
+TimeGauge::value ()
+{
+ assert(m_state == TimeGauge::State::eTSStopped && "clock must be used before you can evaluate it");
+ return m_value;
+}
OpenPOWER on IntegriCloud