forked from enlightenment/enlightenment
Show netstatus output in bits per second while still polling based on ticks to avoid unnecessary wake ups.
This commit is contained in:
parent
3506f550c7
commit
7f3e7d933e
|
@ -8,11 +8,13 @@ struct _Thread_Config
|
|||
Instance *inst;
|
||||
Eina_Bool automax;
|
||||
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;
|
||||
|
@ -143,38 +145,38 @@ _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->inpercent);
|
||||
_netstatus_sysctl_gettstatus(thc->automax, &thc->out, &thc->outcurrent, &thc->outmax, &thc->outpercent);
|
||||
_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);
|
||||
#else
|
||||
_netstatus_proc_getrstatus(thc->automax, &thc->in, &thc->incurrent, &thc->inmax, &thc->inpercent);
|
||||
_netstatus_proc_gettstatus(thc->automax, &thc->out, &thc->outcurrent, &thc->outmax, &thc->outpercent);
|
||||
_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);
|
||||
#endif
|
||||
if (!thc->incurrent)
|
||||
{
|
||||
snprintf(rin, sizeof(rin), "%s: 0 B", _("Receiving"));
|
||||
snprintf(rin, sizeof(rin), "%s: 0 B/s", _("Receiving"));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (thc->incurrent > 1048576)
|
||||
snprintf(rin, sizeof(rin), "%s: %.2f MB", _("Receiving"), ((float)thc->incurrent / 1048576));
|
||||
snprintf(rin, sizeof(rin), "%s: %.2f MB/s", _("Receiving"), ((float)thc->incurrent / 1048576));
|
||||
else if ((thc->incurrent > 1024) && (thc->incurrent < 1048576))
|
||||
snprintf(rin, sizeof(rin), "%s: %lu KB", _("Receiving"), (thc->incurrent / 1024));
|
||||
snprintf(rin, sizeof(rin), "%s: %lu KB/s", _("Receiving"), (thc->incurrent / 1024));
|
||||
else
|
||||
snprintf(rin, sizeof(rin), "%s: %lu B", _("Receiving"), thc->incurrent);
|
||||
snprintf(rin, sizeof(rin), "%s: %lu B/s", _("Receiving"), thc->incurrent);
|
||||
}
|
||||
eina_stringshare_replace(&thc->instring, rin);
|
||||
if (!thc->outcurrent)
|
||||
{
|
||||
snprintf(rout, sizeof(rout), "%s: 0 B", _("Sending"));
|
||||
snprintf(rout, sizeof(rout), "%s: 0 B/s", _("Sending"));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (thc->outcurrent > 1048576)
|
||||
snprintf(rout, sizeof(rout), "%s: %.2f MB", _("Sending"), ((float)thc->outcurrent / 1048576));
|
||||
snprintf(rout, sizeof(rout), "%s: %.2f MB/s", _("Sending"), ((float)thc->outcurrent / 1048576));
|
||||
else if ((thc->outcurrent > 1024) && (thc->outcurrent < 1048576))
|
||||
snprintf(rout, sizeof(rout), "%s: %lu KB", _("Sending"), (thc->outcurrent / 1024));
|
||||
snprintf(rout, sizeof(rout), "%s: %lu KB/s", _("Sending"), (thc->outcurrent / 1024));
|
||||
else
|
||||
snprintf(rout, sizeof(rout), "%s: %lu B", _("Sending"), thc->outcurrent);
|
||||
snprintf(rout, sizeof(rout), "%s: %lu B/s", _("Sending"), thc->outcurrent);
|
||||
}
|
||||
eina_stringshare_replace(&thc->outstring, rout);
|
||||
ecore_thread_feedback(th, NULL);
|
||||
|
|
|
@ -17,9 +17,9 @@ 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, int *prev_inpercent);
|
||||
EINTERN void _netstatus_proc_gettstatus(Eina_Bool automax, unsigned long *prev_out, unsigned long *prev_outcurrent, unsigned long *prev_outmax, int *prev_outpercent);
|
||||
EINTERN void _netstatus_sysctl_getrstatus(Eina_Bool automax, unsigned long *prev_in, unsigned long *prev_incurrent, unsigned long *prev_inmax, int *prev_inpercent);
|
||||
EINTERN void _netstatus_sysctl_gettstatus(Eina_Bool automax, unsigned long *prev_out, unsigned long *prev_outcurrent, unsigned long *prev_outmax, int *prev_outpercent);
|
||||
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 Evas_Object *netstatus_configure(Instance *inst);
|
||||
#endif
|
||||
|
|
|
@ -5,6 +5,7 @@ _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)
|
||||
{
|
||||
unsigned long in, dummy, tot_in = 0;
|
||||
|
@ -12,7 +13,12 @@ _netstatus_proc_getrstatus(Eina_Bool automax,
|
|||
int percent = 0;
|
||||
char buf[4096], dummys[64];
|
||||
FILE *f;
|
||||
time_t current = time(NULL);
|
||||
|
||||
if (!*last_checked)
|
||||
*last_checked = current;
|
||||
else if ((current - *last_checked) < 1)
|
||||
return;
|
||||
f = fopen("/proc/net/dev", "r");
|
||||
if (f)
|
||||
{
|
||||
|
@ -46,6 +52,7 @@ _netstatus_proc_getrstatus(Eina_Bool automax,
|
|||
percent = 0;
|
||||
*prev_inpercent = percent;
|
||||
}
|
||||
*last_checked = current;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -53,6 +60,7 @@ _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;
|
||||
|
@ -60,7 +68,12 @@ _netstatus_proc_gettstatus(Eina_Bool automax,
|
|||
int percent = 0;
|
||||
char buf[4096], dummys[64];
|
||||
FILE *f;
|
||||
time_t current = time(NULL);
|
||||
|
||||
if (!*last_checked)
|
||||
*last_checked = current;
|
||||
else if ((current - *last_checked) < 1)
|
||||
return;
|
||||
f = fopen("/proc/net/dev", "r");
|
||||
if (f)
|
||||
{
|
||||
|
@ -94,5 +107,6 @@ _netstatus_proc_gettstatus(Eina_Bool automax,
|
|||
percent = 0;
|
||||
*prev_outpercent = percent;
|
||||
}
|
||||
*last_checked = current;
|
||||
}
|
||||
|
||||
|
|
|
@ -111,17 +111,24 @@ _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)
|
||||
{
|
||||
unsigned long tot_in = 0, diffin;
|
||||
int percent = 0;
|
||||
unsigned long int incoming = 0, outgoing = 0;
|
||||
time_t current = time(NULL);
|
||||
#if defined(__OpenBSD__)
|
||||
_openbsd_generic_network_status(&incoming, &outgoing);
|
||||
#elif defined(__FreeBSD__) || defined(__DragonFly__)
|
||||
_freebsd_generic_network_status(&incoming, &outgoing);
|
||||
#endif
|
||||
|
||||
if (!*last_checked)
|
||||
*last_checked = current;
|
||||
else if ((current - *last_checked) < 1)
|
||||
return;
|
||||
|
||||
tot_in = incoming;
|
||||
diffin = tot_in - *prev_in;
|
||||
if (!*prev_in)
|
||||
|
@ -142,6 +149,7 @@ _netstatus_sysctl_getrstatus(Eina_Bool automax,
|
|||
percent = 0;
|
||||
*prev_inpercent = percent;
|
||||
}
|
||||
*last_checked = current;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -149,11 +157,13 @@ _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);
|
||||
#if defined(__OpenBSD__)
|
||||
_openbsd_generic_network_status(&incoming, &outgoing);
|
||||
#elif defined(__FreeBSD__) || defined(__DragonFly__)
|
||||
|
@ -161,6 +171,11 @@ _netstatus_sysctl_gettstatus(Eina_Bool automax,
|
|||
#endif
|
||||
tot_out = outgoing;
|
||||
|
||||
if (!*last_checked)
|
||||
*last_checked = current;
|
||||
else if ((current - *last_checked) < 1)
|
||||
return;
|
||||
|
||||
diffout = tot_out - *prev_out;
|
||||
if (!*prev_out)
|
||||
*prev_out = tot_out;
|
||||
|
@ -180,5 +195,6 @@ _netstatus_sysctl_gettstatus(Eina_Bool automax,
|
|||
percent = 0;
|
||||
*prev_outpercent = percent;
|
||||
}
|
||||
*last_checked = current;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue