53#include "debug/Checkpoint.hh"
89 std::ofstream &outstream)
92 if (mkdir(dir.c_str(), 0775) == -1 && errno != EEXIST)
93 fatal(
"couldn't mkdir %s\n", dir);
96 outstream = std::ofstream(cpt_file.c_str());
97 time_t
t = time(NULL);
99 fatal(
"Unable to open file %s for writing\n", cpt_file.c_str());
100 outstream <<
"## checkpoint generated: " << ctime(&
t);
105 assert(!
path.empty());
118 DPRINTF(Checkpoint,
"ScopedCheckpointSection::pushName: %s\n", obj_name);
124 DPRINTF(Checkpoint,
"ScopedCheckpointSection::nameOut: %s\n",
132 assert(!
path.empty());
146 currentDirectory = (
name.find(
"%") != std::string::npos) ?
148 auto isEmptyPath = currentDirectory.empty();
149 auto endsWithSlash = !isEmptyPath && currentDirectory.back() ==
'/';
150 if (!endsWithSlash) {
151 currentDirectory +=
"/";
153 return currentDirectory;
159 return currentDirectory;
163 : db(), _cptDir(setDir(cpt_dir))
167 fatal(
"Can't load checkpoint file '%s'\n", filename);
199 return db.
find(section, entry, value);
static std::string currentDirectory
CheckpointIn(const std::string &cpt_dir)
static const char * baseFilename
bool find(const std::string §ion, const std::string &entry, std::string &value) const
Find value corresponding to given section and entry names.
void visitSection(const std::string §ionName, VisitSectionCallback cb)
Iterate over key/value pairs of the given section.
std::function< void( const std::string &, const std::string &)> VisitSectionCallback
Visitor callback that receives key/value pairs.
bool entryExists(const std::string §ion, const std::string &entry) const
Determine whether the entry exists within named section exists in the .ini file.
bool load(std::istream &f)
Load parameter settings from given istream.
bool sectionExists(const std::string §ion) const
Determine whether the named section exists in the .ini file.
void pushName(const char *name)
~ScopedCheckpointSection()
void nameOut(CheckpointOut &cp)
static std::stack< std::string > path
#define fatal(...)
This implements a cprintf based fatal() function.
bool entryExists(const std::string §ion, const std::string &entry)
virtual void unserialize(CheckpointIn &cp)=0
Unserialize an object.
bool find(const std::string §ion, const std::string &entry, std::string &value)
static std::string setDir(const std::string &base_name)
Set the current directory.
void serializeSection(CheckpointOut &cp, const char *name) const
Serialize an object into a new section.
static const std::string & currentSection()
Gets the fully-qualified name of the active section.
virtual void serialize(CheckpointOut &cp) const =0
Serialize an object.
const std::string getCptDir()
static std::string dir()
Get the current checkout directory name.
bool sectionExists(const std::string §ion)
void visitSection(const std::string §ion, IniFile::VisitSectionCallback cb)
static void generateCheckpointOut(const std::string &cpt_dir, std::ofstream &outstream)
Generate a checkpoint file so that the serialization can be routed to it.
void unserializeSection(CheckpointIn &cp, const char *name)
Unserialize an a child object.
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Tick curTick()
The universal simulation clock.
std::ostream CheckpointOut
std::string csprintf(const char *format, const Args &...args)
const std::string & name()