GNUnet  0.20.0
gnunet-regex-simulation-profiler.c File Reference

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>
Include dependency graph for gnunet-regex-simulation-profiler.c:

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 ProgressMetercreate_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 ProgressMetermeter
 Handle for the progress meter. More...
 
static struct GNUNET_SCHEDULER_Taskscan_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...
 

Detailed Description

Regex profiler that dumps all DFAs into a database instead of using the DHT (with cadet).

Author
Maximilian Szengel
Christophe Genevey

Definition in file gnunet-regex-simulation-profiler.c.

Macro Definition Documentation

◆ INSERT_EDGE_STMT

#define INSERT_EDGE_STMT
Value:
"INSERT IGNORE INTO `%s` " \
"(`key`, `label`, `to_key`, `accepting`) " \
"VALUES (?, ?, ?, ?);"

MySQL statement to insert an edge.

Definition at line 42 of file gnunet-regex-simulation-profiler.c.

◆ SELECT_KEY_STMT

#define SELECT_KEY_STMT
Value:
"SELECT COUNT(*) FROM `%s` " \
"WHERE `key` = ? AND `label` = ?;"

MySQL statement to select a key count.

Definition at line 49 of file gnunet-regex-simulation-profiler.c.

Function Documentation

◆ create_meter()

static struct ProgressMeter* create_meter ( unsigned int  total,
char *  start_string,
int  print 
)
static

Create a meter to keep track of the progress of some task.

Parameters
totalthe total number of items to complete
start_stringa string to prefix the meter with (if printing)
printGNUNET_YES to print the meter, GNUNET_NO to count internally only
Returns
the progress meter

Definition at line 172 of file gnunet-regex-simulation-profiler.c.

173 {
174  struct ProgressMeter *ret;
175 
176  ret = GNUNET_new (struct ProgressMeter);
177  ret->print = print;
178  ret->total = total;
179  ret->modnum = total / 4;
180  if (ret->modnum == 0) /* Divide by zero check */
181  ret->modnum = 1;
182  ret->dotnum = (total / 50) + 1;
183  if (start_string != NULL)
184  ret->startup_string = GNUNET_strdup (start_string);
185  else
186  ret->startup_string = GNUNET_strdup ("");
187 
188  return ret;
189 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Simple struct to keep track of progress, and print a nice little percentage meter for long running ta...
int print
Should the meter be printed?
unsigned int total
Total number of elements.

References GNUNET_new, GNUNET_strdup, ProgressMeter::print, ret, and ProgressMeter::total.

Referenced by do_directory_scan().

Here is the caller graph for this function:

◆ update_meter()

static int update_meter ( struct ProgressMeter meter)
static

Update progress meter (increment by one).

Parameters
meterthe meter to update and print info for
Returns
GNUNET_YES if called the total requested, GNUNET_NO if more items expected

Definition at line 201 of file gnunet-regex-simulation-profiler.c.

202 {
203  if (meter->print == GNUNET_YES)
204  {
205  if (meter->completed % meter->modnum == 0)
206  {
207  if (meter->completed == 0)
208  {
209  fprintf (stdout, "%sProgress: [0%%", meter->startup_string);
210  }
211  else
212  fprintf (stdout, "%d%%",
213  (int) (((float) meter->completed / meter->total) * 100));
214  }
215  else if (meter->completed % meter->dotnum == 0)
216  fprintf (stdout, "%s", ".");
217 
218  if (meter->completed + 1 == meter->total)
219  fprintf (stdout, "%d%%]\n", 100);
220  fflush (stdout);
221  }
222  meter->completed++;
223 
224  if (meter->completed == meter->total)
225  return GNUNET_YES;
226  if (meter->completed > meter->total)
227  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Progress meter overflow!!\n");
228  return GNUNET_NO;
229 }
static struct ProgressMeter * meter
Handle for the progress meter.
#define GNUNET_log(kind,...)
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_ERROR_TYPE_WARNING
unsigned int completed
Completed number.
unsigned int dotnum
Number of dots to print.
unsigned int modnum
Interval for printing percentage.
char * startup_string
String to print on startup.

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().

Here is the caller graph for this function:

◆ reset_meter()

static int reset_meter ( struct ProgressMeter meter)
static

Reset progress meter.

Parameters
meterthe meter to reset
Returns
GNUNET_YES if meter reset, GNUNET_SYSERR on error

Definition at line 241 of file gnunet-regex-simulation-profiler.c.

242 {
243  if (meter == NULL)
244  return GNUNET_SYSERR;
245 
246  meter->completed = 0;
247  return GNUNET_YES;
248 }
@ GNUNET_SYSERR

References ProgressMeter::completed, GNUNET_SYSERR, GNUNET_YES, and meter.

Referenced by do_directory_scan().

Here is the caller graph for this function:

◆ free_meter()

static void free_meter ( struct ProgressMeter meter)
static

Release resources for meter.

Parameters
meterthe meter to free

Definition at line 257 of file gnunet-regex-simulation-profiler.c.

258 {
260  GNUNET_free (meter);
261 }
#define GNUNET_free(ptr)
Wrapper around free.

References GNUNET_free, meter, and ProgressMeter::startup_string.

Referenced by do_directory_scan(), and do_shutdown().

Here is the caller graph for this function:

◆ do_shutdown()

static void do_shutdown ( void *  cls)
static

Shutdown task.

Parameters
clsNULL

Definition at line 270 of file gnunet-regex-simulation-profiler.c.

271 {
272  if (NULL != mysql_ctx)
273  {
274  GNUNET_MYSQL_context_destroy (mysql_ctx);
275  mysql_ctx = NULL;
276  }
277  if (NULL != meter)
278  {
279  free_meter (meter);
280  meter = NULL;
281  }
282 }
static void free_meter(struct ProgressMeter *meter)
Release resources for meter.
static struct GNUNET_MYSQL_Context * mysql_ctx
MySQL context.

References free_meter(), meter, and mysql_ctx.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_abort()

static void do_abort ( void *  cls)
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.

Parameters
clsNULL

Definition at line 297 of file gnunet-regex-simulation-profiler.c.

298 {
299  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Aborting\n");
300  if (NULL != scan_task)
301  {
303  scan_task = NULL;
304  }
307 }
static struct GNUNET_SCHEDULER_Task * scan_task
Scan task identifier;.
static int result
Global testing status.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:562
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ regex_iterator()

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 
)
static

Iterator over all states that inserts each state into the MySQL db.

Parameters
clsclosure.
keyhash for current state.
proofproof for current state.
acceptingGNUNET_YES if this is an accepting state, GNUNET_NO if not.
num_edgesnumber of edges leaving current state.
edgesedges leaving current state.

Definition at line 321 of file gnunet-regex-simulation-profiler.c.

327 {
328  unsigned int i;
329  int result;
330 
331  uint32_t iaccepting = (uint32_t) accepting;
332  uint64_t total;
333 
334  GNUNET_assert (NULL != mysql_ctx);
335 
336  for (i = 0; i < num_edges; i++)
337  {
338  struct GNUNET_MY_QueryParam params_select[] = {
339  GNUNET_MY_query_param_auto_from_type (key),
340  GNUNET_MY_query_param_string (edges[i].label),
341  GNUNET_MY_query_param_end
342  };
343 
344  struct GNUNET_MY_ResultSpec results_select[] = {
345  GNUNET_MY_result_spec_uint64 (&total),
346  GNUNET_MY_result_spec_end
347  };
348 
349  result =
350  GNUNET_MY_exec_prepared (mysql_ctx,
352  params_select);
353 
354  if (GNUNET_SYSERR == result)
355  {
357  "Error executing prepared mysql select statement\n");
359  return;
360  }
361 
362  result =
363  GNUNET_MY_extract_result (select_stmt_handle,
364  results_select);
365 
366  if (GNUNET_SYSERR == result)
367  {
369  "Error extracting result mysql select statement\n");
371  return;
372  }
373 
374  if ((-1 != total) && (total > 0) )
375  {
376  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Total: %llu (%s, %s)\n",
377  (unsigned long long) total,
378  GNUNET_h2s (key), edges[i].label);
379  }
380 
381  struct GNUNET_MY_QueryParam params_stmt[] = {
382  GNUNET_MY_query_param_auto_from_type (&key),
383  GNUNET_MY_query_param_string (edges[i].label),
384  GNUNET_MY_query_param_auto_from_type (&edges[i].destination),
385  GNUNET_MY_query_param_uint32 (&iaccepting),
386  GNUNET_MY_query_param_end
387  };
388 
389  result =
390  GNUNET_MY_exec_prepared (mysql_ctx,
391  stmt_handle,
392  params_stmt);
393 
394  if (0 == result)
395  {
396  char *key_str = GNUNET_strdup (GNUNET_h2s (key));
397  char *to_key_str = GNUNET_strdup (GNUNET_h2s (&edges[i].destination));
398 
399  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Merged (%s, %s, %s, %i)\n",
400  key_str,
401  edges[i].label,
402  to_key_str,
403  accepting);
404 
405  GNUNET_free (key_str);
406  GNUNET_free (to_key_str);
408  }
409  else if (-1 != total)
410  {
412  }
413 
414  if ((GNUNET_SYSERR == result) || ((1 != result) && (0 != result) ))
415  {
417  "Error executing prepared mysql statement for edge: Affected rows: %i, expected 0 or 1!\n",
418  result);
420  }
421  }
422 
423  if (0 == num_edges)
424  {
425  struct GNUNET_MY_QueryParam params_stmt[] = {
426  GNUNET_MY_query_param_auto_from_type (key),
427  GNUNET_MY_query_param_string (""),
428  GNUNET_MY_query_param_fixed_size (NULL, 0),
429  GNUNET_MY_query_param_uint32 (&iaccepting),
430  GNUNET_MY_query_param_end
431  };
432 
433  result =
434  GNUNET_MY_exec_prepared (mysql_ctx,
435  stmt_handle,
436  params_stmt);
437 
438  if ((1 != result) && (0 != result) )
439  {
441  "Error executing prepared mysql statement for edge: Affected rows: %i, expected 0 or 1!\n",
442  result);
444  }
445  }
446 }
struct GNUNET_HashCode key
The key used in the DHT.
static void do_abort(void *cls)
Abort task to run on test timed out.
static unsigned long long num_merged_states
Number of merged states from different policies.
static struct GNUNET_MYSQL_StatementHandle * stmt_handle
MySQL prepared statement handle.
static struct GNUNET_MYSQL_StatementHandle * select_stmt_handle
MySQL prepared statement handle for key select.
static unsigned long long num_merged_transitions
Number of merged transitions.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1299

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ announce_regex()

static int announce_regex ( const char *  regex)
static

Announce a regex by creating the DFA and iterating over each state, inserting each state into a MySQL database.

Parameters
regexregular expression.
Returns
GNUNET_OK on success, GNUNET_SYSERR on failure.

Definition at line 457 of file gnunet-regex-simulation-profiler.c.

458 {
459  struct REGEX_INTERNAL_Automaton *dfa;
460 
461  dfa =
463  strlen (regex),
465 
466  if (NULL == dfa)
467  {
469  "Failed to create DFA for regex %s\n",
470  regex);
472  return GNUNET_SYSERR;
473  }
475  &regex_iterator, NULL);
477 
478  return GNUNET_OK;
479 }
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.
static unsigned int max_path_compression
Maximal path compression length.
@ GNUNET_OK
void REGEX_INTERNAL_iterate_all_edges(struct REGEX_INTERNAL_Automaton *a, REGEX_INTERNAL_KeyIterator iterator, void *iterator_cls)
Iterate over all edges starting from start state of automaton 'a'.
struct REGEX_INTERNAL_Automaton * REGEX_INTERNAL_construct_dfa(const char *regex, const size_t len, unsigned int max_path_len)
Construct DFA for the given 'regex' of length 'len'.
void REGEX_INTERNAL_automaton_destroy(struct REGEX_INTERNAL_Automaton *a)
Free the memory allocated by constructing the REGEX_INTERNAL_Automaton.
Automaton representation.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ policy_filename_cb()

static int policy_filename_cb ( void *  cls,
const char *  filename 
)
static

Function called with a filename.

Parameters
clsclosure
filenamecomplete filename (absolute path)
Returns
GNUNET_OK to continue to iterate, GNUNET_SYSERR to abort iteration with error!

Definition at line 491 of file gnunet-regex-simulation-profiler.c.

492 {
493  char *regex;
494  char *data;
495  char *buf;
496  uint64_t filesize;
497  unsigned int offset;
498 
499  GNUNET_assert (NULL != filename);
500 
502  "Announcing regexes from file %s\n",
503  filename);
504 
506  {
508  "Could not find policy file %s\n",
509  filename);
510  return GNUNET_OK;
511  }
512  if (GNUNET_OK !=
513  GNUNET_DISK_file_size (filename, &filesize,
515  filesize = 0;
516  if (0 == filesize)
517  {
518  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Policy file %s is empty.\n",
519  filename);
520  return GNUNET_OK;
521  }
522  data = GNUNET_malloc (filesize);
523  if (filesize != GNUNET_DISK_fn_read (filename, data, filesize))
524  {
525  GNUNET_free (data);
527  "Could not read policy file %s.\n",
528  filename);
529  return GNUNET_OK;
530  }
531 
533 
534  buf = data;
535  offset = 0;
536  regex = NULL;
537  while (offset < (filesize - 1))
538  {
539  offset++;
540  if (((data[offset] == '\n')) && (buf != &data[offset]))
541  {
542  data[offset] = '|';
543  num_policies++;
544  buf = &data[offset + 1];
545  }
546  else if ((data[offset] == '\n') || (data[offset] == '\0'))
547  buf = &data[offset + 1];
548  }
549  data[offset] = '\0';
550  GNUNET_asprintf (&regex, "%s(%s)", regex_prefix, data);
551  GNUNET_assert (NULL != regex);
553  "Announcing regex: %s\n", regex);
554 
555  if (GNUNET_OK != announce_regex (regex))
556  {
558  "Could not announce regex %s\n",
559  regex);
560  }
561  GNUNET_free (regex);
562  GNUNET_free (data);
563  return GNUNET_OK;
564 }
static char * filename
uint32_t data
The data value.
static unsigned int num_policies
Number of policies.
static int update_meter(struct ProgressMeter *meter)
Update progress meter (increment by one).
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...
static char * regex_prefix
Prefix to add before every regex we're announcing.
static char buf[2048]
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
Definition: disk.c:482
enum GNUNET_GenericReturnValue GNUNET_DISK_file_size(const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode)
Get the size of the file (or directory) of the given file (in bytes).
Definition: disk.c:221
ssize_t GNUNET_DISK_fn_read(const char *fn, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:664
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_malloc(size)
Wrapper around malloc.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_directory_scan()

static void do_directory_scan ( void *  cls)
static

Iterate over files contained in policy_dir.

Parameters
clsNULL

Definition at line 573 of file gnunet-regex-simulation-profiler.c.

574 {
577  char *stmt;
578 
579  /* Create an MySQL prepared statement for the inserts */
580  scan_task = NULL;
582  stmt_handle = GNUNET_MYSQL_statement_prepare (mysql_ctx, stmt);
583  GNUNET_free (stmt);
584 
586  select_stmt_handle = GNUNET_MYSQL_statement_prepare (mysql_ctx, stmt);
587  GNUNET_free (stmt);
588 
589  GNUNET_assert (NULL != stmt_handle);
590 
592  "Announcing policy files\n",
593  GNUNET_YES);
597  stmt_handle);
599  reset_meter (meter);
600  free_meter (meter);
601  meter = NULL;
602 
603  printf ("Announced %u files containing %u policies in %s\n"
604  "Duplicate transitions: %llu\nMerged states: %llu\n",
606  num_policies,
610  result = GNUNET_OK;
612 }
static struct GNUNET_TIME_Absolute start_time
Start time of the current round; used to determine how long one iteration takes (which influences how...
static char * policy_dir
Policy dir containing files that contain policies.
#define SELECT_KEY_STMT
MySQL statement to select a key count.
#define INSERT_EDGE_STMT
MySQL statement to insert an edge.
static unsigned int num_policy_files
Number of policy files.
static int policy_filename_cb(void *cls, const char *filename)
Function called with a filename.
static char * table_name
MySQL table name.
static int reset_meter(struct ProgressMeter *meter)
Reset progress meter.
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.
static struct GNUNET_TIME_Relative duration
How long do we run the test?
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:814
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition: time.c:436
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:569
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle config 
)
static

Main function that will be run by the scheduler.

Parameters
clsclosure
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
configconfiguration

Definition at line 624 of file gnunet-regex-simulation-profiler.c.

628 {
629  if (NULL == args[0])
630  {
631  fprintf (stderr,
632  _ ("No policy directory specified on command line. Exiting.\n"));
634  return;
635  }
636  if (GNUNET_YES !=
638  {
639  fprintf (stderr,
640  _ ("Specified policies directory does not exist. Exiting.\n"));
642  return;
643  }
644  policy_dir = args[0];
645 
647  NULL, NULL);
648  meter = NULL;
649 
650  if (NULL == table_name)
651  {
653  "No table name specified, using default \"NFA\".\n");
654  table_name = "NFA";
655  }
656 
657  mysql_ctx = GNUNET_MYSQL_context_create (config, "regex-mysql");
658  if (NULL == mysql_ctx)
659  {
661  "Failed to create mysql context\n");
663  return;
664  }
665 
666  if (GNUNET_OK !=
668  "regex-mysql",
669  "REGEX_PREFIX",
670  &regex_prefix))
671  {
673  "regex-mysql",
674  "REGEX_PREFIX");
676  return;
677  }
678 
679  result = GNUNET_OK;
681  NULL);
683 }
static void do_directory_scan(void *cls)
Iterate over files contained in policy_dir.
static void do_shutdown(void *cls)
Shutdown task.
static const struct GNUNET_CONFIGURATION_Handle * config
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:403
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition: scheduler.c:1334
#define _(String)
GNU gettext support macro.
Definition: platform.h:178

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 
)

Main function.

Parameters
argcargument count
argvargument values
Returns
0 on success

Definition at line 694 of file gnunet-regex-simulation-profiler.c.

695 {
698  "table",
699  "TABLENAME",
700  gettext_noop (
701  "name of the table to write DFAs"),
702  &table_name),
703 
705  "max-path-compression",
706  "MAX_PATH_COMPRESSION",
707  gettext_noop ("maximum path compression length"),
709 
711  };
712  int ret;
713 
714  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
715  return 2;
716 
718  ret =
719  GNUNET_PROGRAM_run (argc, argv,
720  "gnunet-regex-simulationprofiler [OPTIONS] policy-dir",
721  _ ("Profiler for regex library"), options, &run, NULL);
722  if (GNUNET_OK != ret)
723  return ret;
724  if (GNUNET_OK != result)
725  return 1;
726  return 0;
727 }
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define gettext_noop(String)
Definition: gettext.h:70
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.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_uint(char shortName, const char *name, const char *argumentHelp, const char *description, unsigned int *val)
Allow user to specify an unsigned int.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a string.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition: program.c:400
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1222
Definition of a command line option.

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.

Here is the call graph for this function:

Variable Documentation

◆ meter

struct ProgressMeter* meter
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().

◆ scan_task

struct GNUNET_SCHEDULER_Task* scan_task
static

Scan task identifier;.

Definition at line 98 of file gnunet-regex-simulation-profiler.c.

Referenced by do_abort(), do_directory_scan(), and run().

◆ result

int result
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().

◆ mysql_ctx

struct GNUNET_MYSQL_Context* mysql_ctx
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().

◆ stmt_handle

struct GNUNET_MYSQL_StatementHandle* stmt_handle
static

MySQL prepared statement handle.

Definition at line 113 of file gnunet-regex-simulation-profiler.c.

Referenced by do_directory_scan(), and regex_iterator().

◆ select_stmt_handle

struct GNUNET_MYSQL_StatementHandle* select_stmt_handle
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().

◆ table_name

char* table_name
static

MySQL table name.

Definition at line 123 of file gnunet-regex-simulation-profiler.c.

Referenced by do_directory_scan(), main(), and run().

◆ policy_dir

char* policy_dir
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().

◆ num_policy_files

unsigned int num_policy_files
static

Number of policy files.

Definition at line 133 of file gnunet-regex-simulation-profiler.c.

Referenced by do_directory_scan(), and run().

◆ num_policies

unsigned int num_policies
static

Number of policies.

Definition at line 138 of file gnunet-regex-simulation-profiler.c.

Referenced by do_directory_scan(), and policy_filename_cb().

◆ max_path_compression

unsigned int max_path_compression
static

Maximal path compression length.

Definition at line 143 of file gnunet-regex-simulation-profiler.c.

Referenced by announce_regex(), and main().

◆ num_merged_transitions

unsigned long long num_merged_transitions
static

Number of merged transitions.

Definition at line 148 of file gnunet-regex-simulation-profiler.c.

Referenced by do_directory_scan(), and regex_iterator().

◆ num_merged_states

unsigned long long num_merged_states
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().

◆ regex_prefix

char* regex_prefix
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().