27#include "sparta/utils/TimeManager.hpp"
42 std::vector<std::string> lines_;
43 std::stringstream stream_;
47 typedef std::ostream& (*manip_t)(std::ostream&);
68 if(f ==
static_cast<manip_t>(std::endl)){
81 lines_.push_back(stream_.str());
91 std::vector<std::string> result = lines_;
92 result.push_back(stream_.str());
107 std::string sim_name_;
108 std::string command_line_;
109 std::string working_dir_;
110 std::string executable_;
111 std::string simulator_version_;
112 std::string reproduction_info_;
113 std::string start_time_;
114 std::string sparta_version_;
115 std::vector<std::string> other_;
169 const std::vector<std::string>&
other;
187 start_time_(
TimeManager::getTimeManager().getLocalTime()),
204 sim_name_ = rhp.sim_name_;
205 command_line_ = rhp.command_line_;
206 working_dir_ = rhp.working_dir_;
207 executable_ = rhp.executable_;
208 simulator_version_ = rhp.simulator_version_;
209 reproduction_info_ = rhp.reproduction_info_;
222 sim_name_ = rhp.sim_name_;
223 command_line_ = rhp.command_line_;
224 working_dir_ = rhp.working_dir_;
225 executable_ = rhp.executable_;
226 simulator_version_ = rhp.simulator_version_;
227 reproduction_info_ = rhp.reproduction_info_;
228 start_time_ = rhp.start_time_;
238 const std::string& _command_line,
239 const std::string& _working_dir,
240 const std::string& _executable,
241 const std::string& _simulator_version,
242 const std::string& _reproduction_info,
243 const std::vector<std::string> & _other) :
246 sim_name_ = _sim_name;
247 command_line_ = _command_line;
248 working_dir_ = _working_dir;
249 executable_ = _executable;
250 simulator_version_ = _simulator_version;
251 reproduction_info_ = _reproduction_info;
264 const std::string& _simulator_version,
265 const std::string& _reproduction_info,
266 const std::vector<std::string> & _other) :
269 sim_name_ = _sim_name;
271 simulator_version_ = _simulator_version;
272 reproduction_info_ = _reproduction_info;
275 const uint32_t PATH_SIZE = 2048;
277 if (getcwd(tmp, PATH_SIZE) !=
nullptr) {
280 std::stringstream ss;
281 ss <<
"<error " << errno <<
" determining working directory>";
282 working_dir_ = ss.str();
295 std::map<std::string, std::string> * json_kvpairs =
nullptr);
303 if (sparta_version_.empty()) {
306 return sparta_version_;
315 executable_ = argv[0];
317 std::stringstream cmdln;
318 for(
int i = 0; i < argc; ++i){
322 size_t arglen = strlen(argv[i]);
324 || memchr(argv[i],
' ', arglen) !=
nullptr
325 || memchr(argv[i],
'\t', arglen) !=
nullptr
326 || memchr(argv[i],
'\n', arglen) !=
nullptr){
327 cmdln <<
'"' << argv[i] <<
'"';
332 command_line_ = cmdln.str();
339 command_line_ = cmdline;
346 other_.push_back(_other);
357 template <
typename StreamType=std::ostream>
359 const std::string& line_start=
"# ",
360 const std::string& line_end=
"\n",
361 bool show_field_names=
true)
const {
366 if(show_field_names){
367 o << std::left << std::setw(10) << (p.first +
":");
369 o << p.second << line_end;
372 if(
other.size() > 0){
373 o << line_start <<
"Other:" << line_end;
374 for(
const std::string& oi :
other){
375 o << line_start <<
" " << oi << line_end;
384 template <
typename ...Args>
386 std::stringstream ss;
397 template <
typename ...Args>
408 std::vector<std::pair<std::string, std::string>> result;
409 result.emplace_back(
"Name",
sim_name);
416 std::stringstream timestr;
418 result.emplace_back(
"Elapsed", timestr.str());
420 last_captured_elapsed_time_ = result.back().second;
430 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::ostream &(*) manip_t(std::ostream &)
Default Constructor.
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)
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,...
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()
Default Constructor.
~SimulationInfo()=default
Destruction.
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.
Macros for handling exponential backoff.
std::ostream & operator<<(std::ostream &o, const SimulationInfo &info)
ostream insertion operator for SimulationInfo