Commit 94b6ab8f authored by pdw's avatar pdw

Updated units display (again). This time goes up to GB.

Spec file to 0.8.
parent c5ff172c
Things to do for iftop
$Id$
* Turn off services resolution.
* IP types other than v4?
* Which average to use for the bar graph? Show several and peaks? Colours?
......
Summary: iftop - provides realtime bandwith usage on an interface
Name: iftop
Version: 0.8pre1
Version: 0.8
Release: 1
License: GPL
Group: Applications/Internet
Source0: http://www.ex-parrot.com/~pdw/iftop/download/iftop-0.8pre1.tar.gz
Source0: http://www.ex-parrot.com/~pdw/iftop/download/iftop-0.8.tar.gz
URL: http://www.ex-parrot.com/~pdw/iftop/
Buildroot: %{_tmppath}/%{name}-%{version}-%(id -u -n)
Packager: Riku Meskanen <mesrik@cc.jyu.fi>
......
......@@ -27,6 +27,9 @@
/* 1, 15 and 60 seconds */
int history_divs[HISTORY_DIVISIONS] = {1, 5, 20};
#define UNIT_DIVISIONS 4
char* unit_bits[UNIT_DIVISIONS] = { "b", "K", "M", "G"};
char* unit_bytes[UNIT_DIVISIONS] = { "B", "KB", "MB", "GB"};
typedef struct host_pair_line_tag {
addr_pair ap;
......@@ -63,27 +66,26 @@ int screen_line_compare(void* a, void* b) {
}
void readable_size(float n, char* buf, int bsize, int ksize, int bytes) {
if(n >= 100 * ksize * ksize) {
snprintf(buf, bsize, " %4.0f%s", n / (ksize * ksize), bytes ? "MB" : "M");
}
else if(n >= 10 * ksize * ksize) {
snprintf(buf, bsize, " %4.1f%s", n / (ksize * ksize), bytes ? "MB" : "M");
}
if(n >= ksize * ksize) {
snprintf(buf, bsize, " %4.2f%s", n / (ksize * ksize), bytes ? "MB" : "M" );
}
else if(n >= 100 * ksize) {
snprintf(buf, bsize, " %4.0f%s", n / ksize, bytes ? "KB" : "K" );
}
else if(n >= 10 * ksize) {
snprintf(buf, bsize, " %4.1f%s", n / ksize, bytes ? "KB" : "K" );
}
else if(n >= ksize) {
snprintf(buf, bsize, " %4.2f%s", n / ksize, bytes ? "KB" : "K" );
}
else {
snprintf(buf, bsize, " %4.0f%s", n, bytes ? "B" : "b");
}
int i = 0;
int size = 1;
while(1) {
if(n < size * ksize || i >= UNIT_DIVISIONS - 1) {
snprintf(buf, bsize, " %4.0f%s", n / size, bytes ? unit_bytes[i] : unit_bits[i]);
break;
}
i++;
size *= ksize;
if(n < size * 10) {
snprintf(buf, bsize, " %4.2f%s", n / size, bytes ? unit_bytes[i] : unit_bits[i]);
break;
}
else if(n < size * 100) {
snprintf(buf, bsize, " %4.1f%s", n / size, bytes ? unit_bytes[i] : unit_bits[i]);
break;
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment