12#include "sparta/functional/ArchData.hpp"
15#include "sparta/serialization/checkpoint/FastCheckpointer.hpp"
17namespace sparta::serialization::checkpoint
44 void dump(std::ostream& o)
const {
45 o <<
"<dump not supported on checkpoint file storage adapter>";
48 uint32_t getSize()
const {
50 return sizeof(
decltype(*this));
60 void writeLineBytes(
const char* data,
size_t size) {
61 fs_.write(data, size);
68 "Ostream error while writing checkpoint data");
89 void dump(std::ostream& o)
const {
90 o <<
"<dump not supported on checkpoint file storage adapter>";
93 uint32_t getSize()
const {
95 return sizeof(
decltype(*this));
98 void prepareForLoad() {
110 "Encountered checkpoint data stream error or eof");
113 fs_.read((
char*)&ln_idx,
sizeof(ln_idx));
115 }
else if(ctrl ==
'E'){
119 << ctrl <<
"' control character was found where an 'L' or 'E' was found";
123 void copyLineBytes(
char* buf, uint32_t size) {
173 return checkpoint_id;
184 std::ofstream outf(filename, std::ofstream::out | std::ofstream::binary | std::ofstream::trunc);
187 return checkpoint_id;
198 const bool force_snapshot =
true;
200 std::ostringstream chkpt_filename;
201 chkpt_filename << prefix_ <<
"."
204 std::ofstream outf(chkpt_filename.str(), std::ofstream::binary | std::ofstream::trunc);
207 return checkpoint_id;
217 for (
auto aditr=adatas.begin(); aditr!= adatas.end(); aditr++) {
218 (*aditr)->restoreAll(fsa);
227 std::ifstream in(filename);
238 void save_(std::ostream& outf) {
240 outf.exceptions(std::ostream::eofbit | std::ostream::badbit |
241 std::ostream::failbit | std::ostream::goodbit);
242 FileWriteAdapter fsa(outf);
244 for (
auto aditr=adatas.begin(); aditr!= adatas.end(); aditr++) {
245 (*aditr)->saveAll(fsa);
Set of macros for Sparta assertions. Caught by the framework.
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
Exception class for all of Sparta.
Basic Node framework in sparta device tree composite pattern.
static const line_idx_type INVALID_LINE_IDX
Invalid line index.
offset_type line_idx_type
Represents offsets into this ArchData.
A class that lets you schedule events now and in the future.
Used to construct and throw a standard C++ exception. Inherits from std::exception.
Node in a composite tree representing a sparta Tree item.
const std::vector< ArchData * > & getArchDatas() const
Returns ArchDatas enumerated by this Checkpointer for iteration when saving or loading checkpoint dat...
chkpt_id_t createCheckpoint(bool force_snapshot=false)
Creates a checkpoint at the given scheduler's current tick with a new checkpoint ID some point after ...
Checkpoint::chkpt_id_t chkpt_id_t
tick_t Tick type to which checkpoints will refer
Implements quick checkpointing through delta-checkpoint trees which store state-deltas in a compact f...
file storage adpater for ArchData
file storage adpater for ArchData
Implements a Persistent FastCheckpointer, i.e. implements an interface to save checkpoints to disk.
FastCheckpointer::chkpt_id_t save()
void restore(const std::string &filename)
PersistentFastCheckpointer(TreeNode &root, sparta::Scheduler *sched=nullptr)
PersistentFastCheckpointer Constructor.
void restore(std::istream &in)
virtual ~PersistentFastCheckpointer()
Destructor.
FastCheckpointer::chkpt_id_t save(std::ostream &outf)
FastCheckpointer::chkpt_id_t save(std::string filename)