aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2005-07-09 15:23:36 +0000
committerChristian Grothoff <christian@grothoff.org>2005-07-09 15:23:36 +0000
commit14583621c352eb11fbd4f398bf6107c744cfc6f8 (patch)
tree1094abe26560d03cd1a0947effd61bf1075d19fd
parentdfb5908f8c6dc473128cb08600454bacfd9a1520 (diff)
downloadgnunet-gtk-14583621c352eb11fbd4f398bf6107c744cfc6f8.tar.gz
gnunet-gtk-14583621c352eb11fbd4f398bf6107c744cfc6f8.zip
optimizations
-rw-r--r--src/plugins/stats/functions.c99
1 files changed, 61 insertions, 38 deletions
diff --git a/src/plugins/stats/functions.c b/src/plugins/stats/functions.c
index 1a325082..6e1c84c0 100644
--- a/src/plugins/stats/functions.c
+++ b/src/plugins/stats/functions.c
@@ -36,6 +36,12 @@ static GNUNET_TCP_SOCKET * sock;
36 36
37static Mutex lock; 37static Mutex lock;
38 38
39static long connectionGoal;
40
41static long long banddown;
42
43static long long bandup;
44
39static int getStatValue(long long * value, 45static int getStatValue(long long * value,
40 long long * lvalue, 46 long long * lvalue,
41 cron_t * dtime, 47 cron_t * dtime,
@@ -64,28 +70,53 @@ static int getStatValue(long long * value,
64 return SYSERR; 70 return SYSERR;
65} 71}
66 72
67static int getConnectedNodesStat(const void * closure, 73static void updateConnectionGoal(void * unused) {
68 gfloat ** data) {
69 long long val;
70 char * cmh; 74 char * cmh;
71 long cval; 75 char * availableDown;
76 char * availableUp;
72 77
73 MUTEX_LOCK(&lock); 78 MUTEX_LOCK(&lock);
74 cmh = getConfigurationOptionValue(sock, 79 cmh = getConfigurationOptionValue(sock,
75 "gnunetd", 80 "gnunetd",
76 "connection-max-hosts"); 81 "connection-max-hosts");
82 availableDown = getConfigurationOptionValue(sock,
83 "LOAD",
84 "MAXNETDOWNBPSTOTAL");
85 availableUp = getConfigurationOptionValue(sock,
86 "LOAD",
87 "MAXNETUPBPSTOTAL");
77 MUTEX_UNLOCK(&lock); 88 MUTEX_UNLOCK(&lock);
78 if (cmh == NULL) 89 if (cmh == NULL)
90 connectionGoal = 0;
91 else
92 connectionGoal = atol(cmh);
93 if (availableDown == NULL)
94 banddown = 0;
95 else
96 banddown = atol(availableDown);
97 if (availableUp == NULL)
98 bandup = 0;
99 else
100 bandup = atol(availableUp);
101
102 FREENONNULL(cmh);
103 FREENONNULL(availableDown);
104 FREENONNULL(availableUp);
105}
106
107static int getConnectedNodesStat(const void * closure,
108 gfloat ** data) {
109 long long val;
110
111 if (connectionGoal == 0)
79 return SYSERR; 112 return SYSERR;
80 cval = atol(cmh);
81 FREE(cmh);
82 if (OK != getStatValue(&val, 113 if (OK != getStatValue(&val,
83 NULL, 114 NULL,
84 NULL, 115 NULL,
85 dgettext("GNUnet", 116 dgettext("GNUnet",
86 "# of connected peers"))) 117 "# of connected peers")))
87 return SYSERR; 118 return SYSERR;
88 data[0][0] = 0.8 * val / cval; 119 data[0][0] = 0.8 * val / connectionGoal;
89 return OK; 120 return OK;
90} 121}
91 122
@@ -113,9 +144,7 @@ static int getTrafficRecvStats(const void * closure,
113 long long lnoise; 144 long long lnoise;
114 long long lcontent; 145 long long lcontent;
115 long long lqueries; 146 long long lqueries;
116 long long band;
117 cron_t dtime; 147 cron_t dtime;
118 char * available;
119 char * buffer; 148 char * buffer;
120 int i; 149 int i;
121 150
@@ -159,30 +188,24 @@ static int getTrafficRecvStats(const void * closure,
159 lqueries = 0; 188 lqueries = 0;
160 } 189 }
161 FREE(buffer); 190 FREE(buffer);
162 MUTEX_LOCK(&lock); 191 if (banddown == 0)
163 available = getConfigurationOptionValue(sock,
164 "LOAD",
165 "MAXNETDOWNBPSTOTAL");
166 MUTEX_UNLOCK(&lock);
167 if (available == NULL)
168 return SYSERR; 192 return SYSERR;
169 band = atol(available) * dtime / cronSECONDS; 193
170 FREE(available);
171 total -= ltotal; 194 total -= ltotal;
172 noise -= lnoise; 195 noise -= lnoise;
173 queries -= lqueries; 196 queries -= lqueries;
174 content -= lcontent; 197 content -= lcontent;
175 if (band <= 0) { 198 if (banddown < 0) {
176 data[0][0] = 0.0; 199 data[0][0] = 0.0;
177 data[0][1] = 0.0; 200 data[0][1] = 0.0;
178 data[0][2] = 0.0; 201 data[0][2] = 0.0;
179 data[0][3] = 0.0; 202 data[0][3] = 0.0;
180 return OK; 203 return OK;
181 } 204 }
182 data[0][0] = 0.8 * noise / band; /* red */ 205 data[0][0] = 0.8 * noise / (banddown * dtime / cronSECONDS); /* red */
183 data[0][1] = 0.8 * (content+noise) / band; /* green */ 206 data[0][1] = 0.8 * (content+noise) / (banddown * dtime / cronSECONDS); /* green */
184 data[0][2] = 0.8 * (queries+content+noise) / band; /* yellow */ 207 data[0][2] = 0.8 * (queries+content+noise) / (banddown * dtime / cronSECONDS); /* yellow */
185 data[0][3] = 0.8 * total / band; /* blue */ 208 data[0][3] = 0.8 * total / (banddown * dtime / cronSECONDS); /* blue */
186 /*printf("I: %f %f %f\n", 209 /*printf("I: %f %f %f\n",
187 data[0][0], 210 data[0][0],
188 data[0][1], 211 data[0][1],
@@ -201,9 +224,7 @@ static int getTrafficSendStats(const void * closure,
201 long long lnoise; 224 long long lnoise;
202 long long lcontent; 225 long long lcontent;
203 long long lqueries; 226 long long lqueries;
204 long long band;
205 cron_t dtime; 227 cron_t dtime;
206 char * available;
207 char * buffer; 228 char * buffer;
208 int i; 229 int i;
209 230
@@ -247,30 +268,23 @@ static int getTrafficSendStats(const void * closure,
247 lqueries = 0; 268 lqueries = 0;
248 } 269 }
249 FREE(buffer); 270 FREE(buffer);
250 MUTEX_LOCK(&lock); 271 if (bandup == 0)
251 available = getConfigurationOptionValue(sock,
252 "LOAD",
253 "MAXNETUPBPSTOTAL");
254 MUTEX_UNLOCK(&lock);
255 if (available == NULL)
256 return SYSERR; 272 return SYSERR;
257 band = atol(available) * dtime / cronSECONDS;
258 FREE(available);
259 total -= ltotal; 273 total -= ltotal;
260 noise -= lnoise; 274 noise -= lnoise;
261 queries -= lqueries; 275 queries -= lqueries;
262 content -= lcontent; 276 content -= lcontent;
263 if (band <= 0) { 277 if (bandup < 0) {
264 data[0][0] = 0.0; 278 data[0][0] = 0.0;
265 data[0][1] = 0.0; 279 data[0][1] = 0.0;
266 data[0][2] = 0.0; 280 data[0][2] = 0.0;
267 data[0][3] = 0.0; 281 data[0][3] = 0.0;
268 return OK; 282 return OK;
269 } 283 }
270 data[0][0] = 0.8 * noise / band; /* red */ 284 data[0][0] = 0.8 * noise / (bandup * dtime / cronSECONDS); /* red */
271 data[0][1] = 0.8 * (noise + content) / band; /* green */ 285 data[0][1] = 0.8 * (noise + content) / (bandup*dtime / cronSECONDS); /* green */
272 data[0][2] = 0.8 * (noise + content + queries) / band; /* yellow */ 286 data[0][2] = 0.8 * (noise + content + queries) / (bandup*dtime / cronSECONDS); /* yellow */
273 data[0][3] = 0.8 * total / band; /* yellow */ 287 data[0][3] = 0.8 * total / (bandup*dtime / cronSECONDS); /* yellow */
274 /* printf("O: %f %f %f\n", 288 /* printf("O: %f %f %f\n",
275 data[0][0], 289 data[0][0],
276 data[0][1], 290 data[0][1],
@@ -380,13 +394,22 @@ void init_functions() {
380 UPDATE_INTERVAL = 30 * cronSECONDS; 394 UPDATE_INTERVAL = 30 * cronSECONDS;
381 sock = getClientSocket(); 395 sock = getClientSocket();
382 MUTEX_CREATE(&lock); 396 MUTEX_CREATE(&lock);
397 updateStatValues(NULL);
398 updateConnectionGoal(NULL);
383 addCronJob(&updateStatValues, 399 addCronJob(&updateStatValues,
384 UPDATE_INTERVAL, 400 UPDATE_INTERVAL,
385 UPDATE_INTERVAL, 401 UPDATE_INTERVAL,
386 NULL); 402 NULL);
403 addCronJob(&updateConnectionGoal,
404 5 * cronMINUTES,
405 5 * cronMINUTES,
406 NULL);
387} 407}
388 408
389void done_functions() { 409void done_functions() {
410 delCronJob(&updateConnectionGoal,
411 5 * cronMINUTES,
412 NULL);
390 delCronJob(&updateStatValues, 413 delCronJob(&updateStatValues,
391 UPDATE_INTERVAL, 414 UPDATE_INTERVAL,
392 NULL); 415 NULL);