mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-18 14:20:09 +01:00
Add various units for progress speed reporting.
The progress function remained silent unless the speed was higher than minimal delta for double type in MiB/s. That could confuse users that progress got stucked, but it in fact it was only slow. Now wipe and reencryption progess functions can report speeds in B/s up to GiB/s.
This commit is contained in:
@@ -385,9 +385,9 @@ static void tools_time_progress(uint64_t device_size, uint64_t bytes, uint64_t *
|
|||||||
{
|
{
|
||||||
struct timeval now_time;
|
struct timeval now_time;
|
||||||
unsigned long long mbytes, eta;
|
unsigned long long mbytes, eta;
|
||||||
double tdiff, mib, frequency;
|
double tdiff, uib, frequency;
|
||||||
int final = (bytes == device_size);
|
int final = (bytes == device_size);
|
||||||
const char *eol;
|
const char *eol, *ustr = "";
|
||||||
|
|
||||||
if (opt_batch_mode)
|
if (opt_batch_mode)
|
||||||
return;
|
return;
|
||||||
@@ -418,26 +418,35 @@ static void tools_time_progress(uint64_t device_size, uint64_t bytes, uint64_t *
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
mbytes = bytes / 1024 / 1024;
|
mbytes = bytes / 1024 / 1024;
|
||||||
mib = (double)((bytes - *start_bytes) / 1024 / 1024) / tdiff;
|
uib = (double)(bytes - *start_bytes) / tdiff;
|
||||||
if (!mib)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* FIXME: calculate this from last minute only. */
|
/* FIXME: calculate this from last minute only. */
|
||||||
eta = (unsigned long long)(device_size / 1024 / 1024 / mib - tdiff);
|
eta = (unsigned long long)(device_size / uib - tdiff);
|
||||||
|
|
||||||
|
if (uib > 1073741824.0f) {
|
||||||
|
uib /= 1073741824.0f;
|
||||||
|
ustr = "Gi";
|
||||||
|
} else if (uib > 1048576.0f) {
|
||||||
|
uib /= 1048576.0f;
|
||||||
|
ustr = "Mi";
|
||||||
|
} else if (uib > 1024.0f) {
|
||||||
|
uib /= 1024.0f;
|
||||||
|
ustr = "Ki";
|
||||||
|
}
|
||||||
|
|
||||||
tools_clear_line();
|
tools_clear_line();
|
||||||
if (final)
|
if (final)
|
||||||
log_std("Finished, time %02llu:%02llu.%03llu, "
|
log_std("Finished, time %02llu:%02llu.%03llu, "
|
||||||
"%4llu MiB written, speed %5.1f MiB/s\n",
|
"%4llu MiB written, speed %5.1f %sB/s\n",
|
||||||
(unsigned long long)tdiff / 60,
|
(unsigned long long)tdiff / 60,
|
||||||
(unsigned long long)tdiff % 60,
|
(unsigned long long)tdiff % 60,
|
||||||
(unsigned long long)((tdiff - floor(tdiff)) * 1000.0),
|
(unsigned long long)((tdiff - floor(tdiff)) * 1000.0),
|
||||||
mbytes, mib);
|
mbytes, uib, ustr);
|
||||||
else
|
else
|
||||||
log_std("Progress: %5.1f%%, ETA %02llu:%02llu, "
|
log_std("Progress: %5.1f%%, ETA %02llu:%02llu, "
|
||||||
"%4llu MiB written, speed %5.1f MiB/s%s",
|
"%4llu MiB written, speed %5.1f %sB/s%s",
|
||||||
(double)bytes / device_size * 100,
|
(double)bytes / device_size * 100,
|
||||||
eta / 60, eta % 60, mbytes, mib, eol);
|
eta / 60, eta % 60, mbytes, uib, ustr, eol);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user