version 1.15, 2003/08/31 12:14:22 |
version 1.15.2.2, 2004/08/19 22:37:31 |
|
|
/* signal handler for updating the progress meter */ |
/* signal handler for updating the progress meter */ |
static void update_progress_meter(int); |
static void update_progress_meter(int); |
|
|
static time_t start; /* start progress */ |
static time_t start; /* start progress */ |
static time_t last_update; /* last progress update */ |
static time_t last_update; /* last progress update */ |
static char *file; /* name of the file being transferred */ |
static char *file; /* name of the file being transferred */ |
static off_t end_pos; /* ending position of transfer */ |
static off_t end_pos; /* ending position of transfer */ |
static off_t cur_pos; /* transfer position as of last refresh */ |
static off_t cur_pos; /* transfer position as of last refresh */ |
static volatile off_t *counter; /* progress counter */ |
static volatile off_t *counter; /* progress counter */ |
static long stalled; /* how long we have been stalled */ |
static long stalled; /* how long we have been stalled */ |
static int bytes_per_second; /* current speed in bytes per second */ |
static int bytes_per_second; /* current speed in bytes per second */ |
static int win_size; /* terminal window size */ |
static int win_size; /* terminal window size */ |
|
|
/* units for format_size */ |
/* units for format_size */ |
static const char unit[] = " KMGT"; |
static const char unit[] = " KMGT"; |
|
|
bytes = (bytes + 512) / 1024; |
bytes = (bytes + 512) / 1024; |
} |
} |
snprintf(buf, size, "%3lld.%1lld%c%s", |
snprintf(buf, size, "%3lld.%1lld%c%s", |
(long long) bytes / 100, |
(long long) (bytes + 5) / 100, |
(long long) (bytes + 5) / 10 % 10, |
(long long) (bytes + 5) / 10 % 10, |
unit[i], |
unit[i], |
i ? "B" : " "); |
i ? "B" : " "); |
|
|
off_t transferred; |
off_t transferred; |
double elapsed; |
double elapsed; |
int percent; |
int percent; |
int bytes_left; |
off_t bytes_left; |
int cur_speed; |
int cur_speed; |
int hours, minutes, seconds; |
int hours, minutes, seconds; |
int i, len; |
int i, len; |
|
|
|
|
if (bytes_left > 0) |
if (bytes_left > 0) |
elapsed = now - last_update; |
elapsed = now - last_update; |
else |
else { |
elapsed = now - start; |
elapsed = now - start; |
|
/* Calculate true total speed when done */ |
|
transferred = end_pos; |
|
bytes_per_second = 0; |
|
} |
|
|
/* calculate speed */ |
/* calculate speed */ |
if (elapsed != 0) |
if (elapsed != 0) |
cur_speed = (transferred / elapsed); |
cur_speed = (transferred / elapsed); |
else |
else |
cur_speed = 0; |
cur_speed = transferred; |
|
|
#define AGE_FACTOR 0.9 |
#define AGE_FACTOR 0.9 |
if (bytes_per_second != 0) { |
if (bytes_per_second != 0) { |
|
|
|
|
/* bandwidth usage */ |
/* bandwidth usage */ |
format_rate(buf + strlen(buf), win_size - strlen(buf), |
format_rate(buf + strlen(buf), win_size - strlen(buf), |
bytes_per_second); |
(off_t)bytes_per_second); |
strlcat(buf, "/s ", win_size); |
strlcat(buf, "/s ", win_size); |
|
|
/* ETA */ |
/* ETA */ |
|
|
strlcat(buf, " ", win_size); |
strlcat(buf, " ", win_size); |
} |
} |
|
|
atomicio(vwrite, STDOUT_FILENO, buf, win_size); |
atomicio(vwrite, STDOUT_FILENO, buf, win_size - 1); |
last_update = now; |
last_update = now; |
} |
} |
|
|
|
|
} |
} |
|
|
void |
void |
start_progress_meter(char *f, off_t filesize, off_t *stat) |
start_progress_meter(char *f, off_t filesize, off_t *ctr) |
{ |
{ |
struct winsize winsize; |
struct winsize winsize; |
|
|
|
|
file = f; |
file = f; |
end_pos = filesize; |
end_pos = filesize; |
cur_pos = 0; |
cur_pos = 0; |
counter = stat; |
counter = ctr; |
stalled = 0; |
stalled = 0; |
bytes_per_second = 0; |
bytes_per_second = 0; |
|
|