mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-20 15:20:07 +01:00
Minor time progress print out improvements.
Mostly moves float arithmetics in slow path and also cleans up code a bit.
This commit is contained in:
@@ -369,11 +369,11 @@ int tools_string_to_size(const char *s, uint64_t *size)
|
|||||||
|
|
||||||
/* Time progress helper */
|
/* Time progress helper */
|
||||||
|
|
||||||
/* The difference in seconds between two times in "timeval" format. */
|
/* The difference in microseconds between two times in "timeval" format. */
|
||||||
static double time_diff(struct timeval *start, struct timeval *end)
|
static uint64_t time_diff(struct timeval *start, struct timeval *end)
|
||||||
{
|
{
|
||||||
return (end->tv_sec - start->tv_sec)
|
return (end->tv_sec - start->tv_sec) * UINT64_C(1000000)
|
||||||
+ (end->tv_usec - start->tv_usec) / 1E6;
|
+ (end->tv_usec - start->tv_usec);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tools_clear_line(void)
|
static void tools_clear_line(void)
|
||||||
@@ -385,8 +385,8 @@ static void tools_clear_line(void)
|
|||||||
static void tools_time_progress(uint64_t device_size, uint64_t bytes, struct tools_progress_params *parms)
|
static void tools_time_progress(uint64_t device_size, uint64_t bytes, struct tools_progress_params *parms)
|
||||||
{
|
{
|
||||||
struct timeval now_time;
|
struct timeval now_time;
|
||||||
unsigned long long mbytes, eta;
|
uint64_t mbytes, eta, frequency;
|
||||||
double tdiff, uib, frequency;
|
double tdiff, uib;
|
||||||
int final = (bytes == device_size);
|
int final = (bytes == device_size);
|
||||||
const char *eol, *ustr = "";
|
const char *eol, *ustr = "";
|
||||||
|
|
||||||
@@ -399,10 +399,10 @@ static void tools_time_progress(uint64_t device_size, uint64_t bytes, struct too
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (parms->frequency) {
|
if (parms->frequency) {
|
||||||
frequency = (double)parms->frequency;
|
frequency = parms->frequency * UINT64_C(1000000);
|
||||||
eol = "\n";
|
eol = "\n";
|
||||||
} else {
|
} else {
|
||||||
frequency = 0.5;
|
frequency = 500000;
|
||||||
eol = "";
|
eol = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -411,14 +411,14 @@ static void tools_time_progress(uint64_t device_size, uint64_t bytes, struct too
|
|||||||
|
|
||||||
parms->end_time = now_time;
|
parms->end_time = now_time;
|
||||||
|
|
||||||
tdiff = time_diff(&parms->start_time, &parms->end_time);
|
tdiff = time_diff(&parms->start_time, &parms->end_time) / 1E6;
|
||||||
if (!tdiff)
|
if (!tdiff)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mbytes = bytes / 1024 / 1024;
|
mbytes = bytes / 1024 / 1024;
|
||||||
uib = (double)(bytes - parms->start_offset) / tdiff;
|
uib = (double)(bytes - parms->start_offset) / tdiff;
|
||||||
|
|
||||||
eta = (unsigned long long)(device_size / uib - tdiff);
|
eta = (uint64_t)(device_size / uib - tdiff);
|
||||||
|
|
||||||
if (uib > 1073741824.0f) {
|
if (uib > 1073741824.0f) {
|
||||||
uib /= 1073741824.0f;
|
uib /= 1073741824.0f;
|
||||||
@@ -434,11 +434,11 @@ static void tools_time_progress(uint64_t device_size, uint64_t bytes, struct too
|
|||||||
if (!parms->frequency)
|
if (!parms->frequency)
|
||||||
tools_clear_line();
|
tools_clear_line();
|
||||||
if (final)
|
if (final)
|
||||||
log_std("Finished, time %02llu:%02llu.%03llu, "
|
log_std("Finished, time %02" PRIu64 ":%02" PRIu64 ".%03" PRIu64 ", "
|
||||||
"%4llu MiB written, speed %5.1f %sB/s\n",
|
"%4" PRIu64 " MiB written, speed %5.1f %sB/s\n",
|
||||||
(unsigned long long)tdiff / 60,
|
(uint64_t)tdiff / 60,
|
||||||
(unsigned long long)tdiff % 60,
|
(uint64_t)tdiff % 60,
|
||||||
(unsigned long long)((tdiff - floor(tdiff)) * 1000.0),
|
(uint64_t)((tdiff - floor(tdiff)) * 1000.0),
|
||||||
mbytes, uib, ustr);
|
mbytes, uib, ustr);
|
||||||
else
|
else
|
||||||
log_std("Progress: %5.1f%%, ETA %02llu:%02llu, "
|
log_std("Progress: %5.1f%%, ETA %02llu:%02llu, "
|
||||||
|
|||||||
Reference in New Issue
Block a user