GNUnet  0.10.x
Data Structures | Macros | Functions | Variables
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_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_Contextmysql_ctx
 MySQL context. More...
 
static struct GNUNET_MYSQL_StatementHandlestmt_handle
 MySQL prepared statement handle. More...
 
static struct GNUNET_MYSQL_StatementHandleselect_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 41 of file gnunet-regex-simulation-profiler.c.

Referenced by do_directory_scan().

◆ 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 48 of file gnunet-regex-simulation-profiler.c.

Referenced by do_directory_scan().

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 171 of file gnunet-regex-simulation-profiler.c.

References ProgressMeter::dotnum, GNUNET_new, GNUNET_strdup, ProgressMeter::modnum, ProgressMeter::print, ret, ProgressMeter::startup_string, and ProgressMeter::total.

Referenced by do_directory_scan().

172 {
173  struct ProgressMeter *ret;
174 
175  ret = GNUNET_new (struct ProgressMeter);
176  ret->print = print;
177  ret->total = total;
178  ret->modnum = total / 4;
179  if (ret->modnum == 0) /* Divide by zero check */
180  ret->modnum = 1;
181  ret->dotnum = (total / 50) + 1;
182  if (start_string != NULL)
183  ret->startup_string = GNUNET_strdup (start_string);
184  else
185  ret->startup_string = GNUNET_strdup ("");
186 
187  return ret;
188 }
Simple struct to keep track of progress, and print a nice little percentage meter for long running ta...
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
unsigned int modnum
Intervall for printing percentage.
int print
Should the meter be printed?
unsigned int dotnum
Number of dots to print.
unsigned int total
Total number of elements.
char * startup_string
String to print on startup.
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 200 of file gnunet-regex-simulation-profiler.c.

References ProgressMeter::completed, ProgressMeter::dotnum, FPRINTF, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_NO, GNUNET_YES, ProgressMeter::modnum, ProgressMeter::print, ProgressMeter::startup_string, and ProgressMeter::total.

Referenced by policy_filename_cb().

201 {
202  if (meter->print == GNUNET_YES)
203  {
204  if (meter->completed % meter->modnum == 0)
205  {
206  if (meter->completed == 0)
207  {
208  FPRINTF (stdout, "%sProgress: [0%%", meter->startup_string);
209  }
210  else
211  FPRINTF (stdout, "%d%%",
212  (int) (((float) meter->completed / meter->total) * 100));
213  }
214  else if (meter->completed % meter->dotnum == 0)
215  FPRINTF (stdout, "%s", ".");
216 
217  if (meter->completed + 1 == meter->total)
218  FPRINTF (stdout, "%d%%]\n", 100);
219  fflush (stdout);
220  }
221  meter->completed++;
222 
223  if (meter->completed == meter->total)
224  return GNUNET_YES;
225  if (meter->completed > meter->total)
226  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Progress meter overflow!!\n");
227  return GNUNET_NO;
228 }
#define FPRINTF
Definition: plibc.h:683
#define GNUNET_NO
Definition: gnunet_common.h:81
unsigned int modnum
Intervall for printing percentage.
unsigned int completed
Completed number.
int print
Should the meter be printed?
#define GNUNET_log(kind,...)
unsigned int dotnum
Number of dots to print.
unsigned int total
Total number of elements.
#define GNUNET_YES
Definition: gnunet_common.h:80
char * startup_string
String to print on startup.
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 240 of file gnunet-regex-simulation-profiler.c.

References ProgressMeter::completed, GNUNET_SYSERR, and GNUNET_YES.

Referenced by do_directory_scan().

241 {
242  if (meter == NULL)
243  return GNUNET_SYSERR;
244 
245  meter->completed = 0;
246  return GNUNET_YES;
247 }
unsigned int completed
Completed number.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define GNUNET_YES
Definition: gnunet_common.h:80
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 256 of file gnunet-regex-simulation-profiler.c.

References GNUNET_free, GNUNET_free_non_null, and ProgressMeter::startup_string.

Referenced by do_directory_scan(), and do_shutdown().

257 {
259  GNUNET_free (meter);
260 }
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
char * startup_string
String to print on startup.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ do_shutdown()

static void do_shutdown ( void *  cls)
static

Shutdown task.

Parameters
clsNULL

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

References free_meter(), and GNUNET_MYSQL_context_destroy().

Referenced by run().

270 {
271  if (NULL != mysql_ctx)
272  {
274  mysql_ctx = NULL;
275  }
276  if (NULL != meter)
277  {
278  free_meter (meter);
279  meter = NULL;
280  }
281 }
static struct GNUNET_MYSQL_Context * mysql_ctx
MySQL context.
void GNUNET_MYSQL_context_destroy(struct GNUNET_MYSQL_Context *mc)
Destroy a mysql context.
Definition: mysql.c:379
static struct ProgressMeter * meter
Handle for the progress meter.
static void free_meter(struct ProgressMeter *meter)
Release resources for meter.
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 296 of file gnunet-regex-simulation-profiler.c.

References GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_SCHEDULER_cancel(), GNUNET_SCHEDULER_shutdown(), GNUNET_SYSERR, and result.

Referenced by announce_regex(), and regex_iterator().

297 {
298  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Aborting\n");
299  if (NULL != scan_task)
300  {
302  scan_task = NULL;
303  }
306 }
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:524
static struct GNUNET_SCHEDULER_Task * scan_task
Scan task identifier;.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define GNUNET_log(kind,...)
static int result
Global testing status.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
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 319 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_MY_exec_prepared(), GNUNET_MY_extract_result(), GNUNET_MY_query_param_auto_from_type, GNUNET_MY_query_param_end, GNUNET_MY_query_param_fixed_size(), GNUNET_MY_query_param_string(), GNUNET_MY_query_param_uint32(), GNUNET_MY_result_spec_end, GNUNET_MY_result_spec_uint64(), GNUNET_SCHEDULER_add_now(), GNUNET_strdup, GNUNET_SYSERR, num_merged_states, num_merged_transitions, result, and ProgressMeter::total.

Referenced by announce_regex().

325 {
326  unsigned int i;
327  int result;
328 
329  uint32_t iaccepting = (uint32_t)accepting;
330  uint64_t total;
331 
332  GNUNET_assert (NULL != mysql_ctx);
333 
334  for (i = 0; i < num_edges; i++)
335  {
336  struct GNUNET_MY_QueryParam params_select[] = {
338  GNUNET_MY_query_param_string (edges[i].label),
340  };
341 
342  struct GNUNET_MY_ResultSpec results_select[] = {
345  };
346 
347  result =
350  params_select);
351 
352  if (GNUNET_SYSERR == result)
353  {
355  "Error executing prepared mysql select statement\n");
357  return;
358  }
359 
360  result =
362  results_select);
363 
364  if (GNUNET_SYSERR == result)
365  {
367  "Error extracting result mysql select statement\n");
369  return;
370  }
371 
372  if (-1 != total && total > 0)
373  {
374  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Total: %llu (%s, %s)\n",
375  (unsigned long long)total,
376  GNUNET_h2s (key), edges[i].label);
377  }
378 
379  struct GNUNET_MY_QueryParam params_stmt[] = {
381  GNUNET_MY_query_param_string (edges[i].label),
382  GNUNET_MY_query_param_auto_from_type (&edges[i].destination),
383  GNUNET_MY_query_param_uint32 (&iaccepting),
385  };
386 
387  result =
389  stmt_handle,
390  params_stmt);
391 
392  if (0 == result)
393  {
394  char *key_str = GNUNET_strdup (GNUNET_h2s (key));
395  char *to_key_str = GNUNET_strdup (GNUNET_h2s (&edges[i].destination));
396 
397  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Merged (%s, %s, %s, %i)\n",
398  key_str,
399  edges[i].label,
400  to_key_str,
401  accepting);
402 
403  GNUNET_free (key_str);
404  GNUNET_free (to_key_str);
406  }
407  else if (-1 != total)
408  {
410  }
411 
412  if (GNUNET_SYSERR == result || (1 != result && 0 != result))
413  {
415  "Error executing prepared mysql statement for edge: Affected rows: %i, expected 0 or 1!\n",
416  result);
418  }
419  }
420 
421  if (0 == num_edges)
422  {
423  struct GNUNET_MY_QueryParam params_stmt[] = {
427  GNUNET_MY_query_param_uint32 (&iaccepting),
429  };
430 
431  result =
433  stmt_handle,
434  params_stmt);
435 
436  if (1 != result && 0 != result)
437  {
439  "Error executing prepared mysql statement for edge: Affected rows: %i, expected 0 or 1!\n",
440  result);
442  }
443  }
444 }
#define GNUNET_MY_query_param_auto_from_type(x)
Generate fixed-size query parameter with size determined by variable type.
#define GNUNET_MY_result_spec_end
End of result speceter specification.
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_uint64(uint64_t *u64)
uint64_t expected.
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_fixed_size(const void *ptr, size_t ptr_size)
Generate query parameter for a buffer ptr of ptr_size bytes.FG.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static unsigned long long num_merged_transitions
Number of merged transitions.
Information we pass to GNUNET_MY_exec_prepared() to initialize the arguments of the prepared statemen...
Definition: gnunet_my_lib.h:84
static unsigned long long num_merged_states
Number of merged states from different policies.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
int GNUNET_MY_exec_prepared(struct GNUNET_MYSQL_Context *mc, struct GNUNET_MYSQL_StatementHandle *sh, struct GNUNET_MY_QueryParam *params)
Run a prepared SELECT statement.
Definition: my.c:42
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static struct GNUNET_MYSQL_Context * mysql_ctx
MySQL context.
Information we pass to GNUNET_MY_extract_result() to initialize the arguments of the prepared stateme...
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:1273
int GNUNET_MY_extract_result(struct GNUNET_MYSQL_StatementHandle *sh, struct GNUNET_MY_ResultSpec *specs)
Extract results from a query result according to the given specification.
Definition: my.c:136
#define GNUNET_MY_query_param_end
End of query parameter specification.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_uint32(const uint32_t *x)
Generate query parameter for an uint32_t in host byte order.
#define GNUNET_log(kind,...)
static int result
Global testing status.
static struct GNUNET_MYSQL_StatementHandle * stmt_handle
MySQL prepared statement handle.
unsigned int total
Total number of elements.
static void do_abort(void *cls)
Abort task to run on test timed out.
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_string(const char *ptr)
Generate query parameter for a string.
static struct GNUNET_MYSQL_StatementHandle * select_stmt_handle
MySQL prepared statement handle for key select.
#define GNUNET_free(ptr)
Wrapper around free.
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 455 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_destroy(), REGEX_INTERNAL_construct_dfa(), REGEX_INTERNAL_iterate_all_edges(), and regex_iterator().

Referenced by policy_filename_cb().

456 {
457  struct REGEX_INTERNAL_Automaton *dfa;
458 
459  dfa =
461  strlen (regex),
463 
464  if (NULL == dfa)
465  {
467  "Failed to create DFA for regex %s\n",
468  regex);
470  return GNUNET_SYSERR;
471  }
473  &regex_iterator, NULL);
475 
476  return GNUNET_OK;
477 }
static unsigned int max_path_compression
Maximal path compression length.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
Automaton representation.
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.
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:1273
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
void REGEX_INTERNAL_automaton_destroy(struct REGEX_INTERNAL_Automaton *a)
Free the memory allocated by constructing the REGEX_INTERNAL_Automaton data structure.
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 &#39;a&#39;.
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 &#39;regex&#39; of length &#39;len&#39;.
#define GNUNET_log(kind,...)
static void do_abort(void *cls)
Abort task to run on test timed out.
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 489 of file gnunet-regex-simulation-profiler.c.

References announce_regex(), buf, data, 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, num_policies, REGEX_INTERNAL_Automaton::regex, regex_prefix, and update_meter().

Referenced by do_directory_scan().

490 {
491  char *regex;
492  char *data;
493  char *buf;
494  uint64_t filesize;
495  unsigned int offset;
496 
497  GNUNET_assert (NULL != filename);
498 
500  "Announcing regexes from file %s\n",
501  filename);
502 
504  {
506  "Could not find policy file %s\n",
507  filename);
508  return GNUNET_OK;
509  }
510  if (GNUNET_OK !=
511  GNUNET_DISK_file_size (filename, &filesize,
513  filesize = 0;
514  if (0 == filesize)
515  {
516  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Policy file %s is empty.\n",
517  filename);
518  return GNUNET_OK;
519  }
520  data = GNUNET_malloc (filesize);
521  if (filesize != GNUNET_DISK_fn_read (filename, data, filesize))
522  {
523  GNUNET_free (data);
525  "Could not read policy file %s.\n",
526  filename);
527  return GNUNET_OK;
528  }
529 
531 
532  buf = data;
533  offset = 0;
534  regex = NULL;
535  while (offset < (filesize - 1))
536  {
537  offset++;
538  if (((data[offset] == '\n')) && (buf != &data[offset]))
539  {
540  data[offset] = '|';
541  num_policies++;
542  buf = &data[offset + 1];
543  }
544  else if ((data[offset] == '\n') || (data[offset] == '\0'))
545  buf = &data[offset + 1];
546  }
547  data[offset] = '\0';
548  GNUNET_asprintf (&regex, "%s(%s)", regex_prefix, data);
549  GNUNET_assert (NULL != regex);
551  "Announcing regex: %s\n", regex);
552 
553  if (GNUNET_OK != announce_regex (regex))
554  {
556  "Could not announce regex %s\n",
557  regex);
558  }
559  GNUNET_free (regex);
560  GNUNET_free (data);
561  return GNUNET_OK;
562 }
int 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:669
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...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
static struct ProgressMeter * meter
Handle for the progress meter.
static char buf[2048]
static char * filename
static unsigned int num_policies
Number of policies.
int 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:289
static int update_meter(struct ProgressMeter *meter)
Update progress meter (increment by one).
#define GNUNET_log(kind,...)
static char * regex_prefix
Prefix to add before every regex we&#39;re announcing.
#define GNUNET_YES
Definition: gnunet_common.h:80
uint32_t data
The data value.
#define GNUNET_malloc(size)
Wrapper around malloc.
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:1019
#define GNUNET_free(ptr)
Wrapper around free.
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 571 of file gnunet-regex-simulation-profiler.c.

References create_meter(), free_meter(), GNUNET_asprintf(), GNUNET_assert, GNUNET_DISK_directory_scan(), GNUNET_free, GNUNET_MYSQL_statement_prepare(), 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, num_merged_states, num_merged_transitions, num_policies, num_policy_files, policy_dir, policy_filename_cb(), reset_meter(), result, SELECT_KEY_STMT, and table_name.

Referenced by run().

572 {
575  char *stmt;
576 
577  /* Create an MySQL prepared statement for the inserts */
578  scan_task = NULL;
581  GNUNET_free (stmt);
582 
585  GNUNET_free (stmt);
586 
587  GNUNET_assert (NULL != stmt_handle);
588 
590  "Announcing policy files\n",
591  GNUNET_YES);
595  stmt_handle);
597  reset_meter (meter);
598  free_meter (meter);
599  meter = NULL;
600 
601  printf ("Announced %u files containing %u policies in %s\n"
602  "Duplicate transitions: %llu\nMerged states: %llu\n",
604  num_policies,
608  result = GNUNET_OK;
610 }
static char * table_name
MySQL table name.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define INSERT_EDGE_STMT
MySQL statement to insert an edge.
static unsigned long long num_merged_transitions
Number of merged transitions.
#define GNUNET_NO
Definition: gnunet_common.h:81
static unsigned long long num_merged_states
Number of merged states from different policies.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static int reset_meter(struct ProgressMeter *meter)
Reset progress meter.
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:1233
static unsigned int num_policy_files
Number of policy files.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:524
static char * policy_dir
Policy dir containing files that contain policies.
static struct GNUNET_MYSQL_Context * mysql_ctx
MySQL context.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
static struct ProgressMeter * meter
Handle for the progress meter.
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:727
static struct GNUNET_SCHEDULER_Task * scan_task
Scan task identifier;.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
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 unsigned int num_policies
Number of policies.
#define SELECT_KEY_STMT
MySQL statement to select a key count.
static void free_meter(struct ProgressMeter *meter)
Release resources for meter.
struct GNUNET_MYSQL_StatementHandle * GNUNET_MYSQL_statement_prepare(struct GNUNET_MYSQL_Context *mc, const char *query)
Prepare a statement.
Definition: mysql.c:404
static int policy_filename_cb(void *cls, const char *filename)
Function called with a filename.
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:373
static int result
Global testing status.
static struct GNUNET_MYSQL_StatementHandle * stmt_handle
MySQL prepared statement handle.
static struct GNUNET_TIME_Relative duration
How long do we run the test?
Time for absolute times used by GNUnet, in microseconds.
#define GNUNET_YES
Definition: gnunet_common.h:80
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_MYSQL_StatementHandle * select_stmt_handle
MySQL prepared statement handle for key select.
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
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 622 of file gnunet-regex-simulation-profiler.c.

References _, 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_MYSQL_context_create(), GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SYSERR, GNUNET_YES, num_policy_files, policy_dir, regex_prefix, result, and table_name.

Referenced by main().

626 {
627  if (NULL == args[0])
628  {
629  fprintf (stderr,
630  _("No policy directory specified on command line. Exiting.\n"));
632  return;
633  }
634  if (GNUNET_YES !=
636  {
637  fprintf (stderr,
638  _("Specified policies directory does not exist. Exiting.\n"));
640  return;
641  }
642  policy_dir = args[0];
643 
645  NULL, NULL);
646  meter = NULL;
647 
648  if (NULL == table_name)
649  {
651  "No table name specified, using default \"NFA\".\n");
652  table_name = "NFA";
653  }
654 
655  mysql_ctx = GNUNET_MYSQL_context_create (config, "regex-mysql");
656  if (NULL == mysql_ctx)
657  {
659  "Failed to create mysql context\n");
661  return;
662  }
663 
664  if (GNUNET_OK !=
666  "regex-mysql",
667  "REGEX_PREFIX",
668  &regex_prefix))
669  {
671  "regex-mysql",
672  "REGEX_PREFIX");
674  return;
675  }
676 
677  result = GNUNET_OK;
679  NULL);
681 }
static char * table_name
MySQL table name.
struct GNUNET_MYSQL_Context * GNUNET_MYSQL_context_create(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Create a mysql context.
Definition: mysql.c:331
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, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1293
static void do_directory_scan(void *cls)
Iterate over files contained in policy_dir.
int GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:628
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:1233
static unsigned int num_policy_files
Number of policy files.
static char * policy_dir
Policy dir containing files that contain policies.
static struct GNUNET_MYSQL_Context * mysql_ctx
MySQL context.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
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_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1273
static struct ProgressMeter * meter
Handle for the progress meter.
static struct GNUNET_SCHEDULER_Task * scan_task
Scan task identifier;.
int 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.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static void do_shutdown(void *cls)
Shutdown task.
#define GNUNET_log(kind,...)
static char * regex_prefix
Prefix to add before every regex we&#39;re announcing.
static int result
Global testing status.
#define GNUNET_YES
Definition: gnunet_common.h:80
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 692 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, result, ret, run(), and table_name.

693 {
695 
697  "table",
698  "TABLENAME",
699  gettext_noop ("name of the table to write DFAs"),
700  &table_name),
701 
703  "max-path-compression",
704  "MAX_PATH_COMPRESSION",
705  gettext_noop ("maximum path compression length"),
707 
709  };
710  int ret;
711 
712  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
713  return 2;
714 
716  ret =
717  GNUNET_PROGRAM_run (argc, argv,
718  "gnunet-regex-simulationprofiler [OPTIONS] policy-dir",
719  _("Profiler for regex library"), options, &run, NULL);
720  if (GNUNET_OK != ret)
721  return ret;
722  if (GNUNET_OK != result)
723  return 1;
724  return 0;
725 }
static char * table_name
MySQL table name.
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1521
static unsigned int max_path_compression
Maximal path compression length.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
Definition of a command line option.
static int ret
Final status code.
Definition: gnunet-arm.c:89
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
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.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
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.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static int result
Global testing status.
int 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, parse options).
Definition: program.c:361
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.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:

Variable Documentation

◆ meter

struct ProgressMeter* meter
static

Handle for the progress meter.

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

◆ scan_task

struct GNUNET_SCHEDULER_Task* scan_task
static

Scan task identifier;.

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

◆ result

int result
static

Global testing status.

Definition at line 102 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 107 of file gnunet-regex-simulation-profiler.c.

◆ stmt_handle

struct GNUNET_MYSQL_StatementHandle* stmt_handle
static

MySQL prepared statement handle.

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

◆ select_stmt_handle

struct GNUNET_MYSQL_StatementHandle* select_stmt_handle
static

MySQL prepared statement handle for key select.

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

◆ table_name

char* table_name
static

MySQL table name.

Definition at line 122 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 127 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 132 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 137 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 142 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 147 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 152 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 157 of file gnunet-regex-simulation-profiler.c.

Referenced by policy_filename_cb(), and run().