Regex profiler that dumps all DFAs into a database instead of using the DHT (with cadet). More...
#include "platform.h"
#include "gnunet_util_lib.h"
#include "regex_internal_lib.h"
#include "gnunet_mysql_lib.h"
#include "gnunet_mysql_compat.h"
#include "gnunet_my_lib.h"
#include <mysql/mysql.h>
Go to the source code of this file.
Data Structures | |
struct | ProgressMeter |
Simple struct to keep track of progress, and print a nice little percentage meter for long running tasks. More... | |
Macros | |
#define | INSERT_EDGE_STMT |
MySQL statement to insert an edge. More... | |
#define | SELECT_KEY_STMT |
MySQL statement to select a key count. More... | |
Functions | |
static struct ProgressMeter * | create_meter (unsigned int total, char *start_string, int print) |
Create a meter to keep track of the progress of some task. More... | |
static int | update_meter (struct ProgressMeter *meter) |
Update progress meter (increment by one). More... | |
static int | reset_meter (struct ProgressMeter *meter) |
Reset progress meter. More... | |
static void | free_meter (struct ProgressMeter *meter) |
Release resources for meter. More... | |
static void | do_shutdown (void *cls) |
Shutdown task. More... | |
static void | do_abort (void *cls) |
Abort task to run on test timed out. More... | |
static void | regex_iterator (void *cls, const struct GNUNET_HashCode *key, const char *proof, int accepting, unsigned int num_edges, const struct REGEX_BLOCK_Edge *edges) |
Iterator over all states that inserts each state into the MySQL db. More... | |
static int | announce_regex (const char *regex) |
Announce a regex by creating the DFA and iterating over each state, inserting each state into a MySQL database. More... | |
static int | policy_filename_cb (void *cls, const char *filename) |
Function called with a filename. More... | |
static void | do_directory_scan (void *cls) |
Iterate over files contained in policy_dir. More... | |
static void | run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *config) |
Main function that will be run by the scheduler. More... | |
int | main (int argc, char *const *argv) |
Main function. More... | |
Variables | |
static struct ProgressMeter * | meter |
Handle for the progress meter. More... | |
static struct GNUNET_SCHEDULER_Task * | scan_task |
Scan task identifier;. More... | |
static int | result |
Global testing status. More... | |
static struct GNUNET_MYSQL_Context * | mysql_ctx |
MySQL context. More... | |
static struct GNUNET_MYSQL_StatementHandle * | stmt_handle |
MySQL prepared statement handle. More... | |
static struct GNUNET_MYSQL_StatementHandle * | select_stmt_handle |
MySQL prepared statement handle for key select. More... | |
static char * | table_name |
MySQL table name. More... | |
static char * | policy_dir |
Policy dir containing files that contain policies. More... | |
static unsigned int | num_policy_files |
Number of policy files. More... | |
static unsigned int | num_policies |
Number of policies. More... | |
static unsigned int | max_path_compression |
Maximal path compression length. More... | |
static unsigned long long | num_merged_transitions |
Number of merged transitions. More... | |
static unsigned long long | num_merged_states |
Number of merged states from different policies. More... | |
static char * | regex_prefix |
Prefix to add before every regex we're announcing. More... | |
Regex profiler that dumps all DFAs into a database instead of using the DHT (with cadet).
Definition in file gnunet-regex-simulation-profiler.c.
#define INSERT_EDGE_STMT |
MySQL statement to insert an edge.
Definition at line 42 of file gnunet-regex-simulation-profiler.c.
#define SELECT_KEY_STMT |
MySQL statement to select a key count.
Definition at line 49 of file gnunet-regex-simulation-profiler.c.
|
static |
Create a meter to keep track of the progress of some task.
total | the total number of items to complete |
start_string | a string to prefix the meter with (if printing) |
GNUNET_YES to print the meter, GNUNET_NO to count internally only |
Definition at line 172 of file gnunet-regex-simulation-profiler.c.
References GNUNET_new, GNUNET_strdup, ProgressMeter::print, ret, and ProgressMeter::total.
Referenced by do_directory_scan().
|
static |
Update progress meter (increment by one).
meter | the meter to update and print info for |
Definition at line 201 of file gnunet-regex-simulation-profiler.c.
References ProgressMeter::completed, ProgressMeter::dotnum, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_NO, GNUNET_YES, meter, ProgressMeter::modnum, ProgressMeter::print, ProgressMeter::startup_string, and ProgressMeter::total.
Referenced by policy_filename_cb().
|
static |
Reset progress meter.
meter | the meter to reset |
Definition at line 241 of file gnunet-regex-simulation-profiler.c.
References ProgressMeter::completed, GNUNET_SYSERR, GNUNET_YES, and meter.
Referenced by do_directory_scan().
|
static |
Release resources for meter.
meter | the meter to free |
Definition at line 257 of file gnunet-regex-simulation-profiler.c.
References GNUNET_free, meter, and ProgressMeter::startup_string.
Referenced by do_directory_scan(), and do_shutdown().
|
static |
Shutdown task.
cls | NULL |
Definition at line 270 of file gnunet-regex-simulation-profiler.c.
References free_meter(), meter, and mysql_ctx.
Referenced by run().
|
static |
Abort task to run on test timed out.
FIXME: this doesn't actually work, it used to cancel the already running 'scan_task', but now that should always be NULL and do nothing. We instead need to set a global variable and abort scan_task internally, not via scheduler.
cls | NULL |
Definition at line 297 of file gnunet-regex-simulation-profiler.c.
References GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_SCHEDULER_cancel(), GNUNET_SCHEDULER_shutdown(), GNUNET_SYSERR, result, and scan_task.
Referenced by announce_regex(), and regex_iterator().
|
static |
Iterator over all states that inserts each state into the MySQL db.
cls | closure. |
key | hash for current state. |
proof | proof for current state. |
accepting | GNUNET_YES if this is an accepting state, GNUNET_NO if not. |
num_edges | number of edges leaving current state. |
edges | edges leaving current state. |
Definition at line 321 of file gnunet-regex-simulation-profiler.c.
References do_abort(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_h2s(), GNUNET_log, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, GNUNET_SYSERR, key, mysql_ctx, num_merged_states, num_merged_transitions, result, select_stmt_handle, stmt_handle, and ProgressMeter::total.
Referenced by announce_regex().
|
static |
Announce a regex by creating the DFA and iterating over each state, inserting each state into a MySQL database.
regex | regular expression. |
Definition at line 457 of file gnunet-regex-simulation-profiler.c.
References do_abort(), GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_SYSERR, max_path_compression, REGEX_INTERNAL_Automaton::regex, REGEX_INTERNAL_automaton_destroy(), REGEX_INTERNAL_construct_dfa(), REGEX_INTERNAL_iterate_all_edges(), and regex_iterator().
Referenced by policy_filename_cb().
|
static |
Function called with a filename.
cls | closure |
filename | complete filename (absolute path) |
Definition at line 491 of file gnunet-regex-simulation-profiler.c.
References announce_regex(), buf, data, filename, GNUNET_asprintf(), GNUNET_assert, GNUNET_DISK_file_size(), GNUNET_DISK_file_test(), GNUNET_DISK_fn_read(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_OK, GNUNET_YES, meter, num_policies, REGEX_INTERNAL_Automaton::regex, regex_prefix, and update_meter().
Referenced by do_directory_scan().
|
static |
Iterate over files contained in policy_dir.
cls | NULL |
Definition at line 573 of file gnunet-regex-simulation-profiler.c.
References create_meter(), duration, free_meter(), GNUNET_asprintf(), GNUNET_assert, GNUNET_DISK_directory_scan(), GNUNET_free, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_shutdown(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_get_duration(), GNUNET_YES, INSERT_EDGE_STMT, meter, mysql_ctx, num_merged_states, num_merged_transitions, num_policies, num_policy_files, policy_dir, policy_filename_cb(), reset_meter(), result, scan_task, SELECT_KEY_STMT, select_stmt_handle, start_time, stmt_handle, and table_name.
Referenced by run().
|
static |
Main function that will be run by the scheduler.
cls | closure |
args | remaining command-line arguments |
cfgfile | name of the configuration file used (for saving, can be NULL!) |
config | configuration |
Definition at line 624 of file gnunet-regex-simulation-profiler.c.
References _, consensus-simulation::args, config, do_directory_scan(), do_shutdown(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_DISK_directory_scan(), GNUNET_DISK_directory_test(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_log_config_missing(), GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SYSERR, GNUNET_YES, meter, mysql_ctx, num_policy_files, policy_dir, regex_prefix, result, scan_task, and table_name.
Referenced by main().
int main | ( | int | argc, |
char *const * | argv | ||
) |
Main function.
argc | argument count |
argv | argument values |
Definition at line 694 of file gnunet-regex-simulation-profiler.c.
References _, gettext_noop, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_string(), GNUNET_GETOPT_option_uint(), GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_STRINGS_get_utf8_args(), GNUNET_SYSERR, max_path_compression, options, result, ret, run(), and table_name.
|
static |
Handle for the progress meter.
Definition at line 93 of file gnunet-regex-simulation-profiler.c.
Referenced by do_directory_scan(), do_shutdown(), free_meter(), policy_filename_cb(), reset_meter(), run(), and update_meter().
|
static |
Scan task identifier;.
Definition at line 98 of file gnunet-regex-simulation-profiler.c.
Referenced by do_abort(), do_directory_scan(), and run().
|
static |
Global testing status.
Definition at line 103 of file gnunet-regex-simulation-profiler.c.
Referenced by do_abort(), do_directory_scan(), main(), regex_iterator(), and run().
|
static |
MySQL context.
Definition at line 108 of file gnunet-regex-simulation-profiler.c.
Referenced by do_directory_scan(), do_shutdown(), regex_iterator(), and run().
|
static |
MySQL prepared statement handle.
Definition at line 113 of file gnunet-regex-simulation-profiler.c.
Referenced by do_directory_scan(), and regex_iterator().
|
static |
MySQL prepared statement handle for key
select.
Definition at line 118 of file gnunet-regex-simulation-profiler.c.
Referenced by do_directory_scan(), and regex_iterator().
|
static |
MySQL table name.
Definition at line 123 of file gnunet-regex-simulation-profiler.c.
Referenced by do_directory_scan(), main(), and run().
|
static |
Policy dir containing files that contain policies.
Definition at line 128 of file gnunet-regex-simulation-profiler.c.
Referenced by do_directory_scan(), and run().
|
static |
Number of policy files.
Definition at line 133 of file gnunet-regex-simulation-profiler.c.
Referenced by do_directory_scan(), and run().
|
static |
Number of policies.
Definition at line 138 of file gnunet-regex-simulation-profiler.c.
Referenced by do_directory_scan(), and policy_filename_cb().
|
static |
Maximal path compression length.
Definition at line 143 of file gnunet-regex-simulation-profiler.c.
Referenced by announce_regex(), and main().
|
static |
Number of merged transitions.
Definition at line 148 of file gnunet-regex-simulation-profiler.c.
Referenced by do_directory_scan(), and regex_iterator().
|
static |
Number of merged states from different policies.
Definition at line 153 of file gnunet-regex-simulation-profiler.c.
Referenced by do_directory_scan(), and regex_iterator().
|
static |
Prefix to add before every regex we're announcing.
Definition at line 158 of file gnunet-regex-simulation-profiler.c.
Referenced by policy_filename_cb(), and run().