Exemplo n.º 1
0
/*
 * Update the stats display
 */
static void
stat_display(struct xferstat *xs, int force)
{
	struct timeval now;
	int ctty_pgrp;

	/* check if we're the foreground process */
	if (ioctl(STDERR_FILENO, TIOCGPGRP, &ctty_pgrp) == -1 ||
	    (pid_t)ctty_pgrp != pgrp)
		return;

	gettimeofday(&now, NULL);
	if (!force && now.tv_sec <= xs->last.tv_sec)
		return;
	xs->last = now;

	fprintf(stderr, "\r%-46.46s", xs->name);
	if (xs->size <= 0) {
		setproctitle("%s [%s]", xs->name, stat_bytes(xs->rcvd));
		fprintf(stderr, "        %s", stat_bytes(xs->rcvd));
	} else {
		setproctitle("%s [%d%% of %s]", xs->name,
		    (int)((100.0 * xs->rcvd) / xs->size),
		    stat_bytes(xs->size));
		fprintf(stderr, "%3d%% of %s",
		    (int)((100.0 * xs->rcvd) / xs->size),
		    stat_bytes(xs->size));
	}
	fprintf(stderr, " %s", stat_bps(xs));
	if (xs->size > 0 && xs->rcvd > 0 &&
	    xs->last.tv_sec >= xs->start.tv_sec + 10)
		fprintf(stderr, " %s", stat_eta(xs));
}
Exemplo n.º 2
0
/*
 * Update the stats display
 */
static void
stat_display(struct xferstat *xs, int force)
{
	char bytes[16], bps[16], eta[16];
	struct timeval now;
	int ctty_pgrp;

	/* check if we're the foreground process */
	if (ioctl(STDERR_FILENO, TIOCGPGRP, &ctty_pgrp) != 0 ||
	    (pid_t)ctty_pgrp != pgrp)
		return;

	gettimeofday(&now, NULL);
	if (!force && now.tv_sec <= xs->last.tv_sec)
		return;
	xs->last2 = xs->last;
	xs->last = now;

	fprintf(stderr, "\r%-46.46s", xs->name);
	if (xs->rcvd >= xs->size) {
		stat_bytes(bytes, sizeof bytes, xs->rcvd);
		setproctitle("%s [%s]", xs->name, bytes);
		fprintf(stderr, "        %s", bytes);
	} else {
		stat_bytes(bytes, sizeof bytes, xs->size);
		setproctitle("%s [%d%% of %s]", xs->name,
		    (int)((100.0 * xs->rcvd) / xs->size),
		    bytes);
		fprintf(stderr, "%3d%% of %s",
		    (int)((100.0 * xs->rcvd) / xs->size),
		    bytes);
	}
	if (force == 2) {
		xs->lastrcvd = xs->offset;
		xs->last2 = xs->start;
	}
	stat_bps(bps, sizeof bps, xs);
	fprintf(stderr, " %s", bps);
	if ((xs->size > 0 && xs->rcvd > 0 &&
	     xs->last.tv_sec >= xs->start.tv_sec + 3) ||
	    force == 2) {
		stat_eta(eta, sizeof eta, xs);
		fprintf(stderr, " %s", eta);
	}
	xs->lastrcvd = xs->rcvd;
}
Exemplo n.º 3
0
/*
 * Update the stats display
 */
static void
stat_display(struct xferstat *xs, int force)
{
    struct timeval now;
#if !defined(__minix)
    int ctty_pgrp;
#endif /* !defined(__minix) */

    /* Minix returns "Not a typewriter error" */
#if defined(TIOCGPGRP) && !defined(__minix)
    /* check if we're the foreground process */
    if (ioctl(STDERR_FILENO, TIOCGPGRP, &ctty_pgrp) == -1 ||
            (pid_t)ctty_pgrp != pgrp)
        return;
#endif

    gettimeofday(&now, NULL);
    if (!force && now.tv_sec <= xs->last.tv_sec)
        return;
    xs->last = now;

    fprintf(stderr, "\r%-46.46s", xs->name);
    if (xs->size <= 0) {
#if HAVE_SETPROCTITLE
        setproctitle("%s [%s]", xs->name, stat_bytes(xs->rcvd));
#endif
        fprintf(stderr, "        %s", stat_bytes(xs->rcvd));
    } else {
#if HAVE_SETPROCTITLE
        setproctitle("%s [%d%% of %s]", xs->name,
                     (int)((100.0 * xs->rcvd) / xs->size),
                     stat_bytes(xs->size));
#endif
        fprintf(stderr, "%3d%% of %s",
                (int)((100.0 * xs->rcvd) / xs->size),
                stat_bytes(xs->size));
    }
    fprintf(stderr, " %s", stat_bps(xs));
    if (xs->size > 0 && xs->rcvd > 0 &&
            xs->last.tv_sec >= xs->start.tv_sec + 10)
        fprintf(stderr, " %s", stat_eta(xs));
    fflush(stderr);
}
Exemplo n.º 4
0
/*
 * Finalize the transfer statistics
 */
static void
stat_end(struct xferstat *xs)
{
	gettimeofday(&xs->last, NULL);
	if (v_tty && v_level > 0) {
		stat_display(xs, 1);
		putc('\n', stderr);
	} else if (v_level > 0) {
		fprintf(stderr, "        %s %s\n",
		    stat_bytes(xs->size), stat_bps(xs));
	}
}
Exemplo n.º 5
0
/*
 * Compute and display transfer rate
 */
static const char *
stat_bps(struct xferstat *xs)
{
	static char str[16];
	double delta, bps;

	delta = (xs->last.tv_sec + (xs->last.tv_usec / 1.e6))
	    - (xs->start.tv_sec + (xs->start.tv_usec / 1.e6));
	if (delta == 0.0) {
		snprintf(str, sizeof str, "?? Bps");
	} else {
		bps = (xs->rcvd - xs->offset) / delta;
		snprintf(str, sizeof str, "%sps", stat_bytes((off_t)bps));
	}
	return (str);
}
Exemplo n.º 6
0
/*
 * Finalize the transfer statistics
 */
static void
stat_end(struct xferstat *xs)
{
	char bytes[16], bps[16], eta[16];

	gettimeofday(&xs->last, NULL);
	if (v_progress) {
		stat_display(xs, 2);
		putc('\n', stderr);
	} else if (v_level > 0) {
		stat_bytes(bytes, sizeof bytes, xs->rcvd);
		stat_bps(bps, sizeof bps, xs);
		stat_eta(eta, sizeof eta, xs);
		fprintf(stderr, "        %s %s %s\n", bytes, bps, eta);
	}
}
Exemplo n.º 7
0
/*
 * Compute and display transfer rate
 */
static void
stat_bps(char *str, size_t strsz, struct xferstat *xs)
{
	char bytes[16];
	double delta, bps;

	delta = ((double)xs->last.tv_sec + (xs->last.tv_usec / 1.e6))
	    - ((double)xs->last2.tv_sec + (xs->last2.tv_usec / 1.e6));

	if (delta == 0.0) {
		snprintf(str, strsz, "?? Bps");
	} else {
		bps = (xs->rcvd - xs->lastrcvd) / delta;
		stat_bytes(bytes, sizeof bytes, (off_t)bps);
		snprintf(str, strsz, "%sps", bytes);
	}
}