Storm 1.14.0.1
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
7
8namespace storm {
9namespace utility {
10
11ProgressMeasurement::ProgressMeasurement(std::string const& itemName, uint64_t delay)
12 : delay(delay), itemName(itemName), maxCount(std::numeric_limits<uint64_t>::max()) {}
13
15 lastDisplayedCount = startCount;
16 timeOfStart = std::chrono::high_resolution_clock::now();
17 timeOfLastMessage = timeOfStart;
18}
19
21 bool progressPrinted = false;
22 STORM_LOG_PROGRESS_LAZY([this, count, &progressPrinted](std::ostream& stream) {
23 progressPrinted = updateProgress(count, stream);
24 return progressPrinted;
25 });
26 return progressPrinted;
27}
28
29bool ProgressMeasurement::updateProgress(uint64_t count, std::ostream& outstream) {
30 auto now = std::chrono::high_resolution_clock::now();
31 // Get the duration since the last message in milliseconds.
32 auto durationSinceLastMessage = static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::milliseconds>(now - this->timeOfLastMessage).count());
33 if (durationSinceLastMessage >= this->delay * 1000) {
34 double itemsPerSecond = (static_cast<double>(count - this->lastDisplayedCount) * 1000.0 / static_cast<double>(durationSinceLastMessage));
35 outstream << "Completed " << count << " " << itemName << " " << (this->isMaxCountSet() ? "(out of " + std::to_string(this->getMaxCount()) + ") " : "")
36 << "in " << std::chrono::duration_cast<std::chrono::seconds>(now - timeOfStart).count() << "s (currently " << itemsPerSecond << " "
37 << itemName << " per second).\n";
38 timeOfLastMessage = std::chrono::high_resolution_clock::now();
39 lastDisplayedCount = count;
40 return true;
41 }
42 return false;
43}
44
46 return this->maxCount < std::numeric_limits<uint64_t>::max();
47}
48
50 STORM_LOG_ASSERT(this->isMaxCountSet(), "Tried to get the maximal count but it was not set before.");
51 return this->maxCount;
52}
53
54void ProgressMeasurement::setMaxCount(uint64_t maxCount) {
55 this->maxCount = maxCount;
56}
57
59 this->maxCount = std::numeric_limits<uint64_t>::max();
60}
61
63 return this->delay;
64}
65
67 this->delay = delay;
68}
69
70std::string const& ProgressMeasurement::getItemName() const {
71 return this->itemName;
72}
73
74void ProgressMeasurement::setItemName(std::string const& name) {
75 this->itemName = name;
76}
77
78} // namespace utility
79} // namespace storm
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 logs it (on the progress log channel) if the delay pass...
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.
ProgressMeasurement(std::string const &itemName, uint64_t delay=defaultProgressMeasurementDelay)
Initializes progress measurement.
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_PROGRESS_LAZY(...)
Definition logging.h:77
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:9
ValueType max(ValueType const &first, ValueType const &second)