add estimated time counter
This commit is contained in:
parent
6c9962eb8c
commit
7dcac92491
|
|
@ -184,6 +184,32 @@ static bool is_timing = false;
|
|||
static uint64_t last_count = -1;
|
||||
static time_point last_indeterminate_time;
|
||||
static std::atomic_bool locked = false;
|
||||
static std::array<duration, 10> one_percent_times;
|
||||
static size_t num_percent_times, percent_time_index;
|
||||
static time_point last_percent_time;
|
||||
|
||||
static duration average_times_for_one_percent()
|
||||
{
|
||||
duration pt {};
|
||||
|
||||
for (size_t i = 0; i < num_percent_times; i++) {
|
||||
pt += one_percent_times[i];
|
||||
}
|
||||
|
||||
pt /= num_percent_times;
|
||||
|
||||
return pt;
|
||||
}
|
||||
|
||||
static void register_average_time(duration dt)
|
||||
{
|
||||
one_percent_times[percent_time_index] = dt;
|
||||
percent_time_index = (percent_time_index + 1) % one_percent_times.size();
|
||||
|
||||
if (num_percent_times < one_percent_times.size()) {
|
||||
num_percent_times++;
|
||||
}
|
||||
}
|
||||
|
||||
void header(const char *name)
|
||||
{
|
||||
|
|
@ -233,6 +259,9 @@ void percent(uint64_t count, uint64_t max, bool displayElapsed)
|
|||
is_timing = true;
|
||||
last_count = -1;
|
||||
last_indeterminate_time = {};
|
||||
num_percent_times = 0;
|
||||
percent_time_index = 0;
|
||||
last_percent_time = I_FloatTime();
|
||||
}
|
||||
|
||||
if (count == max) {
|
||||
|
|
@ -243,13 +272,13 @@ void percent(uint64_t count, uint64_t max, bool displayElapsed)
|
|||
if (active_percent_callback) {
|
||||
active_percent_callback(std::nullopt, elapsed);
|
||||
} else {
|
||||
print(flag::PERCENT, "[done] time elapsed: {:.3}\n", elapsed);
|
||||
print(flag::PERCENT, "[done] time elapsed: {:%H:%M:%S}\n", elapsed);
|
||||
}
|
||||
} else {
|
||||
if (active_percent_callback) {
|
||||
active_percent_callback(100u, elapsed);
|
||||
} else {
|
||||
print(flag::PERCENT, "[100%] time elapsed: {:.3}\n", elapsed);
|
||||
print(flag::PERCENT, "[100%] time elapsed: {:%H:%M:%S}\n", elapsed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -261,7 +290,18 @@ void percent(uint64_t count, uint64_t max, bool displayElapsed)
|
|||
if (active_percent_callback) {
|
||||
active_percent_callback(pct, std::nullopt);
|
||||
} else {
|
||||
print(flag::PERCENT, "[{:>3}%]\r", pct);
|
||||
if (pct) {
|
||||
// we shifted from some other percent value to a non-zero value;
|
||||
// calculate the time it took to get a 1% change
|
||||
uint64_t diff = pct - last_count; // should always be >= 1
|
||||
duration dt = I_FloatTime() - last_percent_time;
|
||||
dt /= diff;
|
||||
register_average_time(dt);
|
||||
last_percent_time = I_FloatTime();
|
||||
print(flag::PERCENT, "[{:>3}%] est: {:%H:%M:%S}\r", pct, std::chrono::duration_cast<std::chrono::duration<long long>>(average_times_for_one_percent() * (100 - pct)));
|
||||
} else {
|
||||
print(flag::PERCENT, "[{:>3}%] ...\r", pct);
|
||||
}
|
||||
}
|
||||
last_count = pct;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue