Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
ProgressMeasurement.cpp
Go to the documentation of this file.
2
3#include <limits>
4#include <sstream>
5
9
10namespace storm {
11namespace utility {
12
13ProgressMeasurement::ProgressMeasurement(std::string const& itemName) : itemName(itemName), maxCount(std::numeric_limits<uint64_t>::max()) {
15 showProgress = generalSettings.isShowProgressSet();
16 delay = generalSettings.getShowProgressDelay();
17}
18
20 lastDisplayedCount = startCount;
21 timeOfStart = std::chrono::high_resolution_clock::now();
22 timeOfLastMessage = timeOfStart;
23}
24
26 if (showProgress) {
27 std::stringstream stream;
28 if (updateProgress(count, stream)) {
29 std::string message = stream.str();
30 // Message already contains line break at the end.
31 STORM_PRINT_AND_LOG(message);
32 return true;
33 }
34 }
35 return false;
36}
37
38bool ProgressMeasurement::updateProgress(uint64_t count, std::ostream& outstream) {
39 auto now = std::chrono::high_resolution_clock::now();
40 // Get the duration since the last message in milliseconds.
41 auto durationSinceLastMessage = static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::milliseconds>(now - this->timeOfLastMessage).count());
42 if (durationSinceLastMessage >= this->delay * 1000) {
43 double itemsPerSecond = (static_cast<double>(count - this->lastDisplayedCount) * 1000.0 / static_cast<double>(durationSinceLastMessage));
44 outstream << "Completed " << count << " " << itemName << " " << (this->isMaxCountSet() ? "(out of " + std::to_string(this->getMaxCount()) + ") " : "")
45 << "in " << std::chrono::duration_cast<std::chrono::seconds>(now - timeOfStart).count() << "s (currently " << itemsPerSecond << " "
46 << itemName << " per second).\n";
47 timeOfLastMessage = std::chrono::high_resolution_clock::now();
48 lastDisplayedCount = count;
49 return true;
50 }
51 return false;
52}
53
55 return this->maxCount < std::numeric_limits<uint64_t>::max();
56}
57
59 STORM_LOG_ASSERT(this->isMaxCountSet(), "Tried to get the maximal count but it was not set before.");
60 return this->maxCount;
61}
62
63void ProgressMeasurement::setMaxCount(uint64_t maxCount) {
64 this->maxCount = maxCount;
65}
66
68 this->maxCount = std::numeric_limits<uint64_t>::max();
69}
70
72 return this->delay;
73}
74
76 this->delay = delay;
77}
78
79std::string const& ProgressMeasurement::getItemName() const {
80 return this->itemName;
81}
82
83void ProgressMeasurement::setItemName(std::string const& name) {
84 this->itemName = name;
85}
86
87} // namespace utility
88} // namespace storm
ProgressMeasurement(std::string const &itemName="items")
Initializes progress measurement.
bool isMaxCountSet() const
Returns whether a maximal count (which is required to achieve 100% progress) has been specified.
std::string const & getItemName() const
Returns the current name of what we are counting (e.g.
bool updateProgress(uint64_t count)
Updates the progress to the current count and prints it if the delay passed.
uint64_t getShowProgressDelay() const
Returns the currently specified minimal delay (in seconds) between two progress messages.
void setMaxCount(uint64_t maxCount)
Sets the maximal possible count.
void startNewMeasurement(uint64_t startCount)
Starts a new measurement, dropping all progress information collected so far.
void setItemName(std::string const &name)
Customizes the name of what we are counting (e.g.
uint64_t getMaxCount() const
Returns the maximal possible count (if specified).
void unsetMaxCount()
Erases a previously specified maximal count.
void setShowProgressDelay(uint64_t delay)
Customizes the minimal delay between two progress messages.
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:11
#define STORM_PRINT_AND_LOG(message)
Definition macros.h:68
SettingsType const & getModule()
Get module.
ValueType max(ValueType const &first, ValueType const &second)
LabParser.cpp.
Definition cli.cpp:18