diff options
Diffstat (limited to 'src/gns/gnunet-gns-benchmark.c')
-rw-r--r-- | src/gns/gnunet-gns-benchmark.c | 540 |
1 files changed, 268 insertions, 272 deletions
diff --git a/src/gns/gnunet-gns-benchmark.c b/src/gns/gnunet-gns-benchmark.c index 77066fd3f..b64201f10 100644 --- a/src/gns/gnunet-gns-benchmark.c +++ b/src/gns/gnunet-gns-benchmark.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file src/gns/gnunet-gns-benchmark.c | 21 | * @file src/gns/gnunet-gns-benchmark.c |
22 | * @brief issue many queries to GNS and compute performance statistics | 22 | * @brief issue many queries to GNS and compute performance statistics |
@@ -31,12 +31,12 @@ | |||
31 | /** | 31 | /** |
32 | * How long do we wait at least between requests by default? | 32 | * How long do we wait at least between requests by default? |
33 | */ | 33 | */ |
34 | #define DEF_REQUEST_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 1) | 34 | #define DEF_REQUEST_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 1) |
35 | 35 | ||
36 | /** | 36 | /** |
37 | * How long do we wait until we consider a request failed by default? | 37 | * How long do we wait until we consider a request failed by default? |
38 | */ | 38 | */ |
39 | #define DEF_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1) | 39 | #define DEF_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 1) |
40 | 40 | ||
41 | 41 | ||
42 | /** | 42 | /** |
@@ -45,8 +45,7 @@ | |||
45 | * However, this process does not change how it acts | 45 | * However, this process does not change how it acts |
46 | * based on the category. | 46 | * based on the category. |
47 | */ | 47 | */ |
48 | enum RequestCategory | 48 | enum RequestCategory { |
49 | { | ||
50 | RC_SHARED = 0, | 49 | RC_SHARED = 0, |
51 | RC_PRIVATE = 1, | 50 | RC_PRIVATE = 1, |
52 | /** | 51 | /** |
@@ -61,9 +60,7 @@ enum RequestCategory | |||
61 | * thus optimizing it is crucial for the overall memory consumption of | 60 | * thus optimizing it is crucial for the overall memory consumption of |
62 | * the zone importer. | 61 | * the zone importer. |
63 | */ | 62 | */ |
64 | struct Request | 63 | struct Request { |
65 | { | ||
66 | |||
67 | /** | 64 | /** |
68 | * Active requests are kept in a DLL. | 65 | * Active requests are kept in a DLL. |
69 | */ | 66 | */ |
@@ -101,7 +98,6 @@ struct Request | |||
101 | * Category of the request. | 98 | * Category of the request. |
102 | */ | 99 | */ |
103 | enum RequestCategory cat; | 100 | enum RequestCategory cat; |
104 | |||
105 | }; | 101 | }; |
106 | 102 | ||
107 | 103 | ||
@@ -192,11 +188,11 @@ static int g2d; | |||
192 | * @param req request to free | 188 | * @param req request to free |
193 | */ | 189 | */ |
194 | static void | 190 | static void |
195 | free_request (struct Request *req) | 191 | free_request(struct Request *req) |
196 | { | 192 | { |
197 | if (NULL != req->lr) | 193 | if (NULL != req->lr) |
198 | GNUNET_GNS_lookup_with_tld_cancel (req->lr); | 194 | GNUNET_GNS_lookup_with_tld_cancel(req->lr); |
199 | GNUNET_free (req); | 195 | GNUNET_free(req); |
200 | } | 196 | } |
201 | 197 | ||
202 | 198 | ||
@@ -209,32 +205,32 @@ free_request (struct Request *req) | |||
209 | * @param rd the records in reply | 205 | * @param rd the records in reply |
210 | */ | 206 | */ |
211 | static void | 207 | static void |
212 | process_result (void *cls, | 208 | process_result(void *cls, |
213 | int gns_tld, | 209 | int gns_tld, |
214 | uint32_t rd_count, | 210 | uint32_t rd_count, |
215 | const struct GNUNET_GNSRECORD_Data *rd) | 211 | const struct GNUNET_GNSRECORD_Data *rd) |
216 | { | 212 | { |
217 | struct Request *req = cls; | 213 | struct Request *req = cls; |
218 | 214 | ||
219 | (void) gns_tld; | 215 | (void)gns_tld; |
220 | (void) rd_count; | 216 | (void)rd_count; |
221 | (void) rd; | 217 | (void)rd; |
222 | active_cnt--; | 218 | active_cnt--; |
223 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 219 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
224 | "Got response for request `%s'\n", | 220 | "Got response for request `%s'\n", |
225 | req->hostname); | 221 | req->hostname); |
226 | req->lr = NULL; | 222 | req->lr = NULL; |
227 | req->latency = GNUNET_TIME_absolute_get_duration (req->op_start_time); | 223 | req->latency = GNUNET_TIME_absolute_get_duration(req->op_start_time); |
228 | GNUNET_CONTAINER_DLL_remove (act_head, | 224 | GNUNET_CONTAINER_DLL_remove(act_head, |
229 | act_tail, | 225 | act_tail, |
230 | req); | 226 | req); |
231 | GNUNET_CONTAINER_DLL_insert (succ_head, | 227 | GNUNET_CONTAINER_DLL_insert(succ_head, |
232 | succ_tail, | 228 | succ_tail, |
233 | req); | 229 | req); |
234 | replies[req->cat]++; | 230 | replies[req->cat]++; |
235 | latency_sum[req->cat] | 231 | latency_sum[req->cat] |
236 | = GNUNET_TIME_relative_add (latency_sum[req->cat], | 232 | = GNUNET_TIME_relative_add(latency_sum[req->cat], |
237 | req->latency); | 233 | req->latency); |
238 | } | 234 | } |
239 | 235 | ||
240 | 236 | ||
@@ -244,69 +240,69 @@ process_result (void *cls, | |||
244 | * @param cls NULL | 240 | * @param cls NULL |
245 | */ | 241 | */ |
246 | static void | 242 | static void |
247 | process_queue (void *cls) | 243 | process_queue(void *cls) |
248 | { | 244 | { |
249 | struct Request *req; | 245 | struct Request *req; |
250 | struct GNUNET_TIME_Relative duration; | 246 | struct GNUNET_TIME_Relative duration; |
251 | 247 | ||
252 | (void) cls; | 248 | (void)cls; |
253 | t = NULL; | 249 | t = NULL; |
254 | /* check for expired requests */ | 250 | /* check for expired requests */ |
255 | while (NULL != (req = act_head)) | 251 | while (NULL != (req = act_head)) |
256 | { | 252 | { |
257 | duration = GNUNET_TIME_absolute_get_duration (req->op_start_time); | 253 | duration = GNUNET_TIME_absolute_get_duration(req->op_start_time); |
258 | if (duration.rel_value_us < timeout.rel_value_us) | 254 | if (duration.rel_value_us < timeout.rel_value_us) |
259 | break; | 255 | break; |
260 | GNUNET_CONTAINER_DLL_remove (act_head, | 256 | GNUNET_CONTAINER_DLL_remove(act_head, |
261 | act_tail, | 257 | act_tail, |
262 | req); | 258 | req); |
263 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 259 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
264 | "Failing request `%s' due to timeout\n", | 260 | "Failing request `%s' due to timeout\n", |
265 | req->hostname); | 261 | req->hostname); |
266 | failures[req->cat]++; | 262 | failures[req->cat]++; |
267 | active_cnt--; | 263 | active_cnt--; |
268 | free_request (req); | 264 | free_request(req); |
269 | } | 265 | } |
270 | if (NULL == (req = todo_head)) | 266 | if (NULL == (req = todo_head)) |
271 | { | ||
272 | struct GNUNET_TIME_Absolute at; | ||
273 | |||
274 | if (NULL == (req = act_head)) | ||
275 | { | 267 | { |
276 | GNUNET_SCHEDULER_shutdown (); | 268 | struct GNUNET_TIME_Absolute at; |
269 | |||
270 | if (NULL == (req = act_head)) | ||
271 | { | ||
272 | GNUNET_SCHEDULER_shutdown(); | ||
273 | return; | ||
274 | } | ||
275 | at = GNUNET_TIME_absolute_add(req->op_start_time, | ||
276 | timeout); | ||
277 | t = GNUNET_SCHEDULER_add_at(at, | ||
278 | &process_queue, | ||
279 | NULL); | ||
277 | return; | 280 | return; |
278 | } | 281 | } |
279 | at = GNUNET_TIME_absolute_add (req->op_start_time, | 282 | GNUNET_CONTAINER_DLL_remove(todo_head, |
280 | timeout); | 283 | todo_tail, |
281 | t = GNUNET_SCHEDULER_add_at (at, | 284 | req); |
282 | &process_queue, | 285 | GNUNET_CONTAINER_DLL_insert_tail(act_head, |
283 | NULL); | 286 | act_tail, |
284 | return; | 287 | req); |
285 | } | ||
286 | GNUNET_CONTAINER_DLL_remove (todo_head, | ||
287 | todo_tail, | ||
288 | req); | ||
289 | GNUNET_CONTAINER_DLL_insert_tail (act_head, | ||
290 | act_tail, | ||
291 | req); | ||
292 | lookups[req->cat]++; | 288 | lookups[req->cat]++; |
293 | active_cnt++; | 289 | active_cnt++; |
294 | req->op_start_time = GNUNET_TIME_absolute_get (); | 290 | req->op_start_time = GNUNET_TIME_absolute_get(); |
295 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 291 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
296 | "Starting request `%s' (%u in parallel)\n", | 292 | "Starting request `%s' (%u in parallel)\n", |
297 | req->hostname, | 293 | req->hostname, |
298 | active_cnt); | 294 | active_cnt); |
299 | req->lr = GNUNET_GNS_lookup_with_tld (gns, | 295 | req->lr = GNUNET_GNS_lookup_with_tld(gns, |
300 | req->hostname, | 296 | req->hostname, |
301 | g2d | 297 | g2d |
302 | ? GNUNET_GNSRECORD_TYPE_GNS2DNS | 298 | ? GNUNET_GNSRECORD_TYPE_GNS2DNS |
303 | : GNUNET_GNSRECORD_TYPE_ANY, | 299 | : GNUNET_GNSRECORD_TYPE_ANY, |
304 | GNUNET_GNS_LO_DEFAULT, | 300 | GNUNET_GNS_LO_DEFAULT, |
305 | &process_result, | 301 | &process_result, |
306 | req); | 302 | req); |
307 | t = GNUNET_SCHEDULER_add_delayed (request_delay, | 303 | t = GNUNET_SCHEDULER_add_delayed(request_delay, |
308 | &process_queue, | 304 | &process_queue, |
309 | NULL); | 305 | NULL); |
310 | } | 306 | } |
311 | 307 | ||
312 | 308 | ||
@@ -318,11 +314,11 @@ process_queue (void *cls) | |||
318 | * @return -1 if c1<c2, 1 if c1>c2, 0 if c1==c2. | 314 | * @return -1 if c1<c2, 1 if c1>c2, 0 if c1==c2. |
319 | */ | 315 | */ |
320 | static int | 316 | static int |
321 | compare_req (const void *c1, | 317 | compare_req(const void *c1, |
322 | const void *c2) | 318 | const void *c2) |
323 | { | 319 | { |
324 | const struct Request *r1 = *(void **) c1; | 320 | const struct Request *r1 = *(void **)c1; |
325 | const struct Request *r2 = *(void **) c2; | 321 | const struct Request *r2 = *(void **)c2; |
326 | 322 | ||
327 | if (r1->latency.rel_value_us < r2->latency.rel_value_us) | 323 | if (r1->latency.rel_value_us < r2->latency.rel_value_us) |
328 | return -1; | 324 | return -1; |
@@ -338,101 +334,101 @@ compare_req (const void *c1, | |||
338 | * @param cls NULL | 334 | * @param cls NULL |
339 | */ | 335 | */ |
340 | static void | 336 | static void |
341 | do_shutdown (void *cls) | 337 | do_shutdown(void *cls) |
342 | { | 338 | { |
343 | struct Request *req; | 339 | struct Request *req; |
344 | struct Request **ra[RC_MAX]; | 340 | struct Request **ra[RC_MAX]; |
345 | unsigned int rp[RC_MAX]; | 341 | unsigned int rp[RC_MAX]; |
346 | 342 | ||
347 | (void) cls; | 343 | (void)cls; |
348 | for (enum RequestCategory rc = 0;rc < RC_MAX;rc++) | 344 | for (enum RequestCategory rc = 0; rc < RC_MAX; rc++) |
349 | { | 345 | { |
350 | ra[rc] = GNUNET_new_array (replies[rc], | 346 | ra[rc] = GNUNET_new_array(replies[rc], |
351 | struct Request *); | 347 | struct Request *); |
352 | rp[rc] = 0; | 348 | rp[rc] = 0; |
353 | } | 349 | } |
354 | for (req = succ_head;NULL != req; req = req->next) | 350 | for (req = succ_head; NULL != req; req = req->next) |
355 | { | 351 | { |
356 | GNUNET_assert (rp[req->cat] < replies[req->cat]); | 352 | GNUNET_assert(rp[req->cat] < replies[req->cat]); |
357 | ra[req->cat][rp[req->cat]++] = req; | 353 | ra[req->cat][rp[req->cat]++] = req; |
358 | } | 354 | } |
359 | for (enum RequestCategory rc = 0;rc < RC_MAX;rc++) | 355 | for (enum RequestCategory rc = 0; rc < RC_MAX; rc++) |
360 | { | 356 | { |
361 | unsigned int off; | 357 | unsigned int off; |
362 | 358 | ||
363 | fprintf (stdout, | 359 | fprintf(stdout, |
364 | "Category %u\n", | 360 | "Category %u\n", |
365 | rc); | 361 | rc); |
366 | fprintf (stdout, | 362 | fprintf(stdout, |
367 | "\tlookups: %u replies: %u failures: %u\n", | 363 | "\tlookups: %u replies: %u failures: %u\n", |
368 | lookups[rc], | 364 | lookups[rc], |
369 | replies[rc], | 365 | replies[rc], |
370 | failures[rc]); | 366 | failures[rc]); |
371 | if (0 == rp[rc]) | 367 | if (0 == rp[rc]) |
372 | continue; | 368 | continue; |
373 | qsort (ra[rc], | 369 | qsort(ra[rc], |
374 | rp[rc], | 370 | rp[rc], |
375 | sizeof (struct Request *), | 371 | sizeof(struct Request *), |
376 | &compare_req); | 372 | &compare_req); |
377 | latency_sum[rc] = GNUNET_TIME_relative_divide (latency_sum[rc], | 373 | latency_sum[rc] = GNUNET_TIME_relative_divide(latency_sum[rc], |
378 | replies[rc]); | 374 | replies[rc]); |
379 | fprintf (stdout, | 375 | fprintf(stdout, |
380 | "\taverage: %s\n", | 376 | "\taverage: %s\n", |
381 | GNUNET_STRINGS_relative_time_to_string (latency_sum[rc], | 377 | GNUNET_STRINGS_relative_time_to_string(latency_sum[rc], |
382 | GNUNET_YES)); | 378 | GNUNET_YES)); |
383 | off = rp[rc] * 50 / 100; | 379 | off = rp[rc] * 50 / 100; |
384 | fprintf (stdout, | 380 | fprintf(stdout, |
385 | "\tmedian(50): %s\n", | 381 | "\tmedian(50): %s\n", |
386 | GNUNET_STRINGS_relative_time_to_string (ra[rc][off]->latency, | 382 | GNUNET_STRINGS_relative_time_to_string(ra[rc][off]->latency, |
387 | GNUNET_YES)); | 383 | GNUNET_YES)); |
388 | off = rp[rc] * 75 / 100; | 384 | off = rp[rc] * 75 / 100; |
389 | fprintf (stdout, | 385 | fprintf(stdout, |
390 | "\tquantile(75): %s\n", | 386 | "\tquantile(75): %s\n", |
391 | GNUNET_STRINGS_relative_time_to_string (ra[rc][off]->latency, | 387 | GNUNET_STRINGS_relative_time_to_string(ra[rc][off]->latency, |
392 | GNUNET_YES)); | 388 | GNUNET_YES)); |
393 | off = rp[rc] * 90 / 100; | 389 | off = rp[rc] * 90 / 100; |
394 | fprintf (stdout, | 390 | fprintf(stdout, |
395 | "\tquantile(90): %s\n", | 391 | "\tquantile(90): %s\n", |
396 | GNUNET_STRINGS_relative_time_to_string (ra[rc][off]->latency, | 392 | GNUNET_STRINGS_relative_time_to_string(ra[rc][off]->latency, |
397 | GNUNET_YES)); | 393 | GNUNET_YES)); |
398 | off = rp[rc] * 99 / 100; | 394 | off = rp[rc] * 99 / 100; |
399 | fprintf (stdout, | 395 | fprintf(stdout, |
400 | "\tquantile(99): %s\n", | 396 | "\tquantile(99): %s\n", |
401 | GNUNET_STRINGS_relative_time_to_string (ra[rc][off]->latency, | 397 | GNUNET_STRINGS_relative_time_to_string(ra[rc][off]->latency, |
402 | GNUNET_YES)); | 398 | GNUNET_YES)); |
403 | GNUNET_free (ra[rc]); | 399 | GNUNET_free(ra[rc]); |
404 | } | 400 | } |
405 | if (NULL != t) | 401 | if (NULL != t) |
406 | { | 402 | { |
407 | GNUNET_SCHEDULER_cancel (t); | 403 | GNUNET_SCHEDULER_cancel(t); |
408 | t = NULL; | 404 | t = NULL; |
409 | } | 405 | } |
410 | while (NULL != (req = act_head)) | 406 | while (NULL != (req = act_head)) |
411 | { | 407 | { |
412 | GNUNET_CONTAINER_DLL_remove (act_head, | 408 | GNUNET_CONTAINER_DLL_remove(act_head, |
413 | act_tail, | 409 | act_tail, |
414 | req); | 410 | req); |
415 | free_request (req); | 411 | free_request(req); |
416 | } | 412 | } |
417 | while (NULL != (req = succ_head)) | 413 | while (NULL != (req = succ_head)) |
418 | { | 414 | { |
419 | GNUNET_CONTAINER_DLL_remove (succ_head, | 415 | GNUNET_CONTAINER_DLL_remove(succ_head, |
420 | succ_tail, | 416 | succ_tail, |
421 | req); | 417 | req); |
422 | free_request (req); | 418 | free_request(req); |
423 | } | 419 | } |
424 | while (NULL != (req = todo_head)) | 420 | while (NULL != (req = todo_head)) |
425 | { | 421 | { |
426 | GNUNET_CONTAINER_DLL_remove (todo_head, | 422 | GNUNET_CONTAINER_DLL_remove(todo_head, |
427 | todo_tail, | 423 | todo_tail, |
428 | req); | 424 | req); |
429 | free_request (req); | 425 | free_request(req); |
430 | } | 426 | } |
431 | if (NULL != gns) | 427 | if (NULL != gns) |
432 | { | 428 | { |
433 | GNUNET_GNS_disconnect (gns); | 429 | GNUNET_GNS_disconnect(gns); |
434 | gns = NULL; | 430 | gns = NULL; |
435 | } | 431 | } |
436 | } | 432 | } |
437 | 433 | ||
438 | 434 | ||
@@ -443,32 +439,32 @@ do_shutdown (void *cls) | |||
443 | * @param cat category of the @a hostname | 439 | * @param cat category of the @a hostname |
444 | */ | 440 | */ |
445 | static void | 441 | static void |
446 | queue (const char *hostname, | 442 | queue(const char *hostname, |
447 | enum RequestCategory cat) | 443 | enum RequestCategory cat) |
448 | { | 444 | { |
449 | struct Request *req; | 445 | struct Request *req; |
450 | const char *dot; | 446 | const char *dot; |
451 | size_t hlen; | 447 | size_t hlen; |
452 | 448 | ||
453 | dot = strchr (hostname, | 449 | dot = strchr(hostname, |
454 | (unsigned char) '.'); | 450 | (unsigned char)'.'); |
455 | if (NULL == dot) | 451 | if (NULL == dot) |
456 | { | 452 | { |
457 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 453 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
458 | "Refusing invalid hostname `%s' (lacks '.')\n", | 454 | "Refusing invalid hostname `%s' (lacks '.')\n", |
459 | hostname); | 455 | hostname); |
460 | return; | 456 | return; |
461 | } | 457 | } |
462 | hlen = strlen (hostname) + 1; | 458 | hlen = strlen(hostname) + 1; |
463 | req = GNUNET_malloc (sizeof (struct Request) + hlen); | 459 | req = GNUNET_malloc(sizeof(struct Request) + hlen); |
464 | req->cat = cat; | 460 | req->cat = cat; |
465 | req->hostname = (char *) &req[1]; | 461 | req->hostname = (char *)&req[1]; |
466 | GNUNET_memcpy (&req[1], | 462 | GNUNET_memcpy(&req[1], |
467 | hostname, | 463 | hostname, |
468 | hlen); | 464 | hlen); |
469 | GNUNET_CONTAINER_DLL_insert (todo_head, | 465 | GNUNET_CONTAINER_DLL_insert(todo_head, |
470 | todo_tail, | 466 | todo_tail, |
471 | req); | 467 | req); |
472 | } | 468 | } |
473 | 469 | ||
474 | 470 | ||
@@ -478,7 +474,7 @@ queue (const char *hostname, | |||
478 | * @param cls NULL | 474 | * @param cls NULL |
479 | */ | 475 | */ |
480 | static void | 476 | static void |
481 | process_stdin (void *cls) | 477 | process_stdin(void *cls) |
482 | { | 478 | { |
483 | static struct GNUNET_TIME_Absolute last; | 479 | static struct GNUNET_TIME_Absolute last; |
484 | static uint64_t idot; | 480 | static uint64_t idot; |
@@ -486,48 +482,48 @@ process_stdin (void *cls) | |||
486 | char hn[256]; | 482 | char hn[256]; |
487 | char in[270]; | 483 | char in[270]; |
488 | 484 | ||
489 | (void) cls; | 485 | (void)cls; |
490 | t = NULL; | 486 | t = NULL; |
491 | while (NULL != | 487 | while (NULL != |
492 | fgets (in, | 488 | fgets(in, |
493 | sizeof (in), | 489 | sizeof(in), |
494 | stdin)) | 490 | stdin)) |
495 | { | ||
496 | if (strlen(in) > 0) | ||
497 | hn[strlen(in)-1] = '\0'; /* eat newline */ | ||
498 | if ( (2 != sscanf (in, | ||
499 | "%u %255s", | ||
500 | &cat, | ||
501 | hn)) || | ||
502 | (cat >= RC_MAX) ) | ||
503 | { | ||
504 | fprintf (stderr, | ||
505 | "Malformed input line `%s', skipping\n", | ||
506 | in); | ||
507 | continue; | ||
508 | } | ||
509 | if (0 == idot) | ||
510 | last = GNUNET_TIME_absolute_get (); | ||
511 | idot++; | ||
512 | if (0 == idot % 100000) | ||
513 | { | 491 | { |
514 | struct GNUNET_TIME_Relative delta; | 492 | if (strlen(in) > 0) |
515 | 493 | hn[strlen(in) - 1] = '\0'; /* eat newline */ | |
516 | delta = GNUNET_TIME_absolute_get_duration (last); | 494 | if ((2 != sscanf(in, |
517 | last = GNUNET_TIME_absolute_get (); | 495 | "%u %255s", |
518 | fprintf (stderr, | 496 | &cat, |
519 | "Read 100000 domain names in %s\n", | 497 | hn)) || |
520 | GNUNET_STRINGS_relative_time_to_string (delta, | 498 | (cat >= RC_MAX)) |
521 | GNUNET_YES)); | 499 | { |
500 | fprintf(stderr, | ||
501 | "Malformed input line `%s', skipping\n", | ||
502 | in); | ||
503 | continue; | ||
504 | } | ||
505 | if (0 == idot) | ||
506 | last = GNUNET_TIME_absolute_get(); | ||
507 | idot++; | ||
508 | if (0 == idot % 100000) | ||
509 | { | ||
510 | struct GNUNET_TIME_Relative delta; | ||
511 | |||
512 | delta = GNUNET_TIME_absolute_get_duration(last); | ||
513 | last = GNUNET_TIME_absolute_get(); | ||
514 | fprintf(stderr, | ||
515 | "Read 100000 domain names in %s\n", | ||
516 | GNUNET_STRINGS_relative_time_to_string(delta, | ||
517 | GNUNET_YES)); | ||
518 | } | ||
519 | queue(hn, | ||
520 | (enum RequestCategory)cat); | ||
522 | } | 521 | } |
523 | queue (hn, | 522 | fprintf(stderr, |
524 | (enum RequestCategory) cat); | 523 | "Done reading %llu domain names\n", |
525 | } | 524 | (unsigned long long)idot); |
526 | fprintf (stderr, | 525 | t = GNUNET_SCHEDULER_add_now(&process_queue, |
527 | "Done reading %llu domain names\n", | 526 | NULL); |
528 | (unsigned long long) idot); | ||
529 | t = GNUNET_SCHEDULER_add_now (&process_queue, | ||
530 | NULL); | ||
531 | } | 527 | } |
532 | 528 | ||
533 | 529 | ||
@@ -541,25 +537,25 @@ process_stdin (void *cls) | |||
541 | * @param cfg configuration | 537 | * @param cfg configuration |
542 | */ | 538 | */ |
543 | static void | 539 | static void |
544 | run (void *cls, | 540 | run(void *cls, |
545 | char *const *args, | 541 | char *const *args, |
546 | const char *cfgfile, | 542 | const char *cfgfile, |
547 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 543 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
548 | { | 544 | { |
549 | (void) cls; | 545 | (void)cls; |
550 | (void) args; | 546 | (void)args; |
551 | (void) cfgfile; | 547 | (void)cfgfile; |
552 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | 548 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, |
553 | NULL); | 549 | NULL); |
554 | gns = GNUNET_GNS_connect (cfg); | 550 | gns = GNUNET_GNS_connect(cfg); |
555 | if (NULL == gns) | 551 | if (NULL == gns) |
556 | { | 552 | { |
557 | GNUNET_break (0); | 553 | GNUNET_break(0); |
558 | GNUNET_SCHEDULER_shutdown (); | 554 | GNUNET_SCHEDULER_shutdown(); |
559 | return; | 555 | return; |
560 | } | 556 | } |
561 | t = GNUNET_SCHEDULER_add_now (&process_stdin, | 557 | t = GNUNET_SCHEDULER_add_now(&process_stdin, |
562 | NULL); | 558 | NULL); |
563 | } | 559 | } |
564 | 560 | ||
565 | 561 | ||
@@ -571,44 +567,44 @@ run (void *cls, | |||
571 | * @return 0 on success | 567 | * @return 0 on success |
572 | */ | 568 | */ |
573 | int | 569 | int |
574 | main (int argc, | 570 | main(int argc, |
575 | char *const*argv) | 571 | char *const*argv) |
576 | { | 572 | { |
577 | int ret = 0; | 573 | int ret = 0; |
578 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 574 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
579 | GNUNET_GETOPT_option_relative_time ('d', | 575 | GNUNET_GETOPT_option_relative_time('d', |
580 | "delay", | 576 | "delay", |
581 | "RELATIVETIME", | 577 | "RELATIVETIME", |
582 | gettext_noop ("how long to wait between queries"), | 578 | gettext_noop("how long to wait between queries"), |
583 | &request_delay), | 579 | &request_delay), |
584 | GNUNET_GETOPT_option_relative_time ('t', | 580 | GNUNET_GETOPT_option_relative_time('t', |
585 | "timeout", | 581 | "timeout", |
586 | "RELATIVETIME", | 582 | "RELATIVETIME", |
587 | gettext_noop ("how long to wait for an answer"), | 583 | gettext_noop("how long to wait for an answer"), |
588 | &timeout), | 584 | &timeout), |
589 | GNUNET_GETOPT_option_flag ('2', | 585 | GNUNET_GETOPT_option_flag('2', |
590 | "g2d", | 586 | "g2d", |
591 | gettext_noop ("look for GNS2DNS records instead of ANY"), | 587 | gettext_noop("look for GNS2DNS records instead of ANY"), |
592 | &g2d), | 588 | &g2d), |
593 | GNUNET_GETOPT_OPTION_END | 589 | GNUNET_GETOPT_OPTION_END |
594 | }; | 590 | }; |
595 | 591 | ||
596 | if (GNUNET_OK != | 592 | if (GNUNET_OK != |
597 | GNUNET_STRINGS_get_utf8_args (argc, argv, | 593 | GNUNET_STRINGS_get_utf8_args(argc, argv, |
598 | &argc, &argv)) | 594 | &argc, &argv)) |
599 | return 2; | 595 | return 2; |
600 | timeout = DEF_TIMEOUT; | 596 | timeout = DEF_TIMEOUT; |
601 | request_delay = DEF_REQUEST_DELAY; | 597 | request_delay = DEF_REQUEST_DELAY; |
602 | if (GNUNET_OK != | 598 | if (GNUNET_OK != |
603 | GNUNET_PROGRAM_run (argc, | 599 | GNUNET_PROGRAM_run(argc, |
604 | argv, | 600 | argv, |
605 | "gnunet-gns-benchmark", | 601 | "gnunet-gns-benchmark", |
606 | "resolve GNS names and measure performance", | 602 | "resolve GNS names and measure performance", |
607 | options, | 603 | options, |
608 | &run, | 604 | &run, |
609 | NULL)) | 605 | NULL)) |
610 | ret = 1; | 606 | ret = 1; |
611 | GNUNET_free ((void*) argv); | 607 | GNUNET_free((void*)argv); |
612 | return ret; | 608 | return ret; |
613 | } | 609 | } |
614 | 610 | ||