klee
Timer.h
Go to the documentation of this file.
1//===-- Timer.h -------------------------------------------------*- C++ -*-===//
2//
3// The KLEE Symbolic Virtual Machine
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef KLEE_TIMER_H
11#define KLEE_TIMER_H
12
13#include "klee/System/Time.h"
14
15#include "llvm/ADT/SmallVector.h"
16
17#include <functional>
18#include <memory>
19
20namespace klee {
21
25 class WallTimer {
27 public:
28 WallTimer();
29
31 time::Span delta() const;
32 };
33
34
43 class Timer {
49 std::function<void()> run;
50 public:
53 Timer(const time::Span &interval, std::function<void()> &&callback);
54
56 time::Span getInterval() const;
58 void invoke(const time::Point &currentTime);
60 void reset(const time::Point &currentTime);
61 };
62
63
74 class TimerGroup {
76 llvm::SmallVector<std::unique_ptr<Timer>, 4> timers;
81 public:
83 explicit TimerGroup(const time::Span &minInterval);
84
88 void add(std::unique_ptr<Timer> timer);
90 void invoke();
92 void reset();
93 };
94
95} // klee
96#endif /* KLEE_TIMER_H */
TimerGroup(const time::Span &minInterval)
Definition: Timer.cpp:50
void reset()
Reset all timers.
Definition: Timer.cpp:76
void add(std::unique_ptr< Timer > timer)
Definition: Timer.cpp:60
time::Point currentTime
Time of last invoke call.
Definition: Timer.h:80
void invoke()
Invoke registered timers with current time only if minimum interval exceeded.
Definition: Timer.cpp:71
Timer invocationTimer
Timer that invokes all registered timers after minimum interval.
Definition: Timer.h:78
llvm::SmallVector< std::unique_ptr< Timer >, 4 > timers
Registered timers.
Definition: Timer.h:76
time::Span interval
Approximate interval between callback invocations.
Definition: Timer.h:45
time::Point nextInvocationTime
Wall time for next invocation.
Definition: Timer.h:47
Timer(const time::Span &interval, std::function< void()> &&callback)
Definition: Timer.cpp:29
std::function< void()> run
The event callback.
Definition: Timer.h:49
void invoke(const time::Point &currentTime)
Execute callback if invocation time exceeded.
Definition: Timer.cpp:36
time::Span getInterval() const
Return specified interval between invocations.
Definition: Timer.cpp:32
void reset(const time::Point &currentTime)
Set new invocation time to currentTime + interval.
Definition: Timer.cpp:43
const time::Point start
Definition: Timer.h:26
time::Span delta() const
Return the delta since the timer was created.
Definition: Timer.cpp:22
Definition: main.cpp:291