15 showProgress = generalSettings.isShowProgressSet();
16 delay = generalSettings.getShowProgressDelay();
20 lastDisplayedCount = startCount;
21 timeOfStart = std::chrono::high_resolution_clock::now();
22 timeOfLastMessage = timeOfStart;
27 std::stringstream stream;
29 std::string message = stream.str();
39 auto now = std::chrono::high_resolution_clock::now();
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;
55 return this->maxCount < std::numeric_limits<uint64_t>::max();
60 return this->maxCount;
64 this->maxCount = maxCount;
68 this->maxCount = std::numeric_limits<uint64_t>::max();
80 return this->itemName;
84 this->itemName = name;
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)
#define STORM_PRINT_AND_LOG(message)
SettingsType const & getModule()
Get module.
ValueType max(ValueType const &first, ValueType const &second)