diff options
author | Christophe Genevey Metat <genevey.christophe@gmail.com> | 2016-06-27 14:39:42 +0000 |
---|---|---|
committer | Christophe Genevey Metat <genevey.christophe@gmail.com> | 2016-06-27 14:39:42 +0000 |
commit | 6f9c566127d0737ecd529f458dc28b7fc02e6eb9 (patch) | |
tree | fffca5ca50c684904ad498443a0862f8b0cab9b0 /src/regex/gnunet-regex-simulation-profiler.c | |
parent | 71a483b672933fb1de45aebb7869a06bc63f09be (diff) | |
download | gnunet-6f9c566127d0737ecd529f458dc28b7fc02e6eb9.tar.gz gnunet-6f9c566127d0737ecd529f458dc28b7fc02e6eb9.zip |
adapt gnunet-regex-simulation-profiler to libgnunetmy
Diffstat (limited to 'src/regex/gnunet-regex-simulation-profiler.c')
-rw-r--r-- | src/regex/gnunet-regex-simulation-profiler.c | 131 |
1 files changed, 59 insertions, 72 deletions
diff --git a/src/regex/gnunet-regex-simulation-profiler.c b/src/regex/gnunet-regex-simulation-profiler.c index 585d528b7..d9d02bca7 100644 --- a/src/regex/gnunet-regex-simulation-profiler.c +++ b/src/regex/gnunet-regex-simulation-profiler.c | |||
@@ -23,6 +23,7 @@ | |||
23 | * @brief Regex profiler that dumps all DFAs into a database instead of | 23 | * @brief Regex profiler that dumps all DFAs into a database instead of |
24 | * using the DHT (with cadet). | 24 | * using the DHT (with cadet). |
25 | * @author Maximilian Szengel | 25 | * @author Maximilian Szengel |
26 | * @author Christophe Genevey | ||
26 | * | 27 | * |
27 | */ | 28 | */ |
28 | 29 | ||
@@ -30,6 +31,7 @@ | |||
30 | #include "gnunet_util_lib.h" | 31 | #include "gnunet_util_lib.h" |
31 | #include "regex_internal_lib.h" | 32 | #include "regex_internal_lib.h" |
32 | #include "gnunet_mysql_lib.h" | 33 | #include "gnunet_mysql_lib.h" |
34 | #include "gnunet_my_lib.h" | ||
33 | #include <mysql/mysql.h> | 35 | #include <mysql/mysql.h> |
34 | 36 | ||
35 | /** | 37 | /** |
@@ -302,25 +304,6 @@ do_abort (void *cls) | |||
302 | GNUNET_SCHEDULER_shutdown (); | 304 | GNUNET_SCHEDULER_shutdown (); |
303 | } | 305 | } |
304 | 306 | ||
305 | |||
306 | /** | ||
307 | * Dummy function for prepared select. Always returns #GNUNET_OK. | ||
308 | * | ||
309 | * @param cls closure | ||
310 | * @param num_values number of values. | ||
311 | * @param values returned values from select stmt. | ||
312 | * | ||
313 | * @return #GNUNET_OK | ||
314 | */ | ||
315 | static int | ||
316 | return_ok (void *cls, | ||
317 | unsigned int num_values, | ||
318 | MYSQL_BIND * values) | ||
319 | { | ||
320 | return GNUNET_OK; | ||
321 | } | ||
322 | |||
323 | |||
324 | /** | 307 | /** |
325 | * Iterator over all states that inserts each state into the MySQL db. | 308 | * Iterator over all states that inserts each state into the MySQL db. |
326 | * | 309 | * |
@@ -333,44 +316,37 @@ return_ok (void *cls, | |||
333 | */ | 316 | */ |
334 | static void | 317 | static void |
335 | regex_iterator (void *cls, | 318 | regex_iterator (void *cls, |
336 | const struct GNUNET_HashCode *key, | 319 | const struct GNUNET_HashCode *key, |
337 | const char *proof, | 320 | const char *proof, |
338 | int accepting, | 321 | int accepting, |
339 | unsigned int num_edges, | 322 | unsigned int num_edges, |
340 | const struct REGEX_BLOCK_Edge *edges) | 323 | const struct REGEX_BLOCK_Edge *edges) |
341 | { | 324 | { |
342 | unsigned int i; | 325 | unsigned int i; |
343 | int result; | 326 | int result; |
344 | unsigned long k_length; | 327 | |
345 | unsigned long e_length; | 328 | uint32_t iaccepting = (uint32_t)accepting; |
346 | unsigned long d_length; | 329 | uint64_t total; |
347 | MYSQL_BIND rbind[1]; | ||
348 | unsigned long long total; | ||
349 | 330 | ||
350 | GNUNET_assert (NULL != mysql_ctx); | 331 | GNUNET_assert (NULL != mysql_ctx); |
351 | 332 | ||
352 | for (i = 0; i < num_edges; i++) | 333 | for (i = 0; i < num_edges; i++) |
353 | { | 334 | { |
354 | k_length = sizeof (struct GNUNET_HashCode); | 335 | struct GNUNET_MY_QueryParam params_select[] = { |
355 | e_length = strlen (edges[i].label); | 336 | GNUNET_MY_query_param_auto_from_type (key), |
356 | d_length = sizeof (struct GNUNET_HashCode); | 337 | GNUNET_MY_query_param_fixed_size(edges[i].label, strlen (edges[i].label)), |
357 | memset (rbind, 0, sizeof (rbind)); | 338 | GNUNET_MY_query_param_end |
358 | total = -1; | 339 | }; |
359 | rbind[0].buffer_type = MYSQL_TYPE_LONGLONG; | 340 | |
360 | rbind[0].buffer = &total; | 341 | struct GNUNET_MY_ResultSpec results_select[] = { |
361 | rbind[0].is_unsigned = GNUNET_YES; | 342 | GNUNET_MY_result_spec_uint64 (&total), |
362 | 343 | GNUNET_MY_result_spec_end | |
363 | result = | 344 | }; |
364 | GNUNET_MYSQL_statement_run_prepared_select (select_stmt_handle, 1, | 345 | |
365 | rbind, &return_ok, NULL, | 346 | result = |
366 | MYSQL_TYPE_BLOB, key, | 347 | GNUNET_MY_exec_prepared (mysql_ctx, |
367 | sizeof (struct | 348 | select_stmt_handle, |
368 | GNUNET_HashCode), | 349 | params_select); |
369 | &k_length, | ||
370 | MYSQL_TYPE_STRING, | ||
371 | edges[i].label, | ||
372 | strlen (edges[i].label), | ||
373 | &e_length, -1); | ||
374 | 350 | ||
375 | if (GNUNET_SYSERR == result) | 351 | if (GNUNET_SYSERR == result) |
376 | { | 352 | { |
@@ -380,24 +356,36 @@ regex_iterator (void *cls, | |||
380 | return; | 356 | return; |
381 | } | 357 | } |
382 | 358 | ||
359 | result = | ||
360 | GNUNET_MY_extract_result (select_stmt_handle, | ||
361 | results_select); | ||
362 | |||
363 | if (GNUNET_SYSERR == result) | ||
364 | { | ||
365 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
366 | "Error extracting result mysql select statement\n"); | ||
367 | GNUNET_SCHEDULER_add_now (&do_abort, NULL); | ||
368 | return; | ||
369 | } | ||
370 | |||
383 | if (-1 != total && total > 0) | 371 | if (-1 != total && total > 0) |
384 | { | 372 | { |
385 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Total: %llu (%s, %s)\n", total, | 373 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Total: %llu (%s, %s)\n", total, |
386 | GNUNET_h2s (key), edges[i].label); | 374 | GNUNET_h2s (key), edges[i].label); |
387 | } | 375 | } |
388 | 376 | ||
389 | result = | 377 | struct GNUNET_MY_QueryParam params_stmt[] = { |
390 | GNUNET_MYSQL_statement_run_prepared (stmt_handle, NULL, | 378 | GNUNET_MY_query_param_auto_from_type (&key), |
391 | MYSQL_TYPE_BLOB, key, | 379 | GNUNET_MY_query_param_fixed_size (edges[i].label, strlen (edges[i].label)), |
392 | sizeof (struct GNUNET_HashCode), | 380 | GNUNET_MY_query_param_auto_from_type (&edges[i].destination), |
393 | &k_length, MYSQL_TYPE_STRING, | 381 | GNUNET_MY_query_param_uint32 (&iaccepting), |
394 | edges[i].label, | 382 | GNUNET_MY_query_param_end |
395 | strlen (edges[i].label), &e_length, | 383 | }; |
396 | MYSQL_TYPE_BLOB, | 384 | |
397 | &edges[i].destination, | 385 | result = |
398 | sizeof (struct GNUNET_HashCode), | 386 | GNUNET_MY_exec_prepared (mysql_ctx, |
399 | &d_length, MYSQL_TYPE_LONG, | 387 | stmt_handle, |
400 | &accepting, GNUNET_YES, -1); | 388 | params_stmt); |
401 | 389 | ||
402 | if (0 == result) | 390 | if (0 == result) |
403 | { | 391 | { |
@@ -426,19 +414,18 @@ regex_iterator (void *cls, | |||
426 | 414 | ||
427 | if (0 == num_edges) | 415 | if (0 == num_edges) |
428 | { | 416 | { |
429 | k_length = sizeof (struct GNUNET_HashCode); | 417 | struct GNUNET_MY_QueryParam params_stmt[] = { |
430 | e_length = 0; | 418 | GNUNET_MY_query_param_auto_from_type (key), |
431 | d_length = 0; | 419 | GNUNET_MY_query_param_fixed_size (NULL, 0), |
432 | 420 | GNUNET_MY_query_param_auto_from_type (NULL), | |
433 | result = | 421 | GNUNET_MY_query_param_uint32 (&iaccepting), |
434 | GNUNET_MYSQL_statement_run_prepared (stmt_handle, NULL, | 422 | GNUNET_MY_query_param_end |
435 | MYSQL_TYPE_BLOB, key, | 423 | }; |
436 | sizeof (struct GNUNET_HashCode), | 424 | |
437 | &k_length, MYSQL_TYPE_STRING, NULL, | 425 | result = |
438 | 0, &e_length, MYSQL_TYPE_BLOB, | 426 | GNUNET_MY_exec_prepared(mysql_ctx, |
439 | NULL, 0, &d_length, | 427 | stmt_handle, |
440 | MYSQL_TYPE_LONG, &accepting, | 428 | params_stmt); |
441 | GNUNET_YES, -1); | ||
442 | 429 | ||
443 | if (1 != result && 0 != result) | 430 | if (1 != result && 0 != result) |
444 | { | 431 | { |