summaryrefslogtreecommitdiff
path: root/src/modules/sysinfo/netstatus
diff options
context:
space:
mode:
authorStephen 'Okra' Houston <smhouston88@gmail.com>2017-09-12 12:10:38 -0500
committerStephen 'Okra' Houston <smhouston88@gmail.com>2017-09-12 12:10:38 -0500
commit20a96271ca5ce95e983b466b5a2efc4b35f60fc3 (patch)
treebad42e62b7b94110eb4145847f4bb19ab6086e5e /src/modules/sysinfo/netstatus
parent9eebe065c262e0763649bb9f2dc1b0b9e2d434fe (diff)
downloadenlightenment-20a96271ca5ce95e983b466b5a2efc4b35f60fc3.tar.gz
Update netstatus in/out in the same file read. Fix cpufreq to use powersave again.
Diffstat (limited to 'src/modules/sysinfo/netstatus')
-rw-r--r--src/modules/sysinfo/netstatus/netstatus.c13
-rw-r--r--src/modules/sysinfo/netstatus/netstatus.h12
-rw-r--r--src/modules/sysinfo/netstatus/netstatus_proc.c67
-rw-r--r--src/modules/sysinfo/netstatus/netstatus_sysctl.c55
4 files changed, 51 insertions, 96 deletions
diff --git a/src/modules/sysinfo/netstatus/netstatus.c b/src/modules/sysinfo/netstatus/netstatus.c
index 0e87854a72..87ea74c180 100644
--- a/src/modules/sysinfo/netstatus/netstatus.c
+++ b/src/modules/sysinfo/netstatus/netstatus.c
@@ -7,14 +7,13 @@ struct _Thread_Config
int interval;
Instance *inst;
Eina_Bool automax;
+ time_t checktime;
int inpercent;
- time_t intime;
unsigned long in;
unsigned long incurrent;
unsigned long inmax;
Eina_Stringshare *instring;
int outpercent;
- time_t outtime;
unsigned long out;
unsigned long outcurrent;
unsigned long outmax;
@@ -145,11 +144,13 @@ _netstatus_cb_usage_check_main(void *data, Ecore_Thread *th)
if (ecore_thread_check(th)) break;
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__)
- _netstatus_sysctl_getrstatus(thc->automax, &thc->in, &thc->incurrent, &thc->inmax, &thc->intime, &thc->inpercent);
- _netstatus_sysctl_gettstatus(thc->automax, &thc->out, &thc->outcurrent, &thc->outmax, &thc->outtime, &thc->outpercent);
+ _netstatus_sysctl_getstatus(thc->automax, &thc->checktime, &thc->in, &thc->incurrent,
+ &thc->inmax, &thc->inpercent, &thc->out, &thc->outcurrent, &thc->outmax,
+ &thc->outpercent);
#else
- _netstatus_proc_getrstatus(thc->automax, &thc->in, &thc->incurrent, &thc->inmax, &thc->intime, &thc->inpercent);
- _netstatus_proc_gettstatus(thc->automax, &thc->out, &thc->outcurrent, &thc->outmax, &thc->outtime, &thc->outpercent);
+ _netstatus_proc_getstatus(thc->automax, &thc->checktime, &thc->in, &thc->incurrent,
+ &thc->inmax, &thc->inpercent, &thc->out, &thc->outcurrent, &thc->outmax,
+ &thc->outpercent);
#endif
if (!thc->incurrent)
{
diff --git a/src/modules/sysinfo/netstatus/netstatus.h b/src/modules/sysinfo/netstatus/netstatus.h
index 87010a04a4..ee1a36f907 100644
--- a/src/modules/sysinfo/netstatus/netstatus.h
+++ b/src/modules/sysinfo/netstatus/netstatus.h
@@ -17,9 +17,13 @@ struct _Netstatus_Config
};
EINTERN void _netstatus_config_updated(Instance *inst);
-EINTERN void _netstatus_proc_getrstatus(Eina_Bool automax, unsigned long *prev_in, unsigned long *prev_incurrent, unsigned long *prev_inmax, time_t *last_checked, int *prev_inpercent);
-EINTERN void _netstatus_proc_gettstatus(Eina_Bool automax, unsigned long *prev_out, unsigned long *prev_outcurrent, unsigned long *prev_outmax, time_t *last_checked, int *prev_outpercent);
-EINTERN void _netstatus_sysctl_getrstatus(Eina_Bool automax, unsigned long *prev_in, unsigned long *prev_incurrent, unsigned long *prev_inmax, time_t *last_checked, int *prev_inpercent);
-EINTERN void _netstatus_sysctl_gettstatus(Eina_Bool automax, unsigned long *prev_out, unsigned long *prev_outcurrent, unsigned long *prev_outmax, time_t *last_checked, int *prev_outpercent);
+EINTERN void _netstatus_proc_getstatus(Eina_Bool automax, time_t *last_checked,
+ unsigned long *prev_in, unsigned long *prev_incurrent, unsigned long *prev_inmax,
+ int *prev_inpercent, unsigned long *prev_out, unsigned long *prev_outcurrent,
+ unsigned long *prev_outmax, int *prev_outpercent);
+EINTERN void _netstatus_sysctl_getstatus(Eina_Bool automax, time_t *last_checked,
+ unsigned long *prev_in, unsigned long *prev_incurrent, unsigned long *prev_inmax,
+ int *prev_inpercent, unsigned long *prev_out, unsigned long *prev_outcurrent,
+ unsigned long *prev_outmax, int *prev_outpercent);
EINTERN Evas_Object *netstatus_configure(Instance *inst);
#endif
diff --git a/src/modules/sysinfo/netstatus/netstatus_proc.c b/src/modules/sysinfo/netstatus/netstatus_proc.c
index 1659ce471f..1f9376ddff 100644
--- a/src/modules/sysinfo/netstatus/netstatus_proc.c
+++ b/src/modules/sysinfo/netstatus/netstatus_proc.c
@@ -1,15 +1,19 @@
#include "netstatus.h"
void
-_netstatus_proc_getrstatus(Eina_Bool automax,
- unsigned long *prev_in,
- unsigned long *prev_incurrent,
- unsigned long *prev_inmax,
- time_t *last_checked,
- int *prev_inpercent)
+_netstatus_proc_getstatus(Eina_Bool automax,
+ time_t *last_checked,
+ unsigned long *prev_in,
+ unsigned long *prev_incurrent,
+ unsigned long *prev_inmax,
+ int *prev_inpercent,
+ unsigned long *prev_out,
+ unsigned long *prev_outcurrent,
+ unsigned long *prev_outmax,
+ int *prev_outpercent)
{
- unsigned long in, dummy, tot_in = 0;
- unsigned long diffin;
+ unsigned long in, out, dummy, tot_in = 0, tot_out = 0;
+ unsigned long diffin, diffout;
int percent = 0;
char buf[4096], dummys[64];
FILE *f;
@@ -18,10 +22,11 @@ _netstatus_proc_getrstatus(Eina_Bool automax,
if (!*last_checked)
*last_checked = current;
- else if ((current - *last_checked) < 1)
+ if ((current - *last_checked) < 1)
return;
else
diff = current - *last_checked;
+
f = fopen("/proc/net/dev", "r");
if (f)
{
@@ -29,13 +34,15 @@ _netstatus_proc_getrstatus(Eina_Bool automax,
{
if (sscanf(buf, "%s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu "
"%lu %lu %lu %lu\n", dummys, &in, &dummy, &dummy,
- &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy,
+ &dummy, &dummy, &dummy, &dummy, &dummy, &out, &dummy,
&dummy, &dummy, &dummy, &dummy, &dummy, &dummy) < 17)
continue;
tot_in += in;
+ tot_out += out;
}
fclose(f);
}
+
diffin = tot_in - *prev_in;
if (diff > 1)
diffin /= diff;
@@ -57,45 +64,9 @@ _netstatus_proc_getrstatus(Eina_Bool automax,
percent = 0;
*prev_inpercent = percent;
}
- *last_checked = current;
-}
-void
-_netstatus_proc_gettstatus(Eina_Bool automax,
- unsigned long *prev_out,
- unsigned long *prev_outcurrent,
- unsigned long *prev_outmax,
- time_t *last_checked,
- int *prev_outpercent)
-{
- unsigned long out, dummy, tot_out = 0;
- unsigned long diffout;
- int percent = 0;
- char buf[4096], dummys[64];
- FILE *f;
- time_t current = time(NULL);
- time_t diff = 0;
+ percent = 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)
- {
- while (fgets(buf, sizeof(buf), f) != NULL)
- {
- if (sscanf(buf, "%s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu "
- "%lu %lu %lu %lu\n", dummys, &dummy, &dummy, &dummy,
- &dummy, &dummy, &dummy, &dummy, &dummy, &out, &dummy,
- &dummy, &dummy, &dummy, &dummy, &dummy, &dummy) < 17)
- continue;
- tot_out += out;
- }
- fclose(f);
- }
diffout = tot_out - *prev_out;
if (diff > 1)
diffout /= diff;
@@ -111,7 +82,7 @@ _netstatus_proc_gettstatus(Eina_Bool automax,
}
*prev_outcurrent = diffout;
if (*prev_outcurrent > 0)
- percent = 100 * ((float)*prev_outcurrent / (float)*prev_outmax);
+ percent = 100 * ((float)*prev_outcurrent / (float)*prev_outmax);
if (percent > 100) percent = 100;
else if (percent < 0)
percent = 0;
diff --git a/src/modules/sysinfo/netstatus/netstatus_sysctl.c b/src/modules/sysinfo/netstatus/netstatus_sysctl.c
index 7d67760369..9caf2b0c30 100644
--- a/src/modules/sysinfo/netstatus/netstatus_sysctl.c
+++ b/src/modules/sysinfo/netstatus/netstatus_sysctl.c
@@ -107,14 +107,18 @@ _openbsd_generic_network_status(unsigned long int *in, unsigned long int *out)
#endif
void
-_netstatus_sysctl_getrstatus(Eina_Bool automax,
- unsigned long *prev_in,
- unsigned long *prev_incurrent,
- unsigned long *prev_inmax,
- time_t *last_checked,
- int *prev_inpercent)
+_netstatus_sysctl_getstatus(Eina_Bool automax,
+ time_t *last_checked,
+ unsigned long *prev_in,
+ unsigned long *prev_incurrent,
+ unsigned long *prev_inmax,
+ int *prev_inpercent,
+ unsigned long *prev_out,
+ unsigned long *prev_outcurrent,
+ unsigned long *prev_outmax,
+ int *prev_outpercent)
{
- unsigned long tot_in = 0, diffin;
+ unsigned long tot_out = 0, tot_in = 0, diffin, diffout;
int percent = 0;
unsigned long int incoming = 0, outgoing = 0;
time_t current = time(NULL);
@@ -124,14 +128,16 @@ _netstatus_sysctl_getrstatus(Eina_Bool automax,
#elif defined(__FreeBSD__) || defined(__DragonFly__)
_freebsd_generic_network_status(&incoming, &outgoing);
#endif
-
if (!*last_checked)
*last_checked = current;
- else if ((current - *last_checked) < 1)
+ if ((current - *last_checked) < 1)
return;
else
diff = current - *last_checked;
+
tot_in = incoming;
+ tot_out = outgoing;
+
diffin = tot_in - *prev_in;
if (diff > 1)
diffin /= diff;
@@ -153,35 +159,8 @@ _netstatus_sysctl_getrstatus(Eina_Bool automax,
percent = 0;
*prev_inpercent = percent;
}
- *last_checked = current;
-}
-
-void
-_netstatus_sysctl_gettstatus(Eina_Bool automax,
- unsigned long *prev_out,
- unsigned long *prev_outcurrent,
- unsigned long *prev_outmax,
- time_t *last_checked,
- int *prev_outpercent)
-{
- unsigned long tot_out = 0, diffout;
- 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__)
- _freebsd_generic_network_status(&incoming, &outgoing);
-#endif
- tot_out = outgoing;
-
- if (!*last_checked)
- *last_checked = current;
- else if ((current - *last_checked) < 1)
- return;
- else
- diff = current - *last_checked;
+
+ percent = 0;
diffout = tot_out - *prev_out;
if (diff > 1)