27#include "sparta/utils/TimeManager.hpp"
33#include "simdb/schema/DatabaseTypedefs.hpp"
34namespace simdb {
class ObjectManager; }
45 std::vector<std::string> lines_;
46 std::stringstream stream_;
50 typedef std::ostream& (*manip_t)(std::ostream&);
71 if(f ==
static_cast<manip_t>(std::endl)){
84 lines_.push_back(stream_.str());
94 std::vector<std::string> result = lines_;
95 result.push_back(stream_.str());
110 std::string sim_name_;
111 std::string command_line_;
112 std::string working_dir_;
113 std::string executable_;
114 std::string simulator_version_;
115 std::string reproduction_info_;
116 std::string start_time_;
117 std::string sparta_version_;
118 std::vector<std::string> other_;
132 static std::stack<SimulationInfo*> sim_inst_stack_;
186 const std::vector<std::string>&
other;
192 if (sim_inst_stack_.empty()) {
195 return *sim_inst_stack_.top();
202 if (!sim_inst_stack_.empty()) {
203 sim_inst_stack_.pop();
211 start_time_(
TimeManager::getTimeManager().getLocalTime()),
228 sim_name_ = rhp.sim_name_;
229 command_line_ = rhp.command_line_;
230 working_dir_ = rhp.working_dir_;
231 executable_ = rhp.executable_;
232 simulator_version_ = rhp.simulator_version_;
233 reproduction_info_ = rhp.reproduction_info_;
246 sim_name_ = rhp.sim_name_;
247 command_line_ = rhp.command_line_;
248 working_dir_ = rhp.working_dir_;
249 executable_ = rhp.executable_;
250 simulator_version_ = rhp.simulator_version_;
251 reproduction_info_ = rhp.reproduction_info_;
252 start_time_ = rhp.start_time_;
262 const std::string& _command_line,
263 const std::string& _working_dir,
264 const std::string& _executable,
265 const std::string& _simulator_version,
266 const std::string& _reproduction_info,
267 const std::vector<std::string> & _other) :
270 sim_name_ = _sim_name;
271 command_line_ = _command_line;
272 working_dir_ = _working_dir;
273 executable_ = _executable;
274 simulator_version_ = _simulator_version;
275 reproduction_info_ = _reproduction_info;
288 const std::string& _simulator_version,
289 const std::string& _reproduction_info,
290 const std::vector<std::string> & _other) :
293 sim_name_ = _sim_name;
295 simulator_version_ = _simulator_version;
296 reproduction_info_ = _reproduction_info;
299 const uint32_t PATH_SIZE = 2048;
301 if (getcwd(tmp, PATH_SIZE) !=
nullptr) {
304 std::stringstream ss;
305 ss <<
"<error " << errno <<
" determining working directory>";
306 working_dir_ = ss.str();
322 const simdb::DatabaseID obj_mgr_db_id,
323 const simdb::DatabaseID report_node_id = 0);
333 std::map<std::string, std::string> * json_kvpairs =
nullptr);
343 if (sparta_version_.empty()) {
346 return sparta_version_;
355 executable_ = argv[0];
357 std::stringstream cmdln;
358 for(
int i = 0; i < argc; ++i){
362 size_t arglen = strlen(argv[i]);
364 || memchr(argv[i],
' ', arglen) !=
nullptr
365 || memchr(argv[i],
'\t', arglen) !=
nullptr
366 || memchr(argv[i],
'\n', arglen) !=
nullptr){
367 cmdln <<
'"' << argv[i] <<
'"';
372 command_line_ = cmdln.str();
379 command_line_ = cmdline;
386 other_.push_back(_other);
397 template <
typename StreamType=std::ostream>
399 const std::string& line_start=
"# ",
400 const std::string& line_end=
"\n",
401 bool show_field_names=
true)
const {
406 if(show_field_names){
407 o << std::left << std::setw(10) << (p.first +
":");
409 o << p.second << line_end;
412 if(
other.size() > 0){
413 o << line_start <<
"Other:" << line_end;
414 for(
const std::string& oi :
other){
415 o << line_start <<
" " << oi << line_end;
424 template <
typename ...Args>
426 std::stringstream ss;
437 template <
typename ...Args>
448 std::vector<std::pair<std::string, std::string>> result;
449 result.emplace_back(
"Name",
sim_name);
458 if (db_elapsed_time_.
isValid()) {
459 result.emplace_back(
"Elapsed", db_elapsed_time_.
getValue());
466 std::stringstream timestr;
468 result.emplace_back(
"Elapsed", timestr.str());
471 last_captured_elapsed_time_ = result.back().second;
481 return last_captured_elapsed_time_;
Set of macros for Sparta assertions. Caught by the framework.
Exception class for all of Sparta.
File that defines a ValidValue.
Helper class for building a set of lines through an ostream-like interface.
LineStringStream & operator<<(const T &t)
Insertion operator on this LogObject.
void addNewLine()
Add a new line to the list. This is also called when std::endl is inserted into this stream.
std::vector< std::string > getLines() const
Gets the lines including whathever line is currently being built.
LineStringStream & operator<<(manip_t f)
Handler for stream modifiers (e.g. endl)
std::ostream &(* manip_t)(std::ostream &)
Default Constructor.
Contains information describing the simulation instance for the purpose of identifying the simulation...
std::vector< std::string > stringizeToLines(const Args &...args) const
Generate a vector of lines.
void addOtherInfo(const std::string &_other)
Add other information to the simulation.
const std::string & command_line
Simulator application instance command-line.
SimulationInfo(const std::string &_sim_name, const std::string &_command_line, const std::string &_working_dir, const std::string &_executable, const std::string &_simulator_version, const std::string &_reproduction_info, const std::vector< std::string > &_other)
SimulationInfo constructor.
void setCommandLine(int argc, char **argv)
Assign command_line_ and executable_ from args.
const std::string & start_time
Time at which the simulation started (roughly)
const utils::ValidValue< std::string > & getLastCapturedElapsedTime() const
Return the very last 'Elapsed' time that this object got from the TimeManager. This is reset with eac...
SimulationInfo(const std::string &_sim_name, int argc, char **argv, const std::string &_simulator_version, const std::string &_reproduction_info, const std::vector< std::string > &_other)
SimulationInfo constructor with automatic command-line reconstruction.
const std::vector< std::string > & other
other simulator information
SimulationInfo & operator=(const SimulationInfo &rhp)
Assignable.
SimulationInfo(const SimulationInfo &rhp)
Copy-constructor.
const std::string & executable
Executable being run.
const std::string & working_dir
Simulator application instance working dir.
SimulationInfo(SimulationInfo &&)=delete
Not move-constructable.
std::vector< std::pair< std::string, std::string > > getHeaderPairs() const
Gets (name, value) pairs for each header entry.
void write(StreamType &o, const std::string &line_start="# ", const std::string &line_end="\n", bool show_field_names=true) const
Write this information to an ostream.
const std::string & reproduction_info
versions/buildnums/tags of simulator and dependencies necessary for reproducing the build from a vers...
std::string stringize(const Args &...args) const
Generate a string using the write function without needing to construct a temporary stringstream.
SimulationInfo(std::ifstream &json_fin, std::map< std::string, std::string > *json_kvpairs=nullptr)
Instantiate a SimulationInfo object from a json, json_reduced, json_detail, or js_json report file.
static SimulationInfo & getInstance()
Gets the SimulationInfo singleton instance.
const std::string & sim_name
Simulator application name. Note that multiple simulators could exist in the same process space,...
~SimulationInfo()
Destruction.
std::string getSpartaVersion() const
Get the SPARTA version string for this SimulationInfo object. Most of the time, this will be Simulati...
static const char sparta_version[]
The version of SPARTA.
void setCommandLine(const std::string &cmdline)
Assign command line from string.
SimulationInfo(const simdb::ObjectManager &sim_db, const simdb::DatabaseID obj_mgr_db_id, const simdb::DatabaseID report_node_id=0)
Recreate a SimulationInfo object from the provided SimInfo record with the given ObjMgrID.
SimulationInfo()
Default Constructor.
const std::string & simulator_version
Simulator Version of the simulator itself.
Singleton which manages wall-clock time for simulations in SPARTA This is not a "timer" manager,...
double getSecondsElapsed() const
Gets the number of seconds elapsed since the instantiation of SPARTA static and global vars.
static TimeManager & getTimeManager()
Returns the TimeManager singleton.
Provides a wrapper around a value to ensure that the value is assigned.
const value_type & getValue() const
Get the value - const version.
bool isValid() const
Is this value valid.
Macros for handling exponential backoff.
std::ostream & operator<<(std::ostream &o, const SimulationInfo &info)
ostream insertion operator for SimulationInfo