aboutsummaryrefslogtreecommitdiff
path: root/src/regex/gnunet-regex-simulation-profiler.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/regex/gnunet-regex-simulation-profiler.c')
-rw-r--r--src/regex/gnunet-regex-simulation-profiler.c156
1 files changed, 87 insertions, 69 deletions
diff --git a/src/regex/gnunet-regex-simulation-profiler.c b/src/regex/gnunet-regex-simulation-profiler.c
index 27dfa773d..0f955f7b5 100644
--- a/src/regex/gnunet-regex-simulation-profiler.c
+++ b/src/regex/gnunet-regex-simulation-profiler.c
@@ -89,19 +89,9 @@ struct ProgressMeter
89static struct ProgressMeter *meter; 89static struct ProgressMeter *meter;
90 90
91/** 91/**
92 * Abort task identifier.
93 */
94static struct GNUNET_SCHEDULER_Task * abort_task;
95
96/**
97 * Shutdown task identifier.
98 */
99static struct GNUNET_SCHEDULER_Task * shutdown_task;
100
101/**
102 * Scan task identifier; 92 * Scan task identifier;
103 */ 93 */
104static struct GNUNET_SCHEDULER_Task * scan_task; 94static struct GNUNET_SCHEDULER_Task *scan_task;
105 95
106/** 96/**
107 * Global testing status. 97 * Global testing status.
@@ -240,8 +230,8 @@ update_meter (struct ProgressMeter *meter)
240 * 230 *
241 * @param meter the meter to reset 231 * @param meter the meter to reset
242 * 232 *
243 * @return GNUNET_YES if meter reset, 233 * @return #GNUNET_YES if meter reset,
244 * GNUNET_SYSERR on error 234 * #GNUNET_SYSERR on error
245 */ 235 */
246static int 236static int
247reset_meter (struct ProgressMeter *meter) 237reset_meter (struct ProgressMeter *meter)
@@ -274,21 +264,28 @@ free_meter (struct ProgressMeter *meter)
274 */ 264 */
275static void 265static void
276do_shutdown (void *cls) 266do_shutdown (void *cls)
277{ 267{
278 shutdown_task = NULL;
279 if (NULL != abort_task)
280 GNUNET_SCHEDULER_cancel (abort_task);
281 if (NULL != mysql_ctx) 268 if (NULL != mysql_ctx)
269 {
282 GNUNET_MYSQL_context_destroy (mysql_ctx); 270 GNUNET_MYSQL_context_destroy (mysql_ctx);
271 mysql_ctx = NULL;
272 }
283 if (NULL != meter) 273 if (NULL != meter)
274 {
284 free_meter (meter); 275 free_meter (meter);
285 276 meter = NULL;
286 GNUNET_SCHEDULER_shutdown (); /* Stop scheduler to shutdown testbed run */ 277 }
287} 278}
288 279
289 280
290/** 281/**
291 * abort task to run on test timed out 282 * Abort task to run on test timed out.
283 *
284 * FIXME: this doesn't actually work, it used to cancel
285 * the already running 'scan_task', but now that should
286 * always be NULL and do nothing. We instead need to set
287 * a global variable and abort scan_task internally, not
288 * via scheduler.
292 * 289 *
293 * @param cls NULL 290 * @param cls NULL
294 */ 291 */
@@ -296,25 +293,29 @@ static void
296do_abort (void *cls) 293do_abort (void *cls)
297{ 294{
298 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Aborting\n"); 295 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Aborting\n");
299 abort_task = NULL; 296 if (NULL != scan_task)
300 GNUNET_SCHEDULER_cancel (scan_task); 297 {
301 scan_task = NULL; 298 GNUNET_SCHEDULER_cancel (scan_task);
299 scan_task = NULL;
300 }
302 result = GNUNET_SYSERR; 301 result = GNUNET_SYSERR;
303 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 302 GNUNET_SCHEDULER_shutdown ();
304} 303}
305 304
306 305
307/** 306/**
308 * Dummy function for prepared select. Always return GNUNET_OK. 307 * Dummy function for prepared select. Always returns #GNUNET_OK.
309 * 308 *
310 * @param cls closure 309 * @param cls closure
311 * @param num_values number of values. 310 * @param num_values number of values.
312 * @param values returned values from select stmt. 311 * @param values returned values from select stmt.
313 * 312 *
314 * @return GNUNET_OK 313 * @return #GNUNET_OK
315 */ 314 */
316static int 315static int
317return_ok (void *cls, unsigned int num_values, MYSQL_BIND * values) 316return_ok (void *cls,
317 unsigned int num_values,
318 MYSQL_BIND * values)
318{ 319{
319 return GNUNET_OK; 320 return GNUNET_OK;
320} 321}
@@ -326,13 +327,16 @@ return_ok (void *cls, unsigned int num_values, MYSQL_BIND * values)
326 * @param cls closure. 327 * @param cls closure.
327 * @param key hash for current state. 328 * @param key hash for current state.
328 * @param proof proof for current state. 329 * @param proof proof for current state.
329 * @param accepting GNUNET_YES if this is an accepting state, GNUNET_NO if not. 330 * @param accepting #GNUNET_YES if this is an accepting state, #GNUNET_NO if not.
330 * @param num_edges number of edges leaving current state. 331 * @param num_edges number of edges leaving current state.
331 * @param edges edges leaving current state. 332 * @param edges edges leaving current state.
332 */ 333 */
333static void 334static void
334regex_iterator (void *cls, const struct GNUNET_HashCode *key, const char *proof, 335regex_iterator (void *cls,
335 int accepting, unsigned int num_edges, 336 const struct GNUNET_HashCode *key,
337 const char *proof,
338 int accepting,
339 unsigned int num_edges,
336 const struct REGEX_BLOCK_Edge *edges) 340 const struct REGEX_BLOCK_Edge *edges)
337{ 341{
338 unsigned int i; 342 unsigned int i;
@@ -453,7 +457,7 @@ regex_iterator (void *cls, const struct GNUNET_HashCode *key, const char *proof,
453 * each state into a MySQL database. 457 * each state into a MySQL database.
454 * 458 *
455 * @param regex regular expression. 459 * @param regex regular expression.
456 * @return GNUNET_OK on success, GNUNET_SYSERR on failure. 460 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure.
457 */ 461 */
458static int 462static int
459announce_regex (const char *regex) 463announce_regex (const char *regex)
@@ -461,18 +465,20 @@ announce_regex (const char *regex)
461 struct REGEX_INTERNAL_Automaton *dfa; 465 struct REGEX_INTERNAL_Automaton *dfa;
462 466
463 dfa = 467 dfa =
464 REGEX_INTERNAL_construct_dfa (regex, strlen (regex), max_path_compression); 468 REGEX_INTERNAL_construct_dfa (regex,
469 strlen (regex),
470 max_path_compression);
465 471
466 if (NULL == dfa) 472 if (NULL == dfa)
467 { 473 {
468 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create DFA for regex %s\n", 474 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
475 "Failed to create DFA for regex %s\n",
469 regex); 476 regex);
470 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); 477 GNUNET_SCHEDULER_add_now (&do_abort, NULL);
471 return GNUNET_SYSERR; 478 return GNUNET_SYSERR;
472 } 479 }
473 480 REGEX_INTERNAL_iterate_all_edges (dfa,
474 REGEX_INTERNAL_iterate_all_edges (dfa, &regex_iterator, NULL); 481 &regex_iterator, NULL);
475
476 REGEX_INTERNAL_automaton_destroy (dfa); 482 REGEX_INTERNAL_automaton_destroy (dfa);
477 483
478 return GNUNET_OK; 484 return GNUNET_OK;
@@ -484,8 +490,8 @@ announce_regex (const char *regex)
484 * 490 *
485 * @param cls closure 491 * @param cls closure
486 * @param filename complete filename (absolute path) 492 * @param filename complete filename (absolute path)
487 * @return GNUNET_OK to continue to iterate, 493 * @return #GNUNET_OK to continue to iterate,
488 * GNUNET_SYSERR to abort iteration with error! 494 * #GNUNET_SYSERR to abort iteration with error!
489 */ 495 */
490static int 496static int
491policy_filename_cb (void *cls, const char *filename) 497policy_filename_cb (void *cls, const char *filename)
@@ -498,17 +504,20 @@ policy_filename_cb (void *cls, const char *filename)
498 504
499 GNUNET_assert (NULL != filename); 505 GNUNET_assert (NULL != filename);
500 506
501 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Announcing regexes from file %s\n", 507 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
508 "Announcing regexes from file %s\n",
502 filename); 509 filename);
503 510
504 if (GNUNET_YES != GNUNET_DISK_file_test (filename)) 511 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
505 { 512 {
506 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Could not find policy file %s\n", 513 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
514 "Could not find policy file %s\n",
507 filename); 515 filename);
508 return GNUNET_OK; 516 return GNUNET_OK;
509 } 517 }
510 if (GNUNET_OK != 518 if (GNUNET_OK !=
511 GNUNET_DISK_file_size (filename, &filesize, GNUNET_YES, GNUNET_YES)) 519 GNUNET_DISK_file_size (filename, &filesize,
520 GNUNET_YES, GNUNET_YES))
512 filesize = 0; 521 filesize = 0;
513 if (0 == filesize) 522 if (0 == filesize)
514 { 523 {
@@ -520,7 +529,8 @@ policy_filename_cb (void *cls, const char *filename)
520 if (filesize != GNUNET_DISK_fn_read (filename, data, filesize)) 529 if (filesize != GNUNET_DISK_fn_read (filename, data, filesize))
521 { 530 {
522 GNUNET_free (data); 531 GNUNET_free (data);
523 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Could not read policy file %s.\n", 532 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
533 "Could not read policy file %s.\n",
524 filename); 534 filename);
525 return GNUNET_OK; 535 return GNUNET_OK;
526 } 536 }
@@ -545,11 +555,13 @@ policy_filename_cb (void *cls, const char *filename)
545 data[offset] = '\0'; 555 data[offset] = '\0';
546 GNUNET_asprintf (&regex, "%s(%s)", regex_prefix, data); 556 GNUNET_asprintf (&regex, "%s(%s)", regex_prefix, data);
547 GNUNET_assert (NULL != regex); 557 GNUNET_assert (NULL != regex);
548 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Announcing regex: %s\n", regex); 558 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
559 "Announcing regex: %s\n", regex);
549 560
550 if (GNUNET_OK != announce_regex (regex)) 561 if (GNUNET_OK != announce_regex (regex))
551 { 562 {
552 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not announce regex %s\n", 563 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
564 "Could not announce regex %s\n",
553 regex); 565 regex);
554 } 566 }
555 GNUNET_free (regex); 567 GNUNET_free (regex);
@@ -571,6 +583,7 @@ do_directory_scan (void *cls)
571 char *stmt; 583 char *stmt;
572 584
573 /* Create an MySQL prepared statement for the inserts */ 585 /* Create an MySQL prepared statement for the inserts */
586 scan_task = NULL;
574 GNUNET_asprintf (&stmt, INSERT_EDGE_STMT, table_name); 587 GNUNET_asprintf (&stmt, INSERT_EDGE_STMT, table_name);
575 stmt_handle = GNUNET_MYSQL_statement_prepare (mysql_ctx, stmt); 588 stmt_handle = GNUNET_MYSQL_statement_prepare (mysql_ctx, stmt);
576 GNUNET_free (stmt); 589 GNUNET_free (stmt);
@@ -581,10 +594,13 @@ do_directory_scan (void *cls)
581 594
582 GNUNET_assert (NULL != stmt_handle); 595 GNUNET_assert (NULL != stmt_handle);
583 596
584 meter = 597 meter = create_meter (num_policy_files,
585 create_meter (num_policy_files, "Announcing policy files\n", GNUNET_YES); 598 "Announcing policy files\n",
599 GNUNET_YES);
586 start_time = GNUNET_TIME_absolute_get (); 600 start_time = GNUNET_TIME_absolute_get ();
587 GNUNET_DISK_directory_scan (policy_dir, &policy_filename_cb, stmt_handle); 601 GNUNET_DISK_directory_scan (policy_dir,
602 &policy_filename_cb,
603 stmt_handle);
588 duration = GNUNET_TIME_absolute_get_duration (start_time); 604 duration = GNUNET_TIME_absolute_get_duration (start_time);
589 reset_meter (meter); 605 reset_meter (meter);
590 free_meter (meter); 606 free_meter (meter);
@@ -592,12 +608,13 @@ do_directory_scan (void *cls)
592 608
593 printf ("Announced %u files containing %u policies in %s\n" 609 printf ("Announced %u files containing %u policies in %s\n"
594 "Duplicate transitions: %llu\nMerged states: %llu\n", 610 "Duplicate transitions: %llu\nMerged states: %llu\n",
595 num_policy_files, num_policies, 611 num_policy_files,
612 num_policies,
596 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_NO), 613 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_NO),
597 num_merged_transitions, num_merged_states); 614 num_merged_transitions,
598 615 num_merged_states);
599 result = GNUNET_OK; 616 result = GNUNET_OK;
600 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 617 GNUNET_SCHEDULER_shutdown ();
601} 618}
602 619
603 620
@@ -610,7 +627,9 @@ do_directory_scan (void *cls)
610 * @param config configuration 627 * @param config configuration
611 */ 628 */
612static void 629static void
613run (void *cls, char *const *args, const char *cfgfile, 630run (void *cls,
631 char *const *args,
632 const char *cfgfile,
614 const struct GNUNET_CONFIGURATION_Handle *config) 633 const struct GNUNET_CONFIGURATION_Handle *config)
615{ 634{
616 if (NULL == args[0]) 635 if (NULL == args[0])
@@ -620,7 +639,8 @@ run (void *cls, char *const *args, const char *cfgfile,
620 result = GNUNET_SYSERR; 639 result = GNUNET_SYSERR;
621 return; 640 return;
622 } 641 }
623 if (GNUNET_YES != GNUNET_DISK_directory_test (args[0], GNUNET_YES)) 642 if (GNUNET_YES !=
643 GNUNET_DISK_directory_test (args[0], GNUNET_YES))
624 { 644 {
625 fprintf (stderr, 645 fprintf (stderr,
626 _("Specified policies directory does not exist. Exiting.\n")); 646 _("Specified policies directory does not exist. Exiting.\n"));
@@ -629,7 +649,8 @@ run (void *cls, char *const *args, const char *cfgfile,
629 } 649 }
630 policy_dir = args[0]; 650 policy_dir = args[0];
631 651
632 num_policy_files = GNUNET_DISK_directory_scan (policy_dir, NULL, NULL); 652 num_policy_files = GNUNET_DISK_directory_scan (policy_dir,
653 NULL, NULL);
633 meter = NULL; 654 meter = NULL;
634 655
635 if (NULL == table_name) 656 if (NULL == table_name)
@@ -642,32 +663,29 @@ run (void *cls, char *const *args, const char *cfgfile,
642 mysql_ctx = GNUNET_MYSQL_context_create (config, "regex-mysql"); 663 mysql_ctx = GNUNET_MYSQL_context_create (config, "regex-mysql");
643 if (NULL == mysql_ctx) 664 if (NULL == mysql_ctx)
644 { 665 {
645 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create mysql context\n"); 666 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
667 "Failed to create mysql context\n");
646 result = GNUNET_SYSERR; 668 result = GNUNET_SYSERR;
647 return; 669 return;
648 } 670 }
649 671
650 if (GNUNET_OK != 672 if (GNUNET_OK !=
651 GNUNET_CONFIGURATION_get_value_string (config, "regex-mysql", 673 GNUNET_CONFIGURATION_get_value_string (config,
652 "REGEX_PREFIX", &regex_prefix)) 674 "regex-mysql",
675 "REGEX_PREFIX",
676 &regex_prefix))
653 { 677 {
654 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 678 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
655 _ 679 "regex-mysql",
656 ("%s service is lacking key configuration settings (%s). Exiting.\n"), 680 "REGEX_PREFIX");
657 "regexprofiler", "regex_prefix");
658 result = GNUNET_SYSERR; 681 result = GNUNET_SYSERR;
659 return; 682 return;
660 } 683 }
661 684
662
663 result = GNUNET_OK; 685 result = GNUNET_OK;
664 686 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
687 NULL);
665 scan_task = GNUNET_SCHEDULER_add_now (&do_directory_scan, NULL); 688 scan_task = GNUNET_SCHEDULER_add_now (&do_directory_scan, NULL);
666
667 /* Scheduled the task to clean up when shutdown is called */
668 shutdown_task =
669 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_shutdown,
670 NULL);
671} 689}
672 690
673 691