ravel
Deterministic simulation testing for C++. Seed a bug, replay it exact.
Loading...
Searching...
No Matches
trace.hpp
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5#include <vector>
6
7#include "ravel/clock.hpp"
8
9namespace ravel {
10
11enum class TraceEventKind : std::uint8_t {
12 TaskSpawned,
13 TaskResumed,
14 TaskFinished,
15 TaskThrew,
16 MessageSent,
17 MessageDropped,
18 MessageDelivered,
19 DiskWritten,
20 DiskSynced,
21 DiskFailed,
22 DiskCrashed,
23};
24
25const char* to_string(TraceEventKind kind) noexcept;
26
28enum class TraceSubject : std::uint8_t { Task, Channel, Disk };
29TraceSubject subject_of(TraceEventKind kind) noexcept;
30
33struct TraceEvent {
36 std::size_t subject;
38 TraceEventKind kind;
39
41 bool operator==(const TraceEvent&) const = default;
42};
43
48class Trace {
49 public:
51 void record(const TraceEvent& event);
52
54 const std::vector<TraceEvent>& events() const noexcept { return events_; }
56 std::uint64_t digest() const noexcept { return digest_; }
57
58 private:
59 std::vector<TraceEvent> events_;
60 std::uint64_t digest_ = 0xCBF29CE484222325ULL;
61};
62
63} // namespace ravel
Ordered record of everything that happened during a run (scheduling decisions and message fates),...
Definition trace.hpp:48
std::uint64_t digest() const noexcept
A fingerprint of the events so far; equal digests mean identical runs.
Definition trace.hpp:56
const std::vector< TraceEvent > & events() const noexcept
Every event so far, in order.
Definition trace.hpp:54
void record(const TraceEvent &event)
Appends an event and folds it into the digest.
std::uint64_t Tick
Virtual time, in ticks. A tick has no fixed real-world length.
Definition clock.hpp:15
One fact about the run.
Definition trace.hpp:33
TraceEventKind kind
What happened.
Definition trace.hpp:38
VirtualClock::Tick time
When it happened, in virtual ticks.
Definition trace.hpp:35
std::size_t subject
A task, channel or disk id; see subject_of().
Definition trace.hpp:36
bool operator==(const TraceEvent &) const =default
Events are equal when all their fields are.