Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
print.cpp
Go to the documentation of this file.
2
3#include <boost/algorithm/string/replace.hpp>
4#include <ctime>
5#include <filesystem>
6
7#include "storm-cli-utilities/resources.h" // This header knows what to include for memory consumption
10
11#ifdef STORM_HAVE_CVC5
12#include <cvc5/cvc5.h>
13#endif
14#ifdef STORM_HAVE_GLPK
15#include <glpk.h>
16#endif
17#ifdef STORM_HAVE_GUROBI
18#include <gurobi_c.h>
19#endif
20#ifdef STORM_HAVE_MATHSAT
21#include <mathsat.h>
22#endif
23#ifdef STORM_HAVE_SOPLEX
24#include <soplex.h>
25#endif
26#ifdef STORM_HAVE_SPOT
27#include <spot/misc/version.hh>
28#endif
29#ifdef STORM_HAVE_XERCES
30#include <xercesc/util/XercesVersion.hpp>
31#endif
32#ifdef STORM_HAVE_Z3
33#include <z3.h>
34#endif
35
36namespace storm {
37namespace cli {
38
39std::string shellQuoteSingleIfNecessary(const std::string& arg) {
40 // quote empty argument
41 if (arg.empty()) {
42 return "''";
43 }
44
45 if (arg.find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_./=") != std::string::npos) {
46 // contains potentially unsafe character, needs quoting
47 if (arg.find('\'') != std::string::npos) {
48 // contains ', we have to replace all ' with '\''
49 std::string escaped(arg);
50 boost::replace_all(escaped, "'", "'\\''");
51 return "'" + escaped + "'";
52 } else {
53 return "'" + arg + "'";
54 }
55 }
56
57 return arg;
58}
59
60void printHeader(std::string const& name, const int argc, const char** argv) {
62#ifndef NDEBUG
63 STORM_PRINT("DEBUG BUILD\n");
64#endif
65 // "Compute" the command line argument string with which storm was invoked.
66 std::stringstream commandStream;
67 for (int i = 1; i < argc; ++i) {
68 commandStream << " " << shellQuoteSingleIfNecessary(argv[i]);
69 }
70
71 std::string command = commandStream.str();
72
73 if (!command.empty()) {
74 STORM_PRINT('\n');
75 std::time_t result = std::time(nullptr);
76 STORM_PRINT("Date: " << std::ctime(&result));
77 STORM_PRINT("Command line arguments:" << commandStream.str() << '\n');
78 STORM_PRINT("Current working directory: " << std::filesystem::current_path().string() << "\n\n");
79 }
80}
81
85
86 // Print configuration options
87#ifdef STORM_USE_CLN_EA
88 STORM_PRINT("Using CLN numbers for exact arithmetic.\n");
89#else
90 STORM_PRINT("Using GMP numbers for exact arithmetic.\n");
91#endif
92#ifdef STORM_USE_CLN_RF
93 STORM_PRINT("Using CLN numbers for rational functions.\n");
94#else
95 STORM_PRINT("Using GMP numbers for rational functions.\n");
96#endif
97
98 // Print linked dependencies
99 STORM_PRINT("Linked with CArL v" << STORM_CARL_VERSION << ".\n");
100#ifdef STORM_HAVE_CUDD
101 STORM_PRINT("Linked with CUDD.\n");
102#else
103 STORM_PRINT("Not linked with CUDD.\n");
104#endif
105#ifdef STORM_HAVE_CVC5
106 cvc5::TermManager cvc5TermManager;
107 cvc5::Solver cvc5Solver(cvc5TermManager);
108 STORM_PRINT("Linked with cvc5 v" << cvc5Solver.getVersion() << ".\n");
109#else
110 STORM_PRINT("Not linked with cvc5.\n");
111#endif
112#ifdef STORM_HAVE_GLPK
113 STORM_PRINT("Linked with GLPK v" << GLP_MAJOR_VERSION << "." << GLP_MINOR_VERSION << ".\n");
114#else
115 STORM_PRINT("Not linked with GLPK.\n");
116#endif
117#ifdef STORM_HAVE_GMM
118 STORM_PRINT("Linked with GMM.\n");
119#else
120 STORM_PRINT("Not linked with GMM.\n");
121#endif
122#ifdef STORM_HAVE_GUROBI
123 STORM_PRINT("Linked with Gurobi Optimizer v" << GRB_VERSION_MAJOR << "." << GRB_VERSION_MINOR << "." << GRB_VERSION_TECHNICAL << ".\n");
124#else
125 STORM_PRINT("Not linked with Gurobi.\n");
126#endif
127#ifdef STORM_HAVE_HIGHS
128 STORM_PRINT("Linked with HiGHS.\n");
129#else
130 STORM_PRINT("Not linked with HiGHS.\n");
131#endif
132#ifdef STORM_HAVE_MATHSAT
133 char* msatVersion = msat_get_version();
134 STORM_PRINT("Linked with " << msatVersion << ".\n");
135 msat_free(msatVersion);
136#else
137 STORM_PRINT("Not linked with MathSat.\n");
138#endif
139#ifdef STORM_HAVE_SOPLEX
140 STORM_PRINT("Linked with Soplex v" << SOPLEX_VERSION << ".\n");
141#else
142 STORM_PRINT("Not linked with Soplex.\n");
143#endif
144#ifdef STORM_HAVE_SPOT
145 STORM_PRINT("Linked with Spot v" << spot::version() << ".\n");
146#else
147 STORM_PRINT("Not linked with Spot.\n");
148#endif
149#ifdef STORM_HAVE_SYLVAN
150 STORM_PRINT("Linked with Sylvan.\n");
151#else
152 STORM_PRINT("Not linked with Sylvan.\n");
153#endif
154#ifdef STORM_HAVE_XERCES
155 STORM_PRINT("Linked with Xerces-C v" << gXercesMajVersion << "." << gXercesMinVersion << "." << gXercesRevision << ".\n");
156#else
157 STORM_PRINT("Not linked with Xerces-C.\n");
158#endif
159#ifdef STORM_HAVE_Z3
160 unsigned int z3Major, z3Minor, z3BuildNumber, z3RevisionNumber;
161 Z3_get_version(&z3Major, &z3Minor, &z3BuildNumber, &z3RevisionNumber);
162 STORM_PRINT("Linked with Z3 Theorem Prover v" << z3Major << "." << z3Minor << " Build " << z3BuildNumber << " Rev " << z3RevisionNumber << ".\n");
163#else
164 STORM_PRINT("Not linked with Z3 Theorem Prover\n");
165#endif
166 STORM_PRINT("\n");
167}
168
169void printTimeAndMemoryStatistics(uint64_t wallclockMilliseconds) {
170 struct rusage ru;
171 getrusage(RUSAGE_SELF, &ru);
172
173 std::cout << "\nPerformance statistics:\n";
174#ifdef MACOS
175 // For Mac OS, this is returned in bytes.
176 uint64_t maximumResidentSizeInMegabytes = ru.ru_maxrss / 1024 / 1024;
177#endif
178#ifdef LINUX
179 // For Linux, this is returned in kilobytes.
180 uint64_t maximumResidentSizeInMegabytes = ru.ru_maxrss / 1024;
181#endif
182 std::cout << " * peak memory usage: " << maximumResidentSizeInMegabytes << "MB\n";
183 char oldFillChar = std::cout.fill('0');
184 std::cout << " * CPU time: " << ru.ru_utime.tv_sec << "." << std::setw(3) << ru.ru_utime.tv_usec / 1000 << "s\n";
185 if (wallclockMilliseconds != 0) {
186 std::cout << " * wallclock time: " << (wallclockMilliseconds / 1000) << "." << std::setw(3) << (wallclockMilliseconds % 1000) << "s\n";
187 }
188 std::cout.fill(oldFillChar);
189}
190
191} // namespace cli
192} // namespace storm
void printTimeAndMemoryStatistics(uint64_t wallclockMilliseconds)
Definition print.cpp:169
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:39
void printHeader(std::string const &name, const int argc, const char **argv)
Definition print.cpp:60
void printVersion()
Definition print.cpp:82
#define STORM_PRINT(message)
Define the macros that print information to stdout and optionally also log it.
Definition print.h:14
static std::string longVersionString()
static std::string shortVersionString()
static std::string buildInfo()