1 #ifndef MHO_Snapshot_HH__
2 #define MHO_Snapshot_HH__
25 #ifndef HOPS_SNAPSHOT_DIR
26 #define HOPS_SNAPSHOT_DIR_STR "./"
28 #define HOPS_SNAPSHOT_DIR_STR STRING(HOPS_SNAPSHOT_DIR)
65 if(fInstance ==
nullptr)
101 void AddKey(
const std::string& key);
107 void AddKey(
const char* key);
133 template<
typename XObjType >
void DumpObject(XObjType* obj,
const char* key,
const char* name)
135 DumpObject(obj, std::string(key), std::string(name));
146 template<
typename XObjType >
void DumpObject(XObjType* obj, std::string key, std::string name)
148 if(PassSnapshot(key))
150 std::string output_file = fPrefix + fExeName + fPostfix;
154 std::cout <<
"dump to file: " << output_file << std::endl;
158 uint32_t label = fCountLabel;
159 inter.
Write(*obj, name, label);
164 msg_error(
"file",
"error writing object " << name <<
" to file: " << output_file << eom);
180 template<
typename XObjType >
181 void DumpObject(XObjType* obj, std::string key, std::string name, std::string file,
int line)
183 if(PassSnapshot(key))
185 std::string output_file = fPrefix + fExeName + fPostfix;
189 msg_debug(
"snapshot",
"dumping object (" << name <<
") snapshot to file: " << output_file << eom);
193 obj->Insert(std::string(
"name"), name);
194 obj->Insert(std::string(
"snapshot_key"), key);
195 obj->Insert(std::string(
"executable"), fExeName);
196 obj->Insert(std::string(
"file"), file);
197 obj->Insert(std::string(
"line"), line);
198 obj->Insert(std::string(
"count_label"), (
int)fCountLabel);
199 uint32_t label = fCountLabel;
200 inter.
Write(*obj, name, label);
205 msg_error(
"file",
"error writing object " << name <<
" to file: " << output_file << eom);
219 pid_t pid = getpid();
227 MHO_Snapshot(): fCurrentKeyIsAllowed(false), fAcceptAllKeys(false)
232 std::stringstream ss;
236 fPrefix = dir_string +
"/";
237 fPostfix = ss.str() +
".snap";
243 bool PassSnapshot(std::string key);
250 std::string fPostfix;
251 std::string fExeName;
254 uint32_t fCountLabel;
256 std::set< std::string > fKeys;
257 bool fCurrentKeyIsAllowed;
262 #ifdef HOPS_ENABLE_SNAPSHOTS
264 #define take_snapshot(xKEY, xNAME, xOBJECT) MHO_Snapshot::GetInstance().DumpObject(xOBJECT, xKEY, xNAME);
265 #define take_snapshot_here(xKEY, xNAME, xFILE, xLINE, xOBJECT) \
266 MHO_Snapshot::GetInstance().DumpObject(xOBJECT, xKEY, xNAME, xFILE, xLINE);
270 #define take_snapshot(xKEY, xNAME, xOBJECT)
271 #define take_snapshot_here(xKEY, xNAME, xFILE, xLINE, xOBJECT)
#define msg_debug(xKEY, xCONTENT)
Definition: MHO_Message.hh:297
#define msg_error(xKEY, xCONTENT)
Definition: MHO_Message.hh:244
#define HOPS_SNAPSHOT_DIR_STR
Definition: MHO_Snapshot.hh:26
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:346
Class MHO_Snapshot.
Definition: MHO_Snapshot.hh:48
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:146
static MHO_Snapshot & GetInstance()
provides public access to the only static instance
Definition: MHO_Snapshot.hh:63
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:133
void RemoveAllKeys()
Clears all keys in the MHO_Snapshot object.
Definition: MHO_Snapshot.cc:38
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:9
MHO_Snapshot & operator=(MHO_Snapshot &&)=delete
void AcceptAllKeys()
Sets the internal flag to accept all keys.
Definition: MHO_Snapshot.hh:89
void SetExecutableName(const char *exe_name)
Setter for executable name.
Definition: MHO_Snapshot.hh:84
void SetExecutableName(std::string exe_name)
Setter for executable name.
Definition: MHO_Snapshot.hh:77
MHO_Snapshot & operator=(MHO_Snapshot const &)=delete
void LimitToKeySet()
Sets internal flag to limit keys based on key set.
Definition: MHO_Snapshot.hh:94
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:181
void RemoveKey(const std::string &key)
Removes a key-value pair from the MHO_Snapshot object's keys.
Definition: MHO_Snapshot.cc:19
struct type_status status
Definition: fourfit3.c:53
Definition: MHO_ChannelLabeler.hh:17