summaryrefslogtreecommitdiff
path: root/src/modules
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
parent9eebe065c262e0763649bb9f2dc1b0b9e2d434fe (diff)
Update netstatus in/out in the same file read. Fix cpufreq to use powersave again.
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/cpufreq/e_mod_main.c17
-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
5 files changed, 65 insertions, 99 deletions
diff --git a/src/modules/cpufreq/e_mod_main.c b/src/modules/cpufreq/e_mod_main.c
index e5b6cf5..f4ba259 100644
--- a/src/modules/cpufreq/e_mod_main.c
+++ b/src/modules/cpufreq/e_mod_main.c
@@ -1287,9 +1287,18 @@ typedef struct _Thread_Config Thread_Config;
1287struct _Thread_Config 1287struct _Thread_Config
1288{ 1288{
1289 int interval; 1289 int interval;
1290 E_Powersave_Sleeper *sleeper;
1290}; 1291};
1291 1292
1292static void 1293static void
1294_cpufreq_cb_frequency_check_done(void *data, Ecore_Thread *th EINA_UNUSED)
1295{
1296 Thread_Config *thc = data;
1297 e_powersave_sleeper_free(thc->sleeper);
1298 free(thc);
1299}
1300
1301static void
1293_cpufreq_cb_frequency_check_main(void *data, Ecore_Thread *th) 1302_cpufreq_cb_frequency_check_main(void *data, Ecore_Thread *th)
1294{ 1303{
1295 Thread_Config *thc = data; 1304 Thread_Config *thc = data;
@@ -1304,9 +1313,8 @@ _cpufreq_cb_frequency_check_main(void *data, Ecore_Thread *th)
1304 else 1313 else
1305 _cpufreq_status_free(status); 1314 _cpufreq_status_free(status);
1306 if (ecore_thread_check(th)) break; 1315 if (ecore_thread_check(th)) break;
1307 usleep((1000000.0 / 8.0) * (double)thc->interval); 1316 e_powersave_sleeper_sleep(thc->sleeper, thc->interval);
1308 } 1317 }
1309 free(thc);
1310} 1318}
1311 1319
1312static void 1320static void
@@ -1380,10 +1388,13 @@ _cpufreq_poll_interval_update(void)
1380 if (thc) 1388 if (thc)
1381 { 1389 {
1382 thc->interval = cpufreq_config->poll_interval; 1390 thc->interval = cpufreq_config->poll_interval;
1391 thc->sleeper = e_powersave_sleeper_new();
1383 cpufreq_config->frequency_check_thread = 1392 cpufreq_config->frequency_check_thread =
1384 ecore_thread_feedback_run(_cpufreq_cb_frequency_check_main, 1393 ecore_thread_feedback_run(_cpufreq_cb_frequency_check_main,
1385 _cpufreq_cb_frequency_check_notify, 1394 _cpufreq_cb_frequency_check_notify,
1386 NULL, NULL, thc, EINA_TRUE); 1395 _cpufreq_cb_frequency_check_done,
1396 _cpufreq_cb_frequency_check_done,
1397 thc, EINA_TRUE);
1387 } 1398 }
1388 e_config_save_queue(); 1399 e_config_save_queue();
1389} 1400}
diff --git a/src/modules/sysinfo/netstatus/netstatus.c b/src/modules/sysinfo/netstatus/netstatus.c
index 0e87854..87ea74c 100644
--- a/src/modules/sysinfo/netstatus/netstatus.c
+++ b/src/modules/sysinfo/netstatus/netstatus.c
@@ -7,14 +7,13 @@ struct _Thread_Config
7 int interval; 7 int interval;
8 Instance *inst; 8 Instance *inst;
9 Eina_Bool automax; 9 Eina_Bool automax;
10 time_t checktime;
10 int inpercent; 11 int inpercent;
11 time_t intime;
12 unsigned long in; 12 unsigned long in;
13 unsigned long incurrent; 13 unsigned long incurrent;
14 unsigned long inmax; 14 unsigned long inmax;
15 Eina_Stringshare *instring; 15 Eina_Stringshare *instring;
16 int outpercent; 16 int outpercent;
17 time_t outtime;
18 unsigned long out; 17 unsigned long out;
19 unsigned long outcurrent; 18 unsigned long outcurrent;
20 unsigned long outmax; 19 unsigned long outmax;
@@ -145,11 +144,13 @@ _netstatus_cb_usage_check_main(void *data, Ecore_Thread *th)
145 144
146 if (ecore_thread_check(th)) break; 145 if (ecore_thread_check(th)) break;
147#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__) 146#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__)
148 _netstatus_sysctl_getrstatus(thc->automax, &thc->in, &thc->incurrent, &thc->inmax, &thc->intime, &thc->inpercent); 147 _netstatus_sysctl_getstatus(thc->automax, &thc->checktime, &thc->in, &thc->incurrent,
149 _netstatus_sysctl_gettstatus(thc->automax, &thc->out, &thc->outcurrent, &thc->outmax, &thc->outtime, &thc->outpercent); 148 &thc->inmax, &thc->inpercent, &thc->out, &thc->outcurrent, &thc->outmax,
149 &thc->outpercent);
150#else 150#else
151 _netstatus_proc_getrstatus(thc->automax, &thc->in, &thc->incurrent, &thc->inmax, &thc->intime, &thc->inpercent); 151 _netstatus_proc_getstatus(thc->automax, &thc->checktime, &thc->in, &thc->incurrent,
152 _netstatus_proc_gettstatus(thc->automax, &thc->out, &thc->outcurrent, &thc->outmax, &thc->outtime, &thc->outpercent); 152 &thc->inmax, &thc->inpercent, &thc->out, &thc->outcurrent, &thc->outmax,
153 &thc->outpercent);
153#endif 154#endif
154 if (!thc->incurrent) 155 if (!thc->incurrent)
155 { 156 {
diff --git a/src/modules/sysinfo/netstatus/netstatus.h b/src/modules/sysinfo/netstatus/netstatus.h
index 87010a0..ee1a36f 100644
--- a/src/modules/sysinfo/netstatus/netstatus.h
+++ b/src/modules/sysinfo/netstatus/netstatus.h
@@ -17,9 +17,13 @@ struct _Netstatus_Config
17}; 17};
18 18
19EINTERN void _netstatus_config_updated(Instance *inst); 19EINTERN void _netstatus_config_updated(Instance *inst);
20EINTERN 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); 20EINTERN void _netstatus_proc_getstatus(Eina_Bool automax, time_t *last_checked,
21EINTERN 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); 21 unsigned long *prev_in, unsigned long *prev_incurrent, unsigned long *prev_inmax,
22EINTERN 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); 22 int *prev_inpercent, unsigned long *prev_out, unsigned long *prev_outcurrent,
23EINTERN 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); 23 unsigned long *prev_outmax, int *prev_outpercent);
24EINTERN void _netstatus_sysctl_getstatus(Eina_Bool automax, time_t *last_checked,
25 unsigned long *prev_in, unsigned long *prev_incurrent, unsigned long *prev_inmax,
26 int *prev_inpercent, unsigned long *prev_out, unsigned long *prev_outcurrent,
27 unsigned long *prev_outmax, int *prev_outpercent);
24EINTERN Evas_Object *netstatus_configure(Instance *inst); 28EINTERN Evas_Object *netstatus_configure(Instance *inst);
25#endif 29#endif
diff --git a/src/modules/sysinfo/netstatus/netstatus_proc.c b/src/modules/sysinfo/netstatus/netstatus_proc.c
index 1659ce4..1f9376d 100644
--- a/src/modules/sysinfo/netstatus/netstatus_proc.c
+++ b/src/modules/sysinfo/netstatus/netstatus_proc.c
@@ -1,15 +1,19 @@
1#include "netstatus.h" 1#include "netstatus.h"
2 2
3void 3void
4_netstatus_proc_getrstatus(Eina_Bool automax, 4_netstatus_proc_getstatus(Eina_Bool automax,
5 unsigned long *prev_in, 5 time_t *last_checked,
6 unsigned long *prev_incurrent, 6 unsigned long *prev_in,
7 unsigned long *prev_inmax, 7 unsigned long *prev_incurrent,
8 time_t *last_checked, 8 unsigned long *prev_inmax,
9 int *prev_inpercent) 9 int *prev_inpercent,
10 unsigned long *prev_out,
11 unsigned long *prev_outcurrent,
12 unsigned long *prev_outmax,
13 int *prev_outpercent)
10{ 14{
11 unsigned long in, dummy, tot_in = 0; 15 unsigned long in, out, dummy, tot_in = 0, tot_out = 0;
12 unsigned long diffin; 16 unsigned long diffin, diffout;
13 int percent = 0; 17 int percent = 0;
14 char buf[4096], dummys[64]; 18 char buf[4096], dummys[64];
15 FILE *f; 19 FILE *f;
@@ -18,10 +22,11 @@ _netstatus_proc_getrstatus(Eina_Bool automax,
18 22
19 if (!*last_checked) 23 if (!*last_checked)
20 *last_checked = current; 24 *last_checked = current;
21 else if ((current - *last_checked) < 1) 25 if ((current - *last_checked) < 1)
22 return; 26 return;
23 else 27 else
24 diff = current - *last_checked; 28 diff = current - *last_checked;
29
25 f = fopen("/proc/net/dev", "r"); 30 f = fopen("/proc/net/dev", "r");
26 if (f) 31 if (f)
27 { 32 {
@@ -29,13 +34,15 @@ _netstatus_proc_getrstatus(Eina_Bool automax,
29 { 34 {
30 if (sscanf(buf, "%s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu " 35 if (sscanf(buf, "%s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu "
31 "%lu %lu %lu %lu\n", dummys, &in, &dummy, &dummy, 36 "%lu %lu %lu %lu\n", dummys, &in, &dummy, &dummy,
32 &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, 37 &dummy, &dummy, &dummy, &dummy, &dummy, &out, &dummy,
33 &dummy, &dummy, &dummy, &dummy, &dummy, &dummy) < 17) 38 &dummy, &dummy, &dummy, &dummy, &dummy, &dummy) < 17)
34 continue; 39 continue;
35 tot_in += in; 40 tot_in += in;
41 tot_out += out;
36 } 42 }
37 fclose(f); 43 fclose(f);
38 } 44 }
45
39 diffin = tot_in - *prev_in; 46 diffin = tot_in - *prev_in;
40 if (diff > 1) 47 if (diff > 1)
41 diffin /= diff; 48 diffin /= diff;
@@ -57,45 +64,9 @@ _netstatus_proc_getrstatus(Eina_Bool automax,
57 percent = 0; 64 percent = 0;
58 *prev_inpercent = percent; 65 *prev_inpercent = percent;
59 } 66 }
60 *last_checked = current;
61}
62 67
63void 68 percent = 0;
64_netstatus_proc_gettstatus(Eina_Bool automax,
65 unsigned long *prev_out,
66 unsigned long *prev_outcurrent,
67 unsigned long *prev_outmax,
68 time_t *last_checked,
69 int *prev_outpercent)
70{
71 unsigned long out, dummy, tot_out = 0;
72 unsigned long diffout;
73 int percent = 0;
74 char buf[4096], dummys[64];
75 FILE *f;
76 time_t current = time(NULL);
77 time_t diff = 0;
78 69
79 if (!*last_checked)
80 *last_checked = current;
81 else if ((current - *last_checked) < 1)
82 return;
83 else
84 diff = current - *last_checked;
85 f = fopen("/proc/net/dev", "r");
86 if (f)
87 {
88 while (fgets(buf, sizeof(buf), f) != NULL)
89 {
90 if (sscanf(buf, "%s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu "
91 "%lu %lu %lu %lu\n", dummys, &dummy, &dummy, &dummy,
92 &dummy, &dummy, &dummy, &dummy, &dummy, &out, &dummy,
93 &dummy, &dummy, &dummy, &dummy, &dummy, &dummy) < 17)
94 continue;
95 tot_out += out;
96 }
97 fclose(f);
98 }
99 diffout = tot_out - *prev_out; 70 diffout = tot_out - *prev_out;
100 if (diff > 1) 71 if (diff > 1)
101 diffout /= diff; 72 diffout /= diff;
@@ -111,7 +82,7 @@ _netstatus_proc_gettstatus(Eina_Bool automax,
111 } 82 }
112 *prev_outcurrent = diffout; 83 *prev_outcurrent = diffout;
113 if (*prev_outcurrent > 0) 84 if (*prev_outcurrent > 0)
114 percent = 100 * ((float)*prev_outcurrent / (float)*prev_outmax); 85 percent = 100 * ((float)*prev_outcurrent / (float)*prev_outmax);
115 if (percent > 100) percent = 100; 86 if (percent > 100) percent = 100;
116 else if (percent < 0) 87 else if (percent < 0)
117 percent = 0; 88 percent = 0;
diff --git a/src/modules/sysinfo/netstatus/netstatus_sysctl.c b/src/modules/sysinfo/netstatus/netstatus_sysctl.c
index 7d67760..9caf2b0 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)
107#endif 107#endif
108 108
109void 109void
110_netstatus_sysctl_getrstatus(Eina_Bool automax, 110_netstatus_sysctl_getstatus(Eina_Bool automax,
111 unsigned long *prev_in, 111 time_t *last_checked,
112 unsigned long *prev_incurrent, 112 unsigned long *prev_in,
113 unsigned long *prev_inmax, 113 unsigned long *prev_incurrent,
114 time_t *last_checked, 114 unsigned long *prev_inmax,
115 int *prev_inpercent) 115 int *prev_inpercent,
116 unsigned long *prev_out,
117 unsigned long *prev_outcurrent,
118 unsigned long *prev_outmax,
119 int *prev_outpercent)
116{ 120{
117 unsigned long tot_in = 0, diffin; 121 unsigned long tot_out = 0, tot_in = 0, diffin, diffout;
118 int percent = 0; 122 int percent = 0;
119 unsigned long int incoming = 0, outgoing = 0; 123 unsigned long int incoming = 0, outgoing = 0;
120 time_t current = time(NULL); 124 time_t current = time(NULL);
@@ -124,14 +128,16 @@ _netstatus_sysctl_getrstatus(Eina_Bool automax,
124#elif defined(__FreeBSD__) || defined(__DragonFly__) 128#elif defined(__FreeBSD__) || defined(__DragonFly__)
125 _freebsd_generic_network_status(&incoming, &outgoing); 129 _freebsd_generic_network_status(&incoming, &outgoing);
126#endif 130#endif
127
128 if (!*last_checked) 131 if (!*last_checked)
129 *last_checked = current; 132 *last_checked = current;
130 else if ((current - *last_checked) < 1) 133 if ((current - *last_checked) < 1)
131 return; 134 return;
132 else 135 else
133 diff = current - *last_checked; 136 diff = current - *last_checked;
137
134 tot_in = incoming; 138 tot_in = incoming;
139 tot_out = outgoing;
140
135 diffin = tot_in - *prev_in; 141 diffin = tot_in - *prev_in;
136 if (diff > 1) 142 if (diff > 1)
137 diffin /= diff; 143 diffin /= diff;
@@ -153,35 +159,8 @@ _netstatus_sysctl_getrstatus(Eina_Bool automax,
153 percent = 0; 159 percent = 0;
154 *prev_inpercent = percent; 160 *prev_inpercent = percent;
155 } 161 }
156 *last_checked = current; 162
157} 163 percent = 0;
158
159void
160_netstatus_sysctl_gettstatus(Eina_Bool automax,
161 unsigned long *prev_out,
162 unsigned long *prev_outcurrent,
163 unsigned long *prev_outmax,
164 time_t *last_checked,
165 int *prev_outpercent)
166{
167 unsigned long tot_out = 0, diffout;
168 int percent = 0;
169 unsigned long int incoming = 0, outgoing = 0;
170 time_t current = time(NULL);
171 time_t diff = 0;
172#if defined(__OpenBSD__)
173 _openbsd_generic_network_status(&incoming, &outgoing);
174#elif defined(__FreeBSD__) || defined(__DragonFly__)
175 _freebsd_generic_network_status(&incoming, &outgoing);
176#endif
177 tot_out = outgoing;
178
179 if (!*last_checked)
180 *last_checked = current;
181 else if ((current - *last_checked) < 1)
182 return;
183 else
184 diff = current - *last_checked;
185 164
186 diffout = tot_out - *prev_out; 165 diffout = tot_out - *prev_out;
187 if (diff > 1) 166 if (diff > 1)