about summary refs log tree commit diff homepage
path: root/lib/Support/Timer.cpp
diff options
context:
space:
mode:
authorFrank Busse <bb0xfb@gmail.com>2019-07-30 18:45:42 +0100
committerCristian Cadar <c.cadar@imperial.ac.uk>2019-10-29 15:38:02 -0400
commit4eb050e2999bef42f70dcc72a8ee283f8803ce67 (patch)
tree10b6bc4ade4040661142ae57f57639b402194152 /lib/Support/Timer.cpp
parentf2c9085cab7efd4468ffe44190547445fe5b15fb (diff)
downloadklee-4eb050e2999bef42f70dcc72a8ee283f8803ce67.tar.gz
ExecutorTimers: refactor and move to support lib
- moves timer handling from Executor into support lib
- introduces TimerGroup, removes TimerInfo/WriteStatsTimer/UpdateReachableTimer/WriteIStatsTimer classes
- removes ExecutorTimers.cpp and ExecutorTimerInfo.h
- removes -max-instruction-time flag (see #1114)
Diffstat (limited to 'lib/Support/Timer.cpp')
-rw-r--r--lib/Support/Timer.cpp69
1 files changed, 64 insertions, 5 deletions
diff --git a/lib/Support/Timer.cpp b/lib/Support/Timer.cpp
index 4e52feb5..8a0b4ecc 100644
--- a/lib/Support/Timer.cpp
+++ b/lib/Support/Timer.cpp
@@ -7,16 +7,75 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "klee/Config/Version.h"
+#include "klee/Internal/Support/ErrorHandling.h"
 #include "klee/Internal/Support/Timer.h"
 #include "klee/Internal/System/Time.h"
 
+
 using namespace klee;
 
-WallTimer::WallTimer() {
-  start = time::getWallTime();
+
+// WallTimer
+
+WallTimer::WallTimer() : start{time::getWallTime()} {}
+
+time::Span WallTimer::delta() const {
+  return {time::getWallTime() - start};
+}
+
+
+// Timer
+
+Timer::Timer(const time::Span &interval, std::function<void()> &&callback) :
+  interval{interval}, nextInvocationTime{time::getWallTime() + interval}, run{std::move(callback)} {};
+
+time::Span Timer::getInterval() const {
+  return interval;
+};
+
+void Timer::invoke(const time::Point &currentTime) {
+  if (currentTime < nextInvocationTime) return;
+
+  run();
+  nextInvocationTime = currentTime + interval;
+};
+
+void Timer::reset(const time::Point &currentTime) {
+  nextInvocationTime = currentTime + interval;
+};
+
+
+// TimerGroup
+
+TimerGroup::TimerGroup(const time::Span &minInterval) :
+  invocationTimer{
+    minInterval,
+    [&]{
+      // invoke timers
+      for (auto &timer : timers)
+        timer->invoke(currentTime);
+    }
+  } {};
+
+void TimerGroup::add(std::unique_ptr<klee::Timer> timer) {
+  const auto &interval = timer->getInterval();
+  const auto &minInterval = invocationTimer.getInterval();
+  if (interval < minInterval)
+    klee_warning("Timer interval below minimum timer interval (-timer-interval)");
+  if (interval.toMicroseconds() % minInterval.toMicroseconds())
+    klee_warning("Timer interval not a multiple of timer interval (-timer-interval)");
+
+  timers.emplace_back(std::move(timer));
+}
+
+void TimerGroup::invoke() {
+  currentTime = time::getWallTime();
+  invocationTimer.invoke(currentTime);
 }
 
-time::Span WallTimer::check() {
-  return time::Span(time::getWallTime() - start);
+void TimerGroup::reset() {
+  currentTime = time::getWallTime();
+  invocationTimer.reset(currentTime);
+  for (auto &timer : timers)
+    timer->reset(currentTime);
 }