1
0
mirror of https://github.com/php/php-src.git synced 2026-03-30 12:13:02 +02:00

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.
This commit is contained in:
Christopher Jones
2013-08-30 17:37:44 -07:00
parent 82da51bbce
commit d7ffca590b
5 changed files with 161 additions and 57 deletions

View File

@@ -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<<EOF
PHP_EXT_SRCDIR([oci8])/$ac_provsrc:;
$ac_bdir[$]ac_hdrobj: $ac_srcdir[$]ac_provsrc
CFLAGS="\$(CFLAGS_CLEAN)" dtrace -h -C -s $ac_srcdir[$]ac_provsrc -o \$[]@.bak && \$(SED) -e 's,PHP_,DTRACE_,g' \$[]@.bak > \$[]@
\$(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<<EOF
$ac_bdir[$]ac_provsrc.lo: \$(OCI8_DTRACE_OBJS)
echo "[#] Generated by Makefile for libtool" > \$[]@
@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<<EOF
$ac_bdir[$]ac_provsrc.o: \$(OCI8_DTRACE_OBJS)
CFLAGS="\$(CFLAGS_CLEAN)" dtrace -G -o \$[]@ -s $ac_srcdir[$]ac_provsrc $dtrace_oci8_objs
EOF
;;
esac
])
dnl --with-oci8=shared,instantclient,/path/to/client/dir/lib
dnl or
dnl --with-oci8=shared,/path/to/oracle/home
PHP_ARG_WITH(oci8, for Oracle Database OCI8 support,
[ --with-oci8[=DIR] Include Oracle Database OCI8 support. DIR defaults to \$ORACLE_HOME.
Use --with-oci8=instantclient,/path/to/instant/client/lib
[ --with-oci8[=DIR] Include Oracle Database OCI8 support. DIR defaults to [$]ORACLE_HOME.
Use --with-oci8=instantclient,/path/to/instant/client/lib
to use an Oracle Instant Client installation])
if test "$PHP_OCI8" != "no"; then
@@ -128,22 +214,30 @@ if test "$PHP_OCI8" != "no"; then
AC_MSG_RESULT([$php_version, ok])
fi
dnl conditionally define PHP_INIT_DTRACE.
dnl This prevents 'configure' failing for PECL installs on older PHP versions.
dnl Note DTrace support can't be enabled on older PHP versions.
AC_PROVIDE_IFELSE([PHP_INIT_DTRACE], [], [AC_DEFUN([PHP_INIT_DTRACE], )])
if test "$PHP_DTRACE" = "yes"; then
if test "$oci8_php_version" -lt "5004000"; then
AC_MSG_ERROR([You need at least PHP 5.4 to be able to use DTrace with PHP OCI8])
dnl Check whether --enable-dtrace was set.
dnl To use DTrace with a PECL install, extract the OCI8 archive, phpize it, and set
dnl PHP_DTRACE=yes before running configure
AC_MSG_CHECKING([OCI8 DTrace support])
oci8_do_dtrace="`echo $PHP_OCI8 | cut -d, -f3`"
if test "$PHP_DTRACE" = "yes" -o "$oci8_do_dtrace" = "dtrace" ; then
AC_MSG_RESULT([yes])
if test "$ext_shared" = "no"; then
AC_MSG_ERROR([For DTrace support OCI8 must be configured as a shared extension])
else
AC_CHECK_HEADERS([sys/sdt.h], [
PHP_INIT_DTRACE([ext/oci8/oci8_dtrace.d],[ext/oci8/oci8_dtrace_gen.h],[ext/oci8/oci8.c ext/oci8/oci8_statement.c])
OCI8_INIT_DTRACE([oci8_dtrace.d],[oci8_dtrace_gen.h],[oci8.c oci8_statement.c])
], [
AC_MSG_ERROR(
[Cannot find sys/sdt.h which is required for DTrace support])
])
PHP_SUBST(OCI8_DTRACE_OBJS)
AC_DEFINE(HAVE_OCI8_DTRACE,1,[Defined to 1 if PHP OCI8 DTrace support was enabled during configuration])
dnl Developer warning: hard coded extension is OK for the known supported environments
shared_objects_oci8="$shared_objects_oci8 PHP_EXT_BUILDDIR(oci8)/oci8_dtrace.d.lo"
fi
else
AC_MSG_RESULT([no])
fi
dnl Set some port specific directory components for use later
@@ -255,14 +349,14 @@ if test "$PHP_OCI8" != "no"; then
;;
*)
AC_DEFINE(HAVE_OCI_LOB_READ2,1,[ ])
AC_DEFINE(HAVE_OCI_LOB_READ2,1,[Defined to 1 if OCI8 configuration located Oracle's OCILobRead2 function])
;;
esac
PHP_ADD_LIBRARY(clntsh, 1, OCI8_SHARED_LIBADD)
PHP_ADD_LIBPATH($OCI8_DIR/$OCI8_LIB_DIR, OCI8_SHARED_LIBADD)
PHP_NEW_EXTENSION(oci8, oci8.c oci8_lob.c oci8_statement.c oci8_collection.c oci8_interface.c, $ext_shared)
AC_DEFINE(HAVE_OCI8,1,[ ])
AC_DEFINE(HAVE_OCI8,1,[Defined to 1 if the PHP OCI8 extension for Oracle Database is configured])
PHP_SUBST_OLD(OCI8_SHARED_LIBADD)
PHP_SUBST_OLD(OCI8_DIR)
@@ -330,11 +424,11 @@ if test "$PHP_OCI8" != "no"; then
PHP_ADD_LIBRARY(clntsh, 1, OCI8_SHARED_LIBADD)
PHP_ADD_LIBPATH($PHP_OCI8_INSTANT_CLIENT, OCI8_SHARED_LIBADD)
AC_DEFINE(HAVE_OCI_INSTANT_CLIENT,1,[ ])
AC_DEFINE(HAVE_OCI_LOB_READ2,1,[ ])
AC_DEFINE(HAVE_OCI_INSTANT_CLIENT,1,[Defined to 1 if OCI8 configuration located Oracle's Instant Client libraries])
AC_DEFINE(HAVE_OCI_LOB_READ2,1,[Defined to 1 if OCI8 configuration located Oracle's OCILobRead2 function])
PHP_NEW_EXTENSION(oci8, oci8.c oci8_lob.c oci8_statement.c oci8_collection.c oci8_interface.c, $ext_shared)
AC_DEFINE(HAVE_OCI8,1,[ ])
AC_DEFINE(HAVE_OCI8,1,[Defined to 1 if the PHP OCI8 extension for Oracle Database is configured])
PHP_SUBST_OLD(OCI8_SHARED_LIBADD)
PHP_SUBST_OLD(OCI8_DIR)

View File

@@ -1354,6 +1354,11 @@ PHP_MINFO_FUNCTION(oci)
php_info_print_table_start();
php_info_print_table_row(2, "OCI8 Support", "enabled");
#if defined(HAVE_OCI8_DTRACE)
php_info_print_table_row(2, "OCI8 DTrace Support", "enabled");
#else
php_info_print_table_row(2, "OCI8 DTrace Support", "disabled");
#endif
php_info_print_table_row(2, "OCI8 Version", PHP_OCI8_VERSION);
php_info_print_table_row(2, "Revision", "$Id$");
@@ -1361,6 +1366,8 @@ PHP_MINFO_FUNCTION(oci)
php_oci_client_get_version(&ver TSRMLS_CC);
php_info_print_table_row(2, "Oracle Run-time Client Library Version", ver);
efree(ver);
#else
php_info_print_table_row(2, "Oracle Run-time Client Library Version", "Unknown");
#endif
#if defined(OCI_MAJOR_VERSION) && defined(OCI_MINOR_VERSION)
snprintf(buf, sizeof(buf), "%d.%d", OCI_MAJOR_VERSION, OCI_MINOR_VERSION);
@@ -1384,6 +1391,7 @@ PHP_MINFO_FUNCTION(oci)
#endif
#endif
php_info_print_table_end();
DISPLAY_INI_ENTRIES();
@@ -1467,11 +1475,11 @@ static void php_oci_pconnection_list_np_dtor(zend_rsrc_list_entry *entry TSRMLS_
OCI_G(num_persistent)--;
}
#ifdef HAVE_DTRACE
#ifdef HAVE_OCI8_DTRACE
if (DTRACE_OCI8_CONNECT_P_DTOR_CLOSE_ENABLED()) {
DTRACE_OCI8_CONNECT_P_DTOR_CLOSE(connection);
}
#endif /* HAVE_DTRACE */
#endif /* HAVE_OCI8_DTRACE */
} else {
/*
* Release the connection to underlying pool. We do this unconditionally so that
@@ -1484,11 +1492,11 @@ static void php_oci_pconnection_list_np_dtor(zend_rsrc_list_entry *entry TSRMLS_
*/
php_oci_connection_release(connection TSRMLS_CC);
#ifdef HAVE_DTRACE
#ifdef HAVE_OCI8_DTRACE
if (DTRACE_OCI8_CONNECT_P_DTOR_RELEASE_ENABLED()) {
DTRACE_OCI8_CONNECT_P_DTOR_RELEASE(connection);
}
#endif /* HAVE_DTRACE */
#endif /* HAVE_OCI8_DTRACE */
}
}
/* }}} */
@@ -1687,11 +1695,11 @@ sb4 php_oci_error(OCIError *err_p, sword status TSRMLS_DC)
break;
}
#ifdef HAVE_DTRACE
#ifdef HAVE_OCI8_DTRACE
if (DTRACE_OCI8_ERROR_ENABLED()) {
DTRACE_OCI8_ERROR(status, errcode);
}
#endif /* HAVE_DTRACE */
#endif /* HAVE_OCI8_DTRACE */
return errcode;
}
@@ -1771,11 +1779,11 @@ void php_oci_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent, int exclus
return;
}
#ifdef HAVE_DTRACE
#ifdef HAVE_OCI8_DTRACE
if (DTRACE_OCI8_CONNECT_ENTRY_ENABLED()) {
DTRACE_OCI8_CONNECT_ENTRY(username, dbname, charset, session_mode, persistent, exclusive);
}
#endif /* HAVE_DTRACE */
#endif /* HAVE_OCI8_DTRACE */
if (!charset_len) {
charset = NULL;
@@ -1783,11 +1791,11 @@ void php_oci_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent, int exclus
connection = php_oci_do_connect_ex(username, username_len, password, password_len, NULL, 0, dbname, dbname_len, charset, session_mode, persistent, exclusive TSRMLS_CC);
#ifdef HAVE_DTRACE
#ifdef HAVE_OCI8_DTRACE
if (DTRACE_OCI8_CONNECT_RETURN_ENABLED()) {
DTRACE_OCI8_CONNECT_RETURN(connection);
}
#endif /* HAVE_DTRACE */
#endif /* HAVE_OCI8_DTRACE */
if (!connection) {
@@ -1955,11 +1963,11 @@ php_oci_connection *php_oci_do_connect_ex(char *username, int username_len, char
}
}
#ifdef HAVE_DTRACE
#ifdef HAVE_OCI8_DTRACE
if (DTRACE_OCI8_CONNECT_LOOKUP_ENABLED()) {
DTRACE_OCI8_CONNECT_LOOKUP(connection, connection && connection->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 */
}
/* }}} */

View File

@@ -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);

View File

@@ -40,7 +40,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
<active>no</active>
</lead>
<date>2013-07-24</date>
<date>2013-08-30</date>
<time>12:00:00</time>
<version>
@@ -53,8 +53,10 @@ http://pear.php.net/dtd/package-2.0.xsd">
</stability>
<license uri="http://www.php.net/license">PHP</license>
<notes>
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.
</notes>
<contents>
<dir name="/">
@@ -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:

View File

@@ -44,7 +44,7 @@
# endif
# endif /* osf alpha */
#ifdef HAVE_DTRACE
#ifdef HAVE_OCI8_DTRACE
#include "oci8_dtrace_gen.h"
#endif