From d7ffca590b4ee188a5dcdbafb036e6541f3c79be Mon Sep 17 00:00:00 2001 From: Christopher Jones Date: Fri, 30 Aug 2013 17:37:44 -0700 Subject: [PATCH] Allow OCI8 to be DTrace-enabled independently of core PHP's DTrace status. The proviso is OCI8 must be built "shared" when DTrace is enabled. This implementation (i) works around an incomplete core PHP solution for extension tracing (ii) avoid any issues with DOF section location and the complexities of needing to merge all provider .d files for static builds (iii) allows OCI8 to be DTrace-enabled when doing PECL installs of OCI8 on PHP versions without core PHP DTrace support. This is an initial patch i.e. it will undergo further testing. --- ext/oci8/config.m4 | 126 +++++++++++++++++++++++++++++++++----- ext/oci8/oci8.c | 56 +++++++++-------- ext/oci8/oci8_statement.c | 8 +-- ext/oci8/package.xml | 26 ++++---- ext/oci8/php_oci8_int.h | 2 +- 5 files changed, 161 insertions(+), 57 deletions(-) diff --git a/ext/oci8/config.m4 b/ext/oci8/config.m4 index 311579fd7f..49998d18f0 100644 --- a/ext/oci8/config.m4 +++ b/ext/oci8/config.m4 @@ -82,13 +82,99 @@ AC_DEFUN([AC_OCI8_ORACLE_VERSION],[ AC_MSG_RESULT($OCI8_ORACLE_VERSION) ]) +dnl +dnl OCI8_INIT_DTRACE(providerdesc, header-file, sources) +dnl This mimics PHP_INIT_DTRACE from PHP 5.4's acinclude.m4. It is +dnl necessarily different from PHP_INIT_DTRACE which doesn't currently +dnl support DTrace for extensions. Creating OCI8_INIT_DTRACE +dnl independently instead of using a refactored PHP_INIT_DTRACE allows +dnl OCI8 to be DTraced on versions of PHP where core PHP DTrace support +dnl isn't available. +dnl +AC_DEFUN([OCI8_INIT_DTRACE],[ + ac_srcdir=[]PHP_EXT_SRCDIR([oci8])/ + ac_bdir=[]PHP_EXT_BUILDDIR([oci8])/ + +dnl providerdesc + ac_provsrc=$1 + +dnl header-file + ac_hdrobj=$2 + +dnl DTrace objects + old_IFS=[$]IFS + for ac_src in $3; do + IFS=. + set $ac_src + ac_obj=[$]1 + IFS=$old_IFS + + OCI8_DTRACE_OBJS="[$]OCI8_DTRACE_OBJS [$]ac_bdir[$]ac_obj.lo" + done; + + for ac_lo in $OCI8_DTRACE_OBJS; do + dtrace_oci8_objs="[$]dtrace_oci8_objs `echo $ac_lo | $SED -e 's,\.lo$,.o,' -e 's#\(.*\)\/#\1\/.libs\/#'`" + done; + +dnl Generate Makefile.objects entry +dnl The empty $ac_provsrc command stops an implicit circular dependency +dnl in GNU Make which causes the .d file to be overwritten (Bug 61268) + cat>>Makefile.objects< \$[]@ + +\$(OCI8_DTRACE_OBJS): $ac_bdir[$]ac_hdrobj + +EOF + + case $host_alias in + *solaris*|*linux*) + dtrace_prov_name="`echo $ac_provsrc | $SED -e 's#\(.*\)\/##'`.o" + dtrace_lib_dir="`echo $ac_bdir[$]ac_provsrc | $SED -e 's#\(.*\)/[^/]*#\1#'`/.libs" + dtrace_d_obj="`echo $ac_bdir[$]ac_provsrc | $SED -e 's#\(.*\)/\([^/]*\)#\1/.libs/\2#'`.o" + dtrace_nolib_objs='$(OCI8_DTRACE_OBJS:.lo=.o)' + for ac_lo in $OCI8_DTRACE_OBJS; do + dtrace_oci8_lib_objs="[$]dtrace_oci8_lib_objs `echo $ac_lo | $SED -e 's,\.lo$,.o,' -e 's#\(.*\)\/#\1\/.libs\/#'`" + done; +dnl Always attempt to create both PIC and non-PIC DTrace objects (Bug 63692) + cat>>Makefile.objects< \$[]@ + @test -d "$dtrace_lib_dir" || mkdir $dtrace_lib_dir + if CFLAGS="\$(CFLAGS_CLEAN)" dtrace -G -o $dtrace_d_obj -s $ac_srcdir[$]ac_provsrc $dtrace_oci8_lib_objs 2> /dev/null && test -f "$dtrace_d_obj"; then [\\] + echo "pic_object=['].libs/$dtrace_prov_name[']" >> \$[]@ [;\\] + else [\\] + echo "pic_object='none'" >> \$[]@ [;\\] + fi + if CFLAGS="\$(CFLAGS_CLEAN)" dtrace -G -o $ac_bdir[$]ac_provsrc.o -s $ac_srcdir[$]ac_provsrc $dtrace_nolib_objs 2> /dev/null && test -f "$ac_bdir[$]ac_provsrc.o"; then [\\] + echo "non_pic_object=[']$dtrace_prov_name[']" >> \$[]@ [;\\] + else [\\] + echo "non_pic_object='none'" >> \$[]@ [;\\] + fi + +EOF + ;; + *) + AC_MSG_WARN([OCI8 extension: OCI8 DTrace support is not confirmed on this platform]) +cat>>Makefile.objects<is_stub ? 1 : 0); } -#endif /* HAVE_DTRACE */ +#endif /* HAVE_OCI8_DTRACE */ /* If we got a pconnection stub, then 'load'(OCISessionGet) the real connection from its * private spool A connection is a stub if it is only a cached structure and the real @@ -2186,11 +2194,11 @@ php_oci_connection *php_oci_do_connect_ex(char *username, int username_len, char OCI_G(num_links)++; } -#ifdef HAVE_DTRACE +#ifdef HAVE_OCI8_DTRACE if (DTRACE_OCI8_CONNECT_TYPE_ENABLED()) { DTRACE_OCI8_CONNECT_TYPE(connection->is_persistent ? 1 : 0, exclusive ? 1 : 0, connection, OCI_G(num_persistent), OCI_G(num_links)); } -#endif /* HAVE_DTRACE */ +#endif /* HAVE_OCI8_DTRACE */ return connection; } @@ -2773,11 +2781,11 @@ static int php_oci_persistent_helper(zend_rsrc_list_entry *le TSRMLS_DC) connection = (php_oci_connection *)le->ptr; if (!connection->used_this_request && OCI_G(persistent_timeout) != -1) { -#ifdef HAVE_DTRACE +#ifdef HAVE_OCI8_DTRACE if (DTRACE_OCI8_CONNECT_EXPIRY_ENABLED()) { DTRACE_OCI8_CONNECT_EXPIRY(connection, connection->is_stub ? 1 : 0, connection->idle_expiry, timestamp); } -#endif /* HAVE_DTRACE */ +#endif /* HAVE_OCI8_DTRACE */ if (connection->idle_expiry < timestamp) { /* connection has timed out */ return ZEND_HASH_APPLY_REMOVE; @@ -2913,11 +2921,11 @@ exit_create_spool: PHP_OCI_CALL(OCIHandleFree, ((dvoid *) spoolAuth, (ub4) OCI_HTYPE_AUTHINFO)); } -#ifdef HAVE_DTRACE +#ifdef HAVE_OCI8_DTRACE if (DTRACE_OCI8_SESSPOOL_CREATE_ENABLED()) { DTRACE_OCI8_SESSPOOL_CREATE(session_pool); } -#endif /* HAVE_DTRACE */ +#endif /* HAVE_OCI8_DTRACE */ return session_pool; } @@ -3241,11 +3249,11 @@ static int php_oci_create_session(php_oci_connection *connection, php_oci_spool connection->using_spool = 1; } -#ifdef HAVE_DTRACE +#ifdef HAVE_OCI8_DTRACE if (DTRACE_OCI8_SESSPOOL_TYPE_ENABLED()) { DTRACE_OCI8_SESSPOOL_TYPE(session_pool ? 1 : 0, session_pool ? session_pool : connection->private_spool); } -#endif /* HAVE_DTRACE */ +#endif /* HAVE_OCI8_DTRACE */ /* The passed in "connection" can be a cached stub from plist or freshly created. In the former * case, we do not have to allocate any handles @@ -3294,7 +3302,7 @@ static int php_oci_create_session(php_oci_connection *connection, php_oci_spool /* }}} */ /* {{{ Debug statements */ -#ifdef HAVE_DTRACE +#ifdef HAVE_OCI8_DTRACE if (DTRACE_OCI8_SESSPOOL_STATS_ENABLED()) { ub4 numfree = 0, numbusy = 0, numopen = 0; PHP_OCI_CALL_RETURN(OCI_G(errcode), OCIAttrGet, ((dvoid *)actual_spool->poolh, OCI_HTYPE_SPOOL, (dvoid *)&numopen, (ub4 *)0, OCI_ATTR_SPOOL_OPEN_COUNT, OCI_G(err))); @@ -3302,7 +3310,7 @@ static int php_oci_create_session(php_oci_connection *connection, php_oci_spool numfree = numopen - numbusy; /* number of free connections in the pool */ DTRACE_OCI8_SESSPOOL_STATS(numfree, numbusy, numopen); } -#endif /* HAVE_DTRACE */ +#endif /* HAVE_OCI8_DTRACE */ /* }}} */ /* Ping loop: Ping and loop till we get a good connection. When a database instance goes @@ -3471,11 +3479,11 @@ static sword php_oci_ping_init(php_oci_connection *connection, OCIError *errh TS */ void php_oci_dtrace_check_connection(php_oci_connection *connection, sword errcode, ub4 serverStatus) { -#ifdef HAVE_DTRACE +#ifdef HAVE_OCI8_DTRACE if (DTRACE_OCI8_CHECK_CONNECTION_ENABLED()) { DTRACE_OCI8_CHECK_CONNECTION(connection, connection && connection->is_open ? 1 : 0, (int)errcode, (unsigned long)serverStatus); } -#endif /* HAVE_DTRACE */ +#endif /* HAVE_OCI8_DTRACE */ } /* }}} */ diff --git a/ext/oci8/oci8_statement.c b/ext/oci8/oci8_statement.c index 752a45bcb8..2e6fdabee3 100644 --- a/ext/oci8/oci8_statement.c +++ b/ext/oci8/oci8_statement.c @@ -53,11 +53,11 @@ php_oci_statement *php_oci_statement_create(php_oci_connection *connection, char /* do not allocate stmt handle for refcursors, we'll get it from OCIStmtPrepare2() */ PHP_OCI_CALL(OCIHandleAlloc, (connection->env, (dvoid **)&(statement->stmt), OCI_HTYPE_STMT, 0, NULL)); } else { -#ifdef HAVE_DTRACE +#ifdef HAVE_OCI8_DTRACE if (DTRACE_OCI8_SQLTEXT_ENABLED()) { DTRACE_OCI8_SQLTEXT(query); } -#endif /* HAVE_DTRACE */ +#endif /* HAVE_OCI8_DTRACE */ } PHP_OCI_CALL(OCIHandleAlloc, (connection->env, (dvoid **)&(statement->err), OCI_HTYPE_ERROR, 0, NULL)); @@ -488,11 +488,11 @@ int php_oci_statement_execute(php_oci_statement *statement, ub4 mode TSRMLS_DC) case OCI_DESCRIBE_ONLY: case OCI_DEFAULT: /* only these are allowed */ -#ifdef HAVE_DTRACE +#ifdef HAVE_OCI8_DTRACE if (DTRACE_OCI8_EXECUTE_MODE_ENABLED()) { DTRACE_OCI8_EXECUTE_MODE(mode); } -#endif /* HAVE_DTRACE */ +#endif /* HAVE_OCI8_DTRACE */ break; default: php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid execute mode given: %d", mode); diff --git a/ext/oci8/package.xml b/ext/oci8/package.xml index 4dc78d4983..f18e7afeea 100644 --- a/ext/oci8/package.xml +++ b/ext/oci8/package.xml @@ -40,7 +40,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> no - 2013-07-24 + 2013-08-30 @@ -53,8 +53,10 @@ http://pear.php.net/dtd/package-2.0.xsd"> PHP - Fixed --enable-maintainer-zts mode - Allow Implicit Result Set statement resources to inherit the parent's current prefetch count + Fixed --enable-maintainer-zts mode. + Allow Implicit Result Set statement resources to inherit the parent's current prefetch count. + Allow OCI8 to be DTrace-enabled independently from core PHP. + Require OCI8 to be configured 'shared' when enabling DTrace support. @@ -468,21 +470,21 @@ http://pear.php.net/dtd/package-2.0.xsd"> - NEW FUNCTIONALITY: - Added Implicit Result Set support for Oracle Database 12c. - Streaming of all IRS's returned from a PL/SQL block is available - via oci_fetch_array, oci_fetch_assoc, oci_fetch_object and - oci_fetch_row (but not oci_fetch or oci_fetch_all). - Alternatively individual IRS statement resources can be obtained - with the new function 'oci_get_implicit_resultset' and passed to - any oci_fetch_* function. + Streaming of all IRS's returned from a PL/SQL block is available + via oci_fetch_array, oci_fetch_assoc, oci_fetch_object and + oci_fetch_row (but not oci_fetch or oci_fetch_all). + Alternatively individual IRS statement resources can be obtained + with the new function 'oci_get_implicit_resultset' and passed to + any oci_fetch_* function. - Added DTrace probes enabled with PHP's generic --enable-dtrace - IMPROVED FUNCTIONALITY: - Using 'oci_execute($s, OCI_NO_AUTO_COMMIT)' for a SELECT no - longer unnecessarily initiates an internal ROLLBACK during - connection close. This can improve overall scalability by - reducing "round trips" between PHP and the database. + longer unnecessarily initiates an internal ROLLBACK during + connection close. This can improve overall scalability by + reducing "round trips" between PHP and the database. - CHANGED FUNCTIONALITY: diff --git a/ext/oci8/php_oci8_int.h b/ext/oci8/php_oci8_int.h index ac58145f44..24d80a8163 100644 --- a/ext/oci8/php_oci8_int.h +++ b/ext/oci8/php_oci8_int.h @@ -44,7 +44,7 @@ # endif # endif /* osf alpha */ -#ifdef HAVE_DTRACE +#ifdef HAVE_OCI8_DTRACE #include "oci8_dtrace_gen.h" #endif -- 2.49.0