Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
print.cpp
Go to the documentation of this file.
1#include "print.h"
2
4#include "storm/utility/cli.h"
6
7#include <boost/algorithm/string/replace.hpp>
8#include <ctime>
9
10// Includes for the linked libraries and versions header.
12
13#ifdef STORM_HAVE_GLPK
14#include "glpk.h"
15#endif
16#ifdef STORM_HAVE_GUROBI
17#include "gurobi_c.h"
18#endif
19#ifdef STORM_HAVE_MSAT
20#include "mathsat.h"
21#endif
22#ifdef STORM_HAVE_SOPLEX
23#include "soplex.h"
24#endif
25#ifdef STORM_HAVE_SMTRAT
26#include "lib/smtrat.h"
27#endif
28#ifdef STORM_HAVE_SPOT
29#include <spot/misc/version.hh>
30#endif
31#ifdef STORM_HAVE_XERCES
32#include <xercesc/util/XercesVersion.hpp>
33#endif
34#ifdef STORM_HAVE_Z3
35#include "z3.h"
36#endif
37
38namespace storm {
39namespace cli {
40
41std::string shellQuoteSingleIfNecessary(const std::string& arg) {
42 // quote empty argument
43 if (arg.empty()) {
44 return "''";
45 }
46
47 if (arg.find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_./=") != std::string::npos) {
48 // contains potentially unsafe character, needs quoting
49 if (arg.find('\'') != std::string::npos) {
50 // contains ', we have to replace all ' with '\''
51 std::string escaped(arg);
52 boost::replace_all(escaped, "'", "'\\''");
53 return "'" + escaped + "'";
54 } else {
55 return "'" + arg + "'";
56 }
57 }
58
59 return arg;
60}
61
62void printHeader(std::string const& name, const int argc, const char** argv) {
64#ifndef NDEBUG
65 STORM_PRINT("DEBUG BUILD\n");
66#endif
67 // "Compute" the command line argument string with which storm was invoked.
68 std::stringstream commandStream;
69 for (int i = 1; i < argc; ++i) {
70 commandStream << " " << shellQuoteSingleIfNecessary(argv[i]);
71 }
72
73 std::string command = commandStream.str();
74
75 if (!command.empty()) {
76 STORM_PRINT('\n');
77 std::time_t result = std::time(nullptr);
78 STORM_PRINT("Date: " << std::ctime(&result));
79 STORM_PRINT("Command line arguments:" << commandStream.str() << '\n');
80 STORM_PRINT("Current working directory: " << storm::utility::cli::getCurrentWorkingDirectory() << "\n\n");
81 }
82}
83
87
88 // Print configuration options
89#ifdef STORM_USE_CLN_EA
90 STORM_PRINT("Using CLN numbers for exact arithmetic.\n");
91#else
92 STORM_PRINT("Using GMP numbers for exact arithmetic.\n");
93#endif
94#ifdef STORM_USE_CLN_RF
95 STORM_PRINT("Using CLN numbers for rational functions.\n");
96#else
97 STORM_PRINT("Using GMP numbers for rational functions.\n");
98#endif
99
100 // Print linked dependencies
101#ifdef STORM_HAVE_CARL
102 STORM_PRINT("Linked with CArL v" << STORM_CARL_VERSION << ".\n");
103#endif
104#ifdef STORM_HAVE_GLPK
105 STORM_PRINT("Linked with GNU Linear Programming Kit v" << GLP_MAJOR_VERSION << "." << GLP_MINOR_VERSION << ".\n");
106#endif
107#ifdef STORM_HAVE_GUROBI
108 STORM_PRINT("Linked with Gurobi Optimizer v" << GRB_VERSION_MAJOR << "." << GRB_VERSION_MINOR << "." << GRB_VERSION_TECHNICAL << ".\n");
109#endif
110#ifdef STORM_HAVE_INTELTBB
111 STORM_PRINT("Linked with Intel Threading Building Blocks v" << TBB_VERSION_MAJOR << "." << TBB_VERSION_MINOR << " (Interface version "
112 << TBB_INTERFACE_VERSION << ").\n");
113#endif
114#ifdef STORM_HAVE_MSAT
115 char* msatVersion = msat_get_version();
116 STORM_PRINT("Linked with " << msatVersion << ".\n");
117 msat_free(msatVersion);
118#endif
119#ifdef STORM_HAVE_SOPLEX
120 STORM_PRINT("Linked with Soplex v" << SOPLEX_VERSION << ".\n");
121#endif
122#ifdef STORM_HAVE_SMTRAT
123 STORM_PRINT("Linked with SMT-RAT v" << SMTRAT_VERSION << ".\n");
124#endif
125#ifdef STORM_HAVE_SPOT
126 STORM_PRINT("Linked with Spot v" << spot::version() << ".\n");
127#endif
128#ifdef STORM_HAVE_XERCES
129 STORM_PRINT("Linked with Xerces-C v" << gXercesMajVersion << "." << gXercesMinVersion << "." << gXercesRevision << ".\n");
130#endif
131#ifdef STORM_HAVE_Z3
132 unsigned int z3Major, z3Minor, z3BuildNumber, z3RevisionNumber;
133 Z3_get_version(&z3Major, &z3Minor, &z3BuildNumber, &z3RevisionNumber);
134#ifdef STORM_HAVE_Z3_OPTIMIZE
135 STORM_PRINT("Linked with Z3 Theorem Prover v" << z3Major << "." << z3Minor << " Build " << z3BuildNumber << " Rev " << z3RevisionNumber
136 << " (with optimization features).\n");
137#else
138 STORM_PRINT("Linked with Z3 Theorem Prover v" << z3Major << "." << z3Minor << " Build " << z3BuildNumber << " Rev " << z3RevisionNumber << ".\n");
139#endif
140#endif
141}
142
143void printTimeAndMemoryStatistics(uint64_t wallclockMilliseconds) {
144 struct rusage ru;
145 getrusage(RUSAGE_SELF, &ru);
146
147 std::cout << "\nPerformance statistics:\n";
148#ifdef MACOS
149 // For Mac OS, this is returned in bytes.
150 uint64_t maximumResidentSizeInMegabytes = ru.ru_maxrss / 1024 / 1024;
151#endif
152#ifdef LINUX
153 // For Linux, this is returned in kilobytes.
154 uint64_t maximumResidentSizeInMegabytes = ru.ru_maxrss / 1024;
155#endif
156 std::cout << " * peak memory usage: " << maximumResidentSizeInMegabytes << "MB\n";
157 char oldFillChar = std::cout.fill('0');
158 std::cout << " * CPU time: " << ru.ru_utime.tv_sec << "." << std::setw(3) << ru.ru_utime.tv_usec / 1000 << "s\n";
159 if (wallclockMilliseconds != 0) {
160 std::cout << " * wallclock time: " << (wallclockMilliseconds / 1000) << "." << std::setw(3) << (wallclockMilliseconds % 1000) << "s\n";
161 }
162 std::cout.fill(oldFillChar);
163}
164
165} // namespace cli
166} // namespace storm
#define STORM_PRINT(message)
Define the macros that print information and optionally also log it.
Definition macros.h:62
void printTimeAndMemoryStatistics(uint64_t wallclockMilliseconds)
Definition print.cpp:143
std::string shellQuoteSingleIfNecessary(const std::string &arg)
For a command-line argument, returns a quoted version with single quotes if it contains unsafe charac...
Definition print.cpp:41
void printHeader(std::string const &name, const int argc, const char **argv)
Definition print.cpp:62
void printVersion()
Definition print.cpp:84
std::string getCurrentWorkingDirectory()
Definition cli.cpp:13
LabParser.cpp.
Definition cli.cpp:18
static std::string longVersionString()
static std::string shortVersionString()
static std::string buildInfo()