forked from enlightenment/enlightenment
Netstatus: Average out throughput when time elapsed is greater than 1 second.
This isn't very accurate but seems to be what other tools that check at slower rates than every second do. For instance if you are checking every 10 seconds and in that time frame 500 kb was received, was the throughput for each second 50 kb? No, not likely, but that is the result you will see here. I guess this is one of those close enough things. Thanks to @davemds for reporting this issue.
This commit is contained in:
parent
7f3e7d933e
commit
3b7926a20a
|
@ -14,11 +14,14 @@ _netstatus_proc_getrstatus(Eina_Bool automax,
|
|||
char buf[4096], dummys[64];
|
||||
FILE *f;
|
||||
time_t current = time(NULL);
|
||||
time_t diff = 0;
|
||||
|
||||
if (!*last_checked)
|
||||
*last_checked = current;
|
||||
else if ((current - *last_checked) < 1)
|
||||
return;
|
||||
else
|
||||
diff = current - *last_checked;
|
||||
f = fopen("/proc/net/dev", "r");
|
||||
if (f)
|
||||
{
|
||||
|
@ -34,6 +37,8 @@ _netstatus_proc_getrstatus(Eina_Bool automax,
|
|||
fclose(f);
|
||||
}
|
||||
diffin = tot_in - *prev_in;
|
||||
if (diff > 1)
|
||||
diffin /= diff;
|
||||
if (!*prev_in)
|
||||
*prev_in = tot_in;
|
||||
else
|
||||
|
@ -69,11 +74,14 @@ _netstatus_proc_gettstatus(Eina_Bool automax,
|
|||
char buf[4096], dummys[64];
|
||||
FILE *f;
|
||||
time_t current = time(NULL);
|
||||
time_t diff = 0;
|
||||
|
||||
if (!*last_checked)
|
||||
*last_checked = current;
|
||||
else if ((current - *last_checked) < 1)
|
||||
return;
|
||||
else
|
||||
diff = current - *last_checked;
|
||||
f = fopen("/proc/net/dev", "r");
|
||||
if (f)
|
||||
{
|
||||
|
@ -89,6 +97,8 @@ _netstatus_proc_gettstatus(Eina_Bool automax,
|
|||
fclose(f);
|
||||
}
|
||||
diffout = tot_out - *prev_out;
|
||||
if (diff > 1)
|
||||
diffout /= diff;
|
||||
if (!*prev_out)
|
||||
*prev_out = tot_out;
|
||||
else
|
||||
|
|
|
@ -118,6 +118,7 @@ _netstatus_sysctl_getrstatus(Eina_Bool automax,
|
|||
int percent = 0;
|
||||
unsigned long int incoming = 0, outgoing = 0;
|
||||
time_t current = time(NULL);
|
||||
time_t diff = 0;
|
||||
#if defined(__OpenBSD__)
|
||||
_openbsd_generic_network_status(&incoming, &outgoing);
|
||||
#elif defined(__FreeBSD__) || defined(__DragonFly__)
|
||||
|
@ -128,9 +129,12 @@ _netstatus_sysctl_getrstatus(Eina_Bool automax,
|
|||
*last_checked = current;
|
||||
else if ((current - *last_checked) < 1)
|
||||
return;
|
||||
|
||||
else
|
||||
diff = current - *last_checked;
|
||||
tot_in = incoming;
|
||||
diffin = tot_in - *prev_in;
|
||||
if (diff > 1)
|
||||
diffin /= diff;
|
||||
if (!*prev_in)
|
||||
*prev_in = tot_in;
|
||||
else
|
||||
|
@ -164,6 +168,7 @@ _netstatus_sysctl_gettstatus(Eina_Bool automax,
|
|||
int percent = 0;
|
||||
unsigned long int incoming = 0, outgoing = 0;
|
||||
time_t current = time(NULL);
|
||||
time_t diff = 0;
|
||||
#if defined(__OpenBSD__)
|
||||
_openbsd_generic_network_status(&incoming, &outgoing);
|
||||
#elif defined(__FreeBSD__) || defined(__DragonFly__)
|
||||
|
@ -175,8 +180,12 @@ _netstatus_sysctl_gettstatus(Eina_Bool automax,
|
|||
*last_checked = current;
|
||||
else if ((current - *last_checked) < 1)
|
||||
return;
|
||||
else
|
||||
diff = current - *last_checked;
|
||||
|
||||
diffout = tot_out - *prev_out;
|
||||
if (diff > 1)
|
||||
diffout /= diff;
|
||||
if (!*prev_out)
|
||||
*prev_out = tot_out;
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue