Skip to content

Commit

Permalink
Trace queries in mysql2 (mysql_send_query)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm1 committed Jan 30, 2011
1 parent bf81f57 commit 46f0c29
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ext/tracers/mysql.c
Expand Up @@ -19,7 +19,9 @@ struct memprof_mysql_stats {

static struct tracer tracer;
static struct memprof_mysql_stats stats;

static int (*orig_real_query)(void *mysql, const char *stmt_str, unsigned long length);
static int (*orig_send_query)(void *mysql, const char *stmt_str, unsigned long length);

static int
real_query_tramp(void *mysql, const char *stmt_str, unsigned long length) {
Expand All @@ -36,6 +38,16 @@ real_query_tramp(void *mysql, const char *stmt_str, unsigned long length) {
return ret;
}

static int
send_query_tramp(void *mysql, const char *stmt_str, unsigned long length) {
int ret;

ret = orig_send_query(mysql, stmt_str, length);
stats.query_calls++;

return ret;
}

static void
mysql_trace_start() {
static int inserted = 0;
Expand All @@ -48,6 +60,10 @@ mysql_trace_start() {
orig_real_query = bin_find_symbol("mysql_real_query", NULL, 1);
if (orig_real_query)
insert_tramp("mysql_real_query", real_query_tramp);

orig_send_query = bin_find_symbol("mysql_send_query", NULL, 1);
if (orig_send_query)
insert_tramp("mysql_send_query", send_query_tramp);
}

static void
Expand Down

0 comments on commit 46f0c29

Please sign in to comment.