diff options
author | Calvin Morrison <cmorrison@holts.com> | 2016-02-11 10:56:30 -0500 |
---|---|---|
committer | Calvin Morrison <cmorrison@holts.com> | 2016-02-11 10:58:49 -0500 |
commit | 67d67ff739e4aebcca94d3c1f2676ac2a598dcca (patch) | |
tree | 4858a3395c03be441885fbe0eee81aa7085cfba6 /fsbm.c | |
parent | 38787b9c3111712d92b5b388b71e44900142ffa4 (diff) |
FSBM 1.1
added -i flag for specific interfaces
added -r flag for raw byte counts
update usage
Diffstat (limited to 'fsbm.c')
-rw-r--r-- | fsbm.c | 32 |
1 files changed, 25 insertions, 7 deletions
@@ -22,8 +22,12 @@ struct iface { }; +bool raw = false; +bool request_name_enabled = false; volatile bool q = false; bool use_bits = false; +char *request_name; + struct iface *interfaces = NULL; size_t no_iface = 0; @@ -32,11 +36,18 @@ void endHandler(int signum) { } void print_bps(double bytesPerSecond) { - const char* prefixes[] = { "b", "k", "M", "G", "T", "P", "E", "Z", "Y" }; + const char* prefixes[] = { "", "k", "M", "G", "T", "P", "E", "Z", "Y" }; double value; const char* unit; unsigned prefix = 0; + if(raw) { + if(use_bits) + bytesPerSecond *= 8; + printf("%.2f", bytesPerSecond); + return; + } + // Calculate the value if(use_bits) { value = bytesPerSecond * 8; @@ -97,15 +108,16 @@ void print_stats() { } len = name - buf; + if(request_name_enabled && strcmp(name, request_name) != 0) { + continue; + } + // Parse the statistics, alls well, then get this shit going, otherwise f it. if(sscanf(stats, "%Lu %*u %*u %*u %*u %*u %*u %*u %Lu", &rx_bytes, &tx_bytes) == 2) { size_t i = 0; bool found = false; - if(interfaces == NULL) { - goto skip; - } for(i = 0; i < no_iface; i++) { // if it exists in our interfaces, great. reuse the iface struct if(strcmp(name, interfaces[i].interface) == 0) { @@ -113,7 +125,6 @@ void print_stats() { break; } } - skip: if(found) { double timeDelta, rx_speed, tx_speed = 0; @@ -163,7 +174,7 @@ int main(int argc, char **argv) { int c; unsigned long long interval = 10 * 100000; - while ((c = getopt (argc, argv, "bd:hv")) != -1) + while ((c = getopt (argc, argv, "rbi:d:hv")) != -1) switch (c) { case 'b': @@ -175,9 +186,16 @@ int main(int argc, char **argv) { interval = interval * 100000; break; case 'h': - printf("USAGE: fsbm, -b specifies bits, -d sets interval in 10ths of seconds, 1 sec default\n"); + printf("USAGE: fsbm, -i shows only matching interface, -r gives raw counts, -b specifies bits, -d sets interval in 10ths of seconds, 1 sec default\n"); exit(EXIT_SUCCESS); break; + case 'i': + request_name_enabled = true; + request_name = strdup(optarg); + break; + case 'r': + raw = true; + break; case 'v': printf("Version 1\n"); exit(EXIT_SUCCESS); |