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