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 , interval_{interval}
31 , out_{out}
33 , startSimTime_{sched.now()}
34 {
35 }
36
37 void
39 {
40 scheduler_.in(interval_, [this]() { beat(scheduler_.now()); });
41 }
42
43 void
45 {
46 using namespace std::chrono;
47 RealTime realTime = RealClock::now();
48 SimTime simTime = when;
49
50 RealDuration realDuration = realTime - startRealTime_;
51 SimDuration simDuration = simTime - startSimTime_;
52 out_ << "Heartbeat. Time Elapsed: {sim: " << duration_cast<seconds>(simDuration).count()
53 << "s | real: " << duration_cast<seconds>(realDuration).count() << "s}\n"
54 << std::flush;
55
56 scheduler_.in(interval_, [this]() { beat(scheduler_.now()); });
57 }
58};
59
60} // namespace csf
61} // namespace test
62} // 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:44
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