rippled
Loading...
Searching...
No Matches
timers.h
1#ifndef XRPL_TEST_CSF_TIMERS_H_INCLUDED
2#define XRPL_TEST_CSF_TIMERS_H_INCLUDED
3
4#include <test/csf/Scheduler.h>
5#include <test/csf/SimTime.h>
6
7#include <chrono>
8#include <ostream>
9
10namespace ripple {
11namespace test {
12namespace csf {
13
14// Timers are classes that schedule repeated events and are mostly independent
15// of simulation-specific details.
16
20{
24
27
28public:
30 Scheduler& sched,
31 SimDuration interval = std::chrono::seconds{60},
33 : scheduler_{sched}
34 , interval_{interval}
35 , out_{out}
37 , startSimTime_{sched.now()}
38 {
39 }
40
41 void
43 {
44 scheduler_.in(interval_, [this]() { beat(scheduler_.now()); });
45 }
46
47 void
49 {
50 using namespace std::chrono;
51 RealTime realTime = RealClock::now();
52 SimTime simTime = when;
53
54 RealDuration realDuration = realTime - startRealTime_;
55 SimDuration simDuration = simTime - startSimTime_;
56 out_ << "Heartbeat. Time Elapsed: {sim: "
57 << duration_cast<seconds>(simDuration).count()
58 << "s | real: " << duration_cast<seconds>(realDuration).count()
59 << "s}\n"
60 << std::flush;
61
62 scheduler_.in(interval_, [this]() { beat(scheduler_.now()); });
63 }
64};
65
66} // namespace csf
67} // namespace test
68} // namespace ripple
69
70#endif
Gives heartbeat of simulation to signal simulation progression.
Definition timers.h:20
HeartbeatTimer(Scheduler &sched, SimDuration interval=std::chrono::seconds{60}, std::ostream &out=std::cerr)
Definition timers.h:29
void beat(SimTime when)
Definition timers.h:48
Simulated discrete-event scheduler.
time_point now() const
Return the current network time.
cancel_token in(duration const &delay, Function &&f)
Schedule an event after a specified duration passes.
T flush(T... args)
typename SimClock::duration SimDuration
Definition SimTime.h:17
RealClock::time_point RealTime
Definition SimTime.h:14
typename SimClock::time_point SimTime
Definition SimTime.h:18
RealClock::duration RealDuration
Definition SimTime.h:13
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6