Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions apm.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#ifdef APM_DRIVER_SQLITE3
# include "driver_sqlite3.h"
#endif
#ifdef APM_DRIVER_MYSQL
#if defined(APM_DRIVER_MYSQL) || defined(APM_DRIVER_MYSQLND)
# include "driver_mysql.h"
#endif
#ifdef APM_DRIVER_STATSD
Expand Down Expand Up @@ -122,8 +122,20 @@ struct timeval begin_tp;
struct rusage begin_usg;
#endif

static const zend_module_dep apm_deps[] = {
#ifdef APM_DRIVER_SOCKET
ZEND_MOD_REQUIRED("json")
#endif
#ifdef APM_DRIVER_MYSQLND
ZEND_MOD_REQUIRED("mysqlnd")
#endif
ZEND_MOD_END
};

zend_module_entry apm_module_entry = {
STANDARD_MODULE_HEADER,
STANDARD_MODULE_HEADER_EX,
NULL,
apm_deps,
"apm",
NULL,
PHP_MINIT(apm),
Expand Down Expand Up @@ -186,7 +198,7 @@ PHP_INI_BEGIN()
STD_PHP_INI_BOOLEAN("apm.sqlite_process_silenced_events", "1", PHP_INI_PERDIR, OnUpdateBool, sqlite3_process_silenced_events, zend_apm_globals, apm_globals)
#endif

#ifdef APM_DRIVER_MYSQL
#if defined(APM_DRIVER_MYSQL) || defined(APM_DRIVER_MYSQLND)
/* Boolean controlling whether the driver is active or not */
STD_PHP_INI_BOOLEAN("apm.mysql_enabled", "1", PHP_INI_PERDIR, OnUpdateBool, mysql_enabled, zend_apm_globals, apm_globals)
/* Boolean controlling the collection of stats */
Expand Down Expand Up @@ -260,7 +272,7 @@ static PHP_GINIT_FUNCTION(apm)
*next = apm_driver_sqlite3_create();
next = &(*next)->next;
#endif
#ifdef APM_DRIVER_MYSQL
#if defined(APM_DRIVER_MYSQL) || defined(APM_DRIVER_MYSQLND)
*next = apm_driver_mysql_create();
next = &(*next)->next;
#endif
Expand Down Expand Up @@ -457,6 +469,21 @@ PHP_MINFO_FUNCTION(apm)
php_info_print_table_start();
php_info_print_table_row(2, "APM support", "enabled");
php_info_print_table_row(2, "Version", PHP_APM_VERSION);
#ifdef APM_DRIVER_SQLITE3
php_info_print_table_row(2, "Sqlite3 driver", "enabled");
#endif
#ifdef APM_DRIVER_MYSQL
php_info_print_table_row(2, "MySQL driver (mysqlnd)", "enabled");
#endif
#ifdef APM_DRIVER_MYSQLND
php_info_print_table_row(2, "MySQL driver (libmysqlclient)", "enabled");
#endif
#ifdef APM_DRIVER_STATSD
php_info_print_table_row(2, "Statsd driver", "enabled");
#endif
#ifdef APM_DRIVER_SOCKET
php_info_print_table_row(2, "Socket driver", "enabled");
#endif
php_info_print_table_end();

DISPLAY_INI_ENTRIES();
Expand Down
17 changes: 15 additions & 2 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ PHP_ARG_ENABLE(apm, whether to enable apm support,
[ --enable-apm Enable apm support], yes)
PHP_ARG_WITH(sqlite3, enable support for sqlite3,
[ --with-sqlite3=DIR Location of sqlite3 library], yes, no)
PHP_ARG_WITH(mysql, enable support for MySQL,
PHP_ARG_WITH(mysqlnd, enable support for MySQL through mysqlnd,
[ --with-mysqlnd Enable mysqlnd support], no, no)
PHP_ARG_WITH(mysql, enable support for MySQL through libmysqlclient,
[ --with-mysql=DIR Location of MySQL base directory], yes, no)
PHP_ARG_ENABLE(statsd, enable support for statsd,
[ --enable-statsd Enable statsd support], yes, no)
Expand Down Expand Up @@ -103,7 +105,18 @@ if test "$PHP_APM" != "no"; then
fi
fi

if test "$PHP_MYSQL" != "no"; then
if test "$PHP_MYSQLND" != "no"; then
mysql_driver="driver_mysqlnd.c"
AC_MSG_CHECKING([mysqlnd headers])
if test -f $phpincludedir/ext/mysqlnd/mysqlnd.h; then
AC_MSG_RESULT(found)
AC_DEFINE(APM_DRIVER_MYSQLND, 1, [activate MySQL storage driver])
else
AC_MSG_RESULT(not found)
AC_MSG_ERROR([Please check PHP is build with mysqlnd])
fi

elif test "$PHP_MYSQL" != "no"; then
mysql_driver="driver_mysql.c"
AC_DEFINE(APM_DRIVER_MYSQL, 1, [activate MySQL storage driver])

Expand Down
51 changes: 4 additions & 47 deletions driver_mysql.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,52 +61,9 @@ MYSQL * mysql_get_instance(TSRMLS_D) {

mysql_set_character_set(APM_G(mysql_event_db), "utf8");

mysql_query(
APM_G(mysql_event_db),
"\
CREATE TABLE IF NOT EXISTS request (\
id INTEGER UNSIGNED PRIMARY KEY auto_increment,\
application VARCHAR(255) NOT NULL,\
ts TIMESTAMP NOT NULL,\
script TEXT NOT NULL,\
uri TEXT NOT NULL,\
host TEXT NOT NULL,\
ip INTEGER UNSIGNED NOT NULL,\
cookies TEXT NOT NULL,\
post_vars TEXT NOT NULL,\
referer TEXT NOT NULL,\
method TEXT NOT NULL\
)"
);
mysql_query(
APM_G(mysql_event_db),
"\
CREATE TABLE IF NOT EXISTS event (\
id INTEGER UNSIGNED PRIMARY KEY auto_increment,\
request_id INTEGER UNSIGNED,\
ts TIMESTAMP NOT NULL,\
type SMALLINT UNSIGNED NOT NULL,\
file TEXT NOT NULL,\
line MEDIUMINT UNSIGNED NOT NULL,\
message TEXT NOT NULL,\
backtrace BLOB NOT NULL,\
KEY request (request_id)\
)"
);

mysql_query(
APM_G(mysql_event_db),
"\
CREATE TABLE IF NOT EXISTS stats (\
id INTEGER UNSIGNED PRIMARY KEY auto_increment,\
request_id INTEGER UNSIGNED,\
duration FLOAT UNSIGNED NOT NULL,\
user_cpu FLOAT UNSIGNED NOT NULL,\
sys_cpu FLOAT UNSIGNED NOT NULL,\
mem_peak_usage INTEGER UNSIGNED NOT NULL,\
KEY request (request_id)\
)"
);
mysql_query(APM_G(mysql_event_db), TABLE_REQUEST);
mysql_query(APM_G(mysql_event_db), TABLE_EVENT);
mysql_query(APM_G(mysql_event_db), TABLE_STATS);
}

return APM_G(mysql_event_db);
Expand Down Expand Up @@ -185,7 +142,7 @@ static void apm_driver_mysql_insert_request(TSRMLS_D)
if (mysql_query(connection, sql) != 0)
APM_DEBUG("[MySQL driver] Error: %s\n", mysql_error(APM_G(mysql_event_db)));

mysql_query(connection, "SET @request_id = LAST_INSERT_ID()");
mysql_query(connection, QUERY_REQUEST_ID);

efree(sql);
if (application_esc)
Expand Down
41 changes: 41 additions & 0 deletions driver_mysql.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,45 @@ apm_driver_entry * apm_driver_mysql_create();

PHP_INI_MH(OnUpdateAPMmysqlErrorReporting);

#define TABLE_REQUEST "\
CREATE TABLE IF NOT EXISTS request (\
id INTEGER UNSIGNED PRIMARY KEY auto_increment,\
application VARCHAR(255) NOT NULL,\
ts TIMESTAMP NOT NULL,\
script TEXT NOT NULL,\
uri TEXT NOT NULL,\
host TEXT NOT NULL,\
ip INTEGER UNSIGNED NOT NULL,\
cookies TEXT NOT NULL,\
post_vars TEXT NOT NULL,\
referer TEXT NOT NULL,\
method TEXT NOT NULL\
)"

#define TABLE_EVENT "\
CREATE TABLE IF NOT EXISTS event (\
id INTEGER UNSIGNED PRIMARY KEY auto_increment,\
request_id INTEGER UNSIGNED,\
ts TIMESTAMP NOT NULL,\
type SMALLINT UNSIGNED NOT NULL,\
file TEXT NOT NULL,\
line MEDIUMINT UNSIGNED NOT NULL,\
message TEXT NOT NULL,\
backtrace BLOB NOT NULL,\
KEY request (request_id)\
)"

#define TABLE_STATS "\
CREATE TABLE IF NOT EXISTS stats (\
id INTEGER UNSIGNED PRIMARY KEY auto_increment,\
request_id INTEGER UNSIGNED,\
duration FLOAT UNSIGNED NOT NULL,\
user_cpu FLOAT UNSIGNED NOT NULL,\
sys_cpu FLOAT UNSIGNED NOT NULL,\
mem_peak_usage INTEGER UNSIGNED NOT NULL,\
KEY request (request_id)\
)"

#define QUERY_REQUEST_ID "SET @request_id = LAST_INSERT_ID()"

#endif
Loading