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