diff options
author | Stephen 'Okra' Houston <smhouston88@gmail.com> | 2017-09-08 15:17:52 -0500 |
---|---|---|
committer | Stephen 'Okra' Houston <smhouston88@gmail.com> | 2017-09-08 15:18:23 -0500 |
commit | 7f3e7d933e825567ffe623ca42af8d786b8e149f (patch) | |
tree | 858f9eb2b8d5075f162ad307981a7ce16dbf0a57 | |
parent | 3506f550c7c0455b2ee6a6584a60047e5f2f83f3 (diff) | |
download | enlightenment-7f3e7d933e825567ffe623ca42af8d786b8e149f.tar.gz |
Show netstatus output in bits per second while still polling based on ticks to avoid unnecessary wake ups.
-rw-r--r-- | src/modules/sysinfo/netstatus/netstatus.c | 26 | ||||
-rw-r--r-- | src/modules/sysinfo/netstatus/netstatus.h | 8 | ||||
-rw-r--r-- | src/modules/sysinfo/netstatus/netstatus_proc.c | 14 | ||||
-rw-r--r-- | src/modules/sysinfo/netstatus/netstatus_sysctl.c | 16 |
4 files changed, 48 insertions, 16 deletions
diff --git a/src/modules/sysinfo/netstatus/netstatus.c b/src/modules/sysinfo/netstatus/netstatus.c index 00536fe6e5..0e87854a72 100644 --- a/src/modules/sysinfo/netstatus/netstatus.c +++ b/src/modules/sysinfo/netstatus/netstatus.c @@ -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); diff --git a/src/modules/sysinfo/netstatus/netstatus.h b/src/modules/sysinfo/netstatus/netstatus.h index 257434d56d..87010a04a4 100644 --- a/src/modules/sysinfo/netstatus/netstatus.h +++ b/src/modules/sysinfo/netstatus/netstatus.h @@ -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 diff --git a/src/modules/sysinfo/netstatus/netstatus_proc.c b/src/modules/sysinfo/netstatus/netstatus_proc.c index 5291f85f1d..4258a94920 100644 --- a/src/modules/sysinfo/netstatus/netstatus_proc.c +++ b/src/modules/sysinfo/netstatus/netstatus_proc.c @@ -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; } diff --git a/src/modules/sysinfo/netstatus/netstatus_sysctl.c b/src/modules/sysinfo/netstatus/netstatus_sysctl.c index f5debc0037..007e4e85aa 100644 --- a/src/modules/sysinfo/netstatus/netstatus_sysctl.c +++ b/src/modules/sysinfo/netstatus/netstatus_sysctl.c @@ -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; } |