Update netstatus in/out in the same file read. Fix cpufreq to use powersave again.

This commit is contained in:
Stephen 'Okra' Houston 2017-09-12 12:10:38 -05:00
parent 9eebe065c2
commit 20a96271ca
5 changed files with 65 additions and 99 deletions

View File

@ -1287,8 +1287,17 @@ typedef struct _Thread_Config Thread_Config;
struct _Thread_Config struct _Thread_Config
{ {
int interval; int interval;
E_Powersave_Sleeper *sleeper;
}; };
static void
_cpufreq_cb_frequency_check_done(void *data, Ecore_Thread *th EINA_UNUSED)
{
Thread_Config *thc = data;
e_powersave_sleeper_free(thc->sleeper);
free(thc);
}
static void static void
_cpufreq_cb_frequency_check_main(void *data, Ecore_Thread *th) _cpufreq_cb_frequency_check_main(void *data, Ecore_Thread *th)
{ {
@ -1304,9 +1313,8 @@ _cpufreq_cb_frequency_check_main(void *data, Ecore_Thread *th)
else else
_cpufreq_status_free(status); _cpufreq_status_free(status);
if (ecore_thread_check(th)) break; if (ecore_thread_check(th)) break;
usleep((1000000.0 / 8.0) * (double)thc->interval); e_powersave_sleeper_sleep(thc->sleeper, thc->interval);
} }
free(thc);
} }
static void static void
@ -1380,10 +1388,13 @@ _cpufreq_poll_interval_update(void)
if (thc) if (thc)
{ {
thc->interval = cpufreq_config->poll_interval; thc->interval = cpufreq_config->poll_interval;
thc->sleeper = e_powersave_sleeper_new();
cpufreq_config->frequency_check_thread = cpufreq_config->frequency_check_thread =
ecore_thread_feedback_run(_cpufreq_cb_frequency_check_main, ecore_thread_feedback_run(_cpufreq_cb_frequency_check_main,
_cpufreq_cb_frequency_check_notify, _cpufreq_cb_frequency_check_notify,
NULL, NULL, thc, EINA_TRUE); _cpufreq_cb_frequency_check_done,
_cpufreq_cb_frequency_check_done,
thc, EINA_TRUE);
} }
e_config_save_queue(); e_config_save_queue();
} }

View File

@ -7,14 +7,13 @@ struct _Thread_Config
int interval; int interval;
Instance *inst; Instance *inst;
Eina_Bool automax; Eina_Bool automax;
time_t checktime;
int inpercent; int inpercent;
time_t intime;
unsigned long in; unsigned long in;
unsigned long incurrent; unsigned long incurrent;
unsigned long inmax; unsigned long inmax;
Eina_Stringshare *instring; Eina_Stringshare *instring;
int outpercent; int outpercent;
time_t outtime;
unsigned long out; unsigned long out;
unsigned long outcurrent; unsigned long outcurrent;
unsigned long outmax; unsigned long outmax;
@ -145,11 +144,13 @@ _netstatus_cb_usage_check_main(void *data, Ecore_Thread *th)
if (ecore_thread_check(th)) break; if (ecore_thread_check(th)) break;
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__) #if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__)
_netstatus_sysctl_getrstatus(thc->automax, &thc->in, &thc->incurrent, &thc->inmax, &thc->intime, &thc->inpercent); _netstatus_sysctl_getstatus(thc->automax, &thc->checktime, &thc->in, &thc->incurrent,
_netstatus_sysctl_gettstatus(thc->automax, &thc->out, &thc->outcurrent, &thc->outmax, &thc->outtime, &thc->outpercent); &thc->inmax, &thc->inpercent, &thc->out, &thc->outcurrent, &thc->outmax,
&thc->outpercent);
#else #else
_netstatus_proc_getrstatus(thc->automax, &thc->in, &thc->incurrent, &thc->inmax, &thc->intime, &thc->inpercent); _netstatus_proc_getstatus(thc->automax, &thc->checktime, &thc->in, &thc->incurrent,
_netstatus_proc_gettstatus(thc->automax, &thc->out, &thc->outcurrent, &thc->outmax, &thc->outtime, &thc->outpercent); &thc->inmax, &thc->inpercent, &thc->out, &thc->outcurrent, &thc->outmax,
&thc->outpercent);
#endif #endif
if (!thc->incurrent) if (!thc->incurrent)
{ {

View File

@ -17,9 +17,13 @@ struct _Netstatus_Config
}; };
EINTERN void _netstatus_config_updated(Instance *inst); 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_getstatus(Eina_Bool automax, time_t *last_checked,
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); unsigned long *prev_in, unsigned long *prev_incurrent, unsigned long *prev_inmax,
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); int *prev_inpercent, unsigned long *prev_out, unsigned long *prev_outcurrent,
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); 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); EINTERN Evas_Object *netstatus_configure(Instance *inst);
#endif #endif

View File

@ -1,15 +1,19 @@
#include "netstatus.h" #include "netstatus.h"
void void
_netstatus_proc_getrstatus(Eina_Bool automax, _netstatus_proc_getstatus(Eina_Bool automax,
unsigned long *prev_in, time_t *last_checked,
unsigned long *prev_incurrent, unsigned long *prev_in,
unsigned long *prev_inmax, unsigned long *prev_incurrent,
time_t *last_checked, unsigned long *prev_inmax,
int *prev_inpercent) 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 in, out, dummy, tot_in = 0, tot_out = 0;
unsigned long diffin; unsigned long diffin, diffout;
int percent = 0; int percent = 0;
char buf[4096], dummys[64]; char buf[4096], dummys[64];
FILE *f; FILE *f;
@ -18,10 +22,11 @@ _netstatus_proc_getrstatus(Eina_Bool automax,
if (!*last_checked) if (!*last_checked)
*last_checked = current; *last_checked = current;
else if ((current - *last_checked) < 1) if ((current - *last_checked) < 1)
return; return;
else else
diff = current - *last_checked; diff = current - *last_checked;
f = fopen("/proc/net/dev", "r"); f = fopen("/proc/net/dev", "r");
if (f) 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 " 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, "%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) &dummy, &dummy, &dummy, &dummy, &dummy, &dummy) < 17)
continue; continue;
tot_in += in; tot_in += in;
tot_out += out;
} }
fclose(f); fclose(f);
} }
diffin = tot_in - *prev_in; diffin = tot_in - *prev_in;
if (diff > 1) if (diff > 1)
diffin /= diff; diffin /= diff;
@ -57,45 +64,9 @@ _netstatus_proc_getrstatus(Eina_Bool automax,
percent = 0; percent = 0;
*prev_inpercent = percent; *prev_inpercent = percent;
} }
*last_checked = current;
}
void percent = 0;
_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;
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; diffout = tot_out - *prev_out;
if (diff > 1) if (diff > 1)
diffout /= diff; diffout /= diff;
@ -111,7 +82,7 @@ _netstatus_proc_gettstatus(Eina_Bool automax,
} }
*prev_outcurrent = diffout; *prev_outcurrent = diffout;
if (*prev_outcurrent > 0) 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; if (percent > 100) percent = 100;
else if (percent < 0) else if (percent < 0)
percent = 0; percent = 0;

View File

@ -107,14 +107,18 @@ _openbsd_generic_network_status(unsigned long int *in, unsigned long int *out)
#endif #endif
void void
_netstatus_sysctl_getrstatus(Eina_Bool automax, _netstatus_sysctl_getstatus(Eina_Bool automax,
unsigned long *prev_in, time_t *last_checked,
unsigned long *prev_incurrent, unsigned long *prev_in,
unsigned long *prev_inmax, unsigned long *prev_incurrent,
time_t *last_checked, unsigned long *prev_inmax,
int *prev_inpercent) 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; int percent = 0;
unsigned long int incoming = 0, outgoing = 0; unsigned long int incoming = 0, outgoing = 0;
time_t current = time(NULL); time_t current = time(NULL);
@ -124,14 +128,16 @@ _netstatus_sysctl_getrstatus(Eina_Bool automax,
#elif defined(__FreeBSD__) || defined(__DragonFly__) #elif defined(__FreeBSD__) || defined(__DragonFly__)
_freebsd_generic_network_status(&incoming, &outgoing); _freebsd_generic_network_status(&incoming, &outgoing);
#endif #endif
if (!*last_checked) if (!*last_checked)
*last_checked = current; *last_checked = current;
else if ((current - *last_checked) < 1) if ((current - *last_checked) < 1)
return; return;
else else
diff = current - *last_checked; diff = current - *last_checked;
tot_in = incoming; tot_in = incoming;
tot_out = outgoing;
diffin = tot_in - *prev_in; diffin = tot_in - *prev_in;
if (diff > 1) if (diff > 1)
diffin /= diff; diffin /= diff;
@ -153,35 +159,8 @@ _netstatus_sysctl_getrstatus(Eina_Bool automax,
percent = 0; percent = 0;
*prev_inpercent = percent; *prev_inpercent = percent;
} }
*last_checked = current;
} percent = 0;
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;
diffout = tot_out - *prev_out; diffout = tot_out - *prev_out;
if (diff > 1) if (diff > 1)