1 #ifndef MHO_Snapshot_HH__
2 #define MHO_Snapshot_HH__
61 "could not determine HOPS install prefix; writing snapshot files to the current directory" << eom);
62 return std::string(
".");
64 return prefix +
"/snapshot";
103 void AddKey(
const std::string& key);
124 template<
typename XObjType >
void DumpObject(XObjType* obj,
const char* key,
const char* name)
126 DumpObject(obj, std::string(key), std::string(name));
137 template<
typename XObjType >
void DumpObject(XObjType* obj, std::string key, std::string name)
139 if(PassSnapshot(key))
141 std::string output_file = fPrefix + fExeName + fPostfix;
145 std::cout <<
"dump to file: " << output_file << std::endl;
149 inter.
Write(*obj, name);
154 msg_error(
"file",
"error writing object " << name <<
" to file: " << output_file << eom);
170 template<
typename XObjType >
171 void DumpObject(XObjType* obj, std::string key, std::string name, std::string file,
int line)
173 if(PassSnapshot(key))
175 std::string output_file = fPrefix + fExeName + fPostfix;
179 msg_debug(
"snapshot",
"dumping object (" << name <<
") snapshot to file: " << output_file << eom);
183 obj->Insert(std::string(
"name"), name);
184 obj->Insert(std::string(
"snapshot_key"), key);
185 obj->Insert(std::string(
"executable"), fExeName);
186 obj->Insert(std::string(
"file"), file);
187 obj->Insert(std::string(
"line"), line);
188 obj->Insert(std::string(
"count_label"), (
int)fCountLabel);
189 inter.
Write(*obj, name);
194 msg_error(
"file",
"error writing object " << name <<
" to file: " << output_file << eom);
208 pid_t pid = getpid();
214 MHO_Snapshot(): fCurrentKeyIsAllowed(false), fAcceptAllKeys(false)
219 std::stringstream ss;
223 fPrefix = dir_string +
"/";
224 fPostfix = ss.str() +
".snap";
230 bool PassSnapshot(std::string key);
235 std::string fPostfix;
236 std::string fExeName;
239 uint32_t fCountLabel;
241 std::set< std::string > fKeys;
242 bool fCurrentKeyIsAllowed;
247 #ifdef HOPS_ENABLE_SNAPSHOTS
249 #define take_snapshot(xKEY, xNAME, xOBJECT) MHO_Snapshot::GetInstance().DumpObject(xOBJECT, xKEY, xNAME);
250 #define take_snapshot_here(xKEY, xNAME, xFILE, xLINE, xOBJECT) \
251 MHO_Snapshot::GetInstance().DumpObject(xOBJECT, xKEY, xNAME, xFILE, xLINE);
255 #define take_snapshot(xKEY, xNAME, xOBJECT)
256 #define take_snapshot_here(xKEY, xNAME, xFILE, xLINE, xOBJECT)
#define msg_debug(xKEY, xCONTENT)
Definition: MHO_Message.hh:291
#define msg_warn(xKEY, xCONTENT)
Definition: MHO_Message.hh:248
#define msg_error(xKEY, xCONTENT)
Definition: MHO_Message.hh:238
Class MHO_BinaryFileInterface.
Definition: MHO_BinaryFileInterface.hh:27
bool OpenToAppend(const std::string &obj_filename, const std::string &index_filename="")
Opens a file for appending objects and optionally streams keys to an index file.
Definition: MHO_BinaryFileInterface.hh:87
void Close()
Closes file and key/index streamers if open.
Definition: MHO_BinaryFileInterface.hh:319
bool Write(const XWriteType &obj, const std::string &shortname="")
Writes an object (must inherit from MHO_Serializable) to a file (with optional shortname string)....
Definition: MHO_BinaryFileInterface.hh:347
static std::string GetHopsInstallPrefix()
Returns the absolute path of the HOPS install prefix, determined at runtime from the on-disk location...
Definition: MHO_DirectoryInterface.cc:73
Class MHO_Snapshot.
Definition: MHO_Snapshot.hh:41
void DumpObject(XObjType *obj, std::string key, std::string name)
Dumps an object of type XObjType to a file specified by key and name.
Definition: MHO_Snapshot.hh:137
static MHO_Snapshot & GetInstance()
provides public access to the only static instance
Definition: MHO_Snapshot.hh:73
void DumpObject(XObjType *obj, const char *key, const char *name)
Dumps an object of type XObjType to a file specified by key and name.
Definition: MHO_Snapshot.hh:124
void RemoveAllKeys()
Clears all keys in the MHO_Snapshot object.
Definition: MHO_Snapshot.cc:20
MHO_Snapshot(MHO_Snapshot const &)=delete
void AddKey(const std::string &key)
Inserts a key into the set of keys for MHO_Snapshot.
Definition: MHO_Snapshot.cc:6
MHO_Snapshot & operator=(MHO_Snapshot &&)=delete
static std::string GetSnapshotDirectory()
Definition: MHO_Snapshot.hh:55
void AcceptAllKeys()
Sets the internal flag to accept all keys.
Definition: MHO_Snapshot.hh:90
void SetExecutableName(std::string exe_name)
Setter for executable name.
Definition: MHO_Snapshot.hh:85
MHO_Snapshot & operator=(MHO_Snapshot const &)=delete
void LimitToKeySet()
Sets internal flag to limit keys based on key set.
Definition: MHO_Snapshot.hh:95
MHO_Snapshot(MHO_Snapshot &&)=delete
void DumpObject(XObjType *obj, std::string key, std::string name, std::string file, int line)
Dumps an object to a file with given key, name, file and line number.
Definition: MHO_Snapshot.hh:171
void RemoveKey(const std::string &key)
Removes a key from the MHO_Snapshot object if it exists.
Definition: MHO_Snapshot.cc:11
struct type_status status
Definition: fourfit3.c:53
Definition: MHO_AdhocFlagging.hh:18