aboutsummaryrefslogtreecommitdiff
path: root/src/regex/gnunet-regex-simulation-profiler.c
diff options
context:
space:
mode:
authorMaximilian Szengel <gnunet@maxsz.de>2012-10-26 16:10:04 +0000
committerMaximilian Szengel <gnunet@maxsz.de>2012-10-26 16:10:04 +0000
commitf4e425272b12649edd919ab408501e1aa3a072bd (patch)
tree863d7dfc2db524a698323227bfd36270ddff7a14 /src/regex/gnunet-regex-simulation-profiler.c
parent9b141acb9c06621c4a2966c0b3c120f4f5276b0d (diff)
downloadgnunet-f4e425272b12649edd919ab408501e1aa3a072bd.tar.gz
gnunet-f4e425272b12649edd919ab408501e1aa3a072bd.zip
using prepared statements for regex simulation profiler
Diffstat (limited to 'src/regex/gnunet-regex-simulation-profiler.c')
-rw-r--r--src/regex/gnunet-regex-simulation-profiler.c79
1 files changed, 67 insertions, 12 deletions
diff --git a/src/regex/gnunet-regex-simulation-profiler.c b/src/regex/gnunet-regex-simulation-profiler.c
index 14d0d6b07..74e88ea9f 100644
--- a/src/regex/gnunet-regex-simulation-profiler.c
+++ b/src/regex/gnunet-regex-simulation-profiler.c
@@ -30,6 +30,11 @@
30#include "gnunet_util_lib.h" 30#include "gnunet_util_lib.h"
31#include "gnunet_regex_lib.h" 31#include "gnunet_regex_lib.h"
32#include "gnunet_mysql_lib.h" 32#include "gnunet_mysql_lib.h"
33#include <mysql/mysql.h>
34
35#define INSERT_EDGE_STMT "INSERT IGNORE INTO `%s` "\
36 "(`key`, `label`, `to_key`, `accepting`) "\
37 "VALUES (?, ?, ?, ?);"
33 38
34/** 39/**
35 * Simple struct to keep track of progress, and print a 40 * Simple struct to keep track of progress, and print a
@@ -77,6 +82,11 @@ static int result;
77static struct GNUNET_MYSQL_Context *mysql_ctx; 82static struct GNUNET_MYSQL_Context *mysql_ctx;
78 83
79/** 84/**
85 * MySQL prepared statement handle.
86 */
87static struct GNUNET_MYSQL_StatementHandle *stmt_handle;
88
89/**
80 * MySQL table name. 90 * MySQL table name.
81 */ 91 */
82static char *table_name; 92static char *table_name;
@@ -259,27 +269,64 @@ regex_iterator (void *cls,
259 unsigned int num_edges, 269 unsigned int num_edges,
260 const struct GNUNET_REGEX_Edge *edges) 270 const struct GNUNET_REGEX_Edge *edges)
261{ 271{
262 char *stmt;
263 unsigned int i; 272 unsigned int i;
273 int result;
274 unsigned long k_length;
275 unsigned long e_length;
276 unsigned long d_length;
264 277
265 GNUNET_assert (NULL != mysql_ctx); 278 GNUNET_assert (NULL != mysql_ctx);
266 279
267 for (i = 0; i < num_edges; i++) 280 for (i = 0; i < num_edges; i++)
268 { 281 {
269 GNUNET_asprintf (&stmt, 282 k_length = sizeof (struct GNUNET_HashCode);
270 "INSERT IGNORE INTO `%s` (`key`, `label`, `to_key`, `accepting`) VALUES ('%s', '%s', '%s', '%d');", 283 e_length = strlen (edges[i].label);
271 table_name, GNUNET_h2s_full (key), edges[i].label, 284 d_length = sizeof (struct GNUNET_HashCode);
272 GNUNET_h2s_full (&edges[i].destination), accepting); 285
273 286 result =
274 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Insert statement: %s\n", stmt); 287 GNUNET_MYSQL_statement_run_prepared (
275 288 mysql_ctx,
276 if (GNUNET_OK != GNUNET_MYSQL_statement_run (mysql_ctx, stmt)) 289 stmt_handle,
290 NULL,
291 MYSQL_TYPE_BLOB, key, sizeof (struct GNUNET_HashCode), &k_length,
292 MYSQL_TYPE_STRING, edges[i].label, strlen (edges[i].label), &e_length,
293 MYSQL_TYPE_BLOB, &edges[i].destination, sizeof (struct GNUNET_HashCode), &d_length,
294 MYSQL_TYPE_LONG, &accepting, GNUNET_YES,
295 -1);
296
297 if (1 != result && 0 != result)
277 { 298 {
278 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 299 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
279 "Error executing mysql statement: %s\n", stmt); 300 "Error executing prepared mysql statement for edge: Affected rows: %i, expected 0 or 1!\n",
301 result);
302 GNUNET_SCHEDULER_add_now (&do_abort, NULL);
280 } 303 }
304 }
281 305
282 GNUNET_free (stmt); 306 if (0 == num_edges)
307 {
308 k_length = sizeof (struct GNUNET_HashCode);
309 e_length = 0;
310 d_length = 0;
311
312 result =
313 GNUNET_MYSQL_statement_run_prepared (
314 mysql_ctx,
315 stmt_handle,
316 NULL,
317 MYSQL_TYPE_BLOB, key, sizeof (struct GNUNET_HashCode), &k_length,
318 MYSQL_TYPE_STRING, NULL, 0, &e_length,
319 MYSQL_TYPE_BLOB, NULL, 0, &d_length,
320 MYSQL_TYPE_LONG, &accepting, GNUNET_YES,
321 -1);
322
323 if (1 != result && 0 != result)
324 {
325 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
326 "Error executing prepared mysql statement for edge: Affected rows: %i, expected 0 or 1!\n",
327 result);
328 GNUNET_SCHEDULER_add_now (&do_abort, NULL);
329 }
283 } 330 }
284} 331}
285 332
@@ -403,15 +450,23 @@ do_directory_scan (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
403{ 450{
404 struct GNUNET_TIME_Absolute start_time; 451 struct GNUNET_TIME_Absolute start_time;
405 struct GNUNET_TIME_Relative duration; 452 struct GNUNET_TIME_Relative duration;
453 char *stmt;
406 454
407 if (GNUNET_SCHEDULER_NO_TASK != abort_task) 455 if (GNUNET_SCHEDULER_NO_TASK != abort_task)
408 GNUNET_SCHEDULER_cancel (abort_task); 456 GNUNET_SCHEDULER_cancel (abort_task);
409 457
458 /* Create an MySQL prepared statement for the inserts */
459 GNUNET_asprintf (&stmt, INSERT_EDGE_STMT, table_name);
460 stmt_handle = GNUNET_MYSQL_statement_prepare (mysql_ctx, stmt);
461 GNUNET_free (stmt);
462
463 GNUNET_assert (NULL != stmt_handle);
464
410 meter = create_meter (num_policy_files, "Announcing policy files\n", GNUNET_YES); 465 meter = create_meter (num_policy_files, "Announcing policy files\n", GNUNET_YES);
411 start_time = GNUNET_TIME_absolute_get (); 466 start_time = GNUNET_TIME_absolute_get ();
412 GNUNET_DISK_directory_scan (policy_dir, 467 GNUNET_DISK_directory_scan (policy_dir,
413 &policy_filename_cb, 468 &policy_filename_cb,
414 NULL); 469 stmt_handle);
415 duration = GNUNET_TIME_absolute_get_duration (start_time); 470 duration = GNUNET_TIME_absolute_get_duration (start_time);
416 reset_meter (meter); 471 reset_meter (meter);
417 free_meter (meter); 472 free_meter (meter);