(calc_copy_file_progress): clarify calculation of BPSes and ETAs.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2024-09-21 13:04:26 +03:00
parent 07ea52d767
commit ff1a404bb3
3 changed files with 15 additions and 16 deletions

View File

@ -1133,37 +1133,36 @@ static void
calc_copy_file_progress (file_op_context_t *ctx, gint64 tv_current, off_t file_part,
off_t file_size)
{
gint64 dt;
double dt;
/* Update rotating dash after some time */
rotate_dash (TRUE);
/* Compute ETA */
dt = (tv_current - ctx->transfer_start) / G_USEC_PER_SEC;
dt = (tv_current - ctx->transfer_start) / (double) G_USEC_PER_SEC;
if (file_part == 0)
ctx->eta_secs = 0.0;
else
ctx->eta_secs = ((dt / (double) file_part) * file_size) - dt;
ctx->eta_secs = ((double) file_size / file_part - 1) * dt;
/* Compute BPS rate */
dt = MAX (1, dt);
ctx->bps = file_part / dt;
dt = MAX (1.0, dt);
ctx->bps = (long) (file_part / dt);
/* Compute total ETA and BPS */
if (ctx->total_bytes != 0)
{
dt = (tv_current - ctx->total_transfer_start) / G_USEC_PER_SEC;
dt = MAX (1, dt);
ctx->total_bps = ctx->total_progress_bytes / dt;
dt = (tv_current - ctx->total_transfer_start) / (double) G_USEC_PER_SEC;
if (ctx->total_bps == 0)
const uintmax_t copied_bytes = ctx->total_progress_bytes + file_part;
if (copied_bytes == 0)
ctx->total_eta_secs = 0;
else
{
const uintmax_t remain_bytes = ctx->total_bytes - ctx->total_progress_bytes;
ctx->total_eta_secs = remain_bytes / ctx->total_bps;
}
ctx->total_eta_secs = ((double) ctx->total_bytes / copied_bytes - 1) * dt;
dt = MAX (1.0, dt);
ctx->total_bps = (long) (copied_bytes / dt);
}
}

View File

@ -1140,7 +1140,7 @@ file_progress_show_total (file_op_context_t *ctx, uintmax_t copied_bytes, gint64
label_set_textv (ui->time_label, _("Time: %s %s"), buffer2, buffer3);
else
{
file_bps_prepare_for_show (buffer4, (long) ctx->total_bps);
file_bps_prepare_for_show (buffer4, ctx->total_bps);
label_set_textv (ui->time_label, _("Time: %s %s (%s)"), buffer2, buffer3, buffer4);
}
}
@ -1150,7 +1150,7 @@ file_progress_show_total (file_op_context_t *ctx, uintmax_t copied_bytes, gint64
label_set_textv (ui->time_label, _("Time: %s"), buffer2);
else
{
file_bps_prepare_for_show (buffer4, (long) ctx->total_bps);
file_bps_prepare_for_show (buffer4, ctx->total_bps);
label_set_textv (ui->time_label, _("Time: %s (%s)"), buffer2, buffer4);
}
}

View File

@ -143,7 +143,7 @@ typedef struct
/* The estimated time of arrival in seconds */
double total_eta_secs;
/* Transferred bytes per second */
size_t total_bps;
long total_bps;
/* Used in OP_MOVE between copy and remove directories */
size_t prev_total_progress_count;