aboutsummaryrefslogtreecommitdiff
path: root/fsbm.c
diff options
context:
space:
mode:
Diffstat (limited to 'fsbm.c')
-rw-r--r--fsbm.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/fsbm.c b/fsbm.c
index ada40b8..18fa55c 100644
--- a/fsbm.c
+++ b/fsbm.c
@@ -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);