1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406
|
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<chapter xml:id="oci8.dtrace" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>OCI8 and DTrace Dynamic Tracing</title>
<para>
OCI8 2.0 introduced static DTrace probes that can be used on
operating systems that support DTrace.
See <link linkend="features.dtrace">DTrace Dynamic Tracing</link>
for an overview of PHP and DTrace.
</para>
<section>
<title>Installing OCI8 with DTrace Support</title>
<para>
To enable DTrace support in PHP OCI8, build OCI8 as a shared
extension after setting <literal>PHP_DTRACE</literal>.
</para>
<para>
<informalexample>
<screen>
<![CDATA[
$ export PHP_DTRACE=yes
$ pecl install oci8
]]>
</screen>
</informalexample>
</para>
<para>
Edit php.ini,
set <link linkend="ini.extension-dir">extension_dir</link> to the
directory with the created <filename>oci8.so</filename> and also
enable the extension by adding:
</para>
<para>
<informalexample>
<screen>
<![CDATA[
extension=oci8.so
]]>
</screen>
</informalexample>
</para>
<para>
If you install PHP OCI8 from PECL using <filename>phpize</filename> and
<filename>configure</filename> (instead
of <filename>pecl</filename>), you will still need to set
<literal>PHP_DTRACE=yes</literal>. This is because
the <literal>--enable-dtrace</literal> option will be ignored by the
limited <filename>configure</filename> script of a PECL bundle.
</para>
<para>
See <link linkend="install.pecl">Installation of PECL
extensions</link> for general PECL installation instructions.
</para>
</section>
<section>
<title>DTrace Static Probes in PHP OCI8</title>
<table>
<title>The following static probes are available in PHP OCI8</title>
<tgroup cols="2">
<thead>
<row>
<entry>Probe Name</entry>
<entry>Probe Description</entry>
<entry>Probe Arguments</entry>
</row>
</thead>
<tbody>
<row>
<entry><literal>oci8-connect-entry</literal></entry>
<entry>Initiated by oci_connect(), oci_pconnect() and oci_new_connect(). Fires before database connection is established.</entry>
<entry>char *<varname>username</varname>, char *<varname>dbname</varname>, char *<varname>charset</varname>, long <varname>session_mode</varname>, int <varname>persistent</varname>, int <varname>exclusive</varname></entry>
</row>
<row>
<entry><literal>oci8-connect-return</literal></entry>
<entry>Fires at the end of connection.</entry>
<entry>void *<varname>connection</varname></entry>
</row>
<row>
<entry><literal>oci8-check-connection</literal></entry>
<entry>Fires if an Oracle error might have caused the connection to become invalid.</entry>
<entry>void *<varname>connection</varname>, char *<varname>client_id</varname>, int <varname>is_open</varname>, long <varname>errcode</varname>, unsigned long <varname>server_status</varname></entry>
</row>
<row>
<entry><literal>oci8-sqltext</literal></entry>
<entry>Fires when oci_parse() is executed.</entry>
<entry>void *<varname>connection</varname>, char *<varname>client_id</varname>, void *<varname>statement</varname>, char *<varname>sql</varname></entry>
</row>
<row>
<entry><literal>oci8-connection-close</literal></entry>
<entry>Fires when the connection to the database is completely destroyed.</entry>
<entry>void *<varname>connection</varname></entry>
</row>
<row>
<entry><literal>oci8-error</literal></entry>
<entry>Fires if an Oracle error occurs.</entry>
<entry>int <varname>status</varname>, long <varname>errcode</varname></entry>
</row>
<row>
<entry><literal>oci8-execute-mode</literal></entry>
<entry>Fires at <function>oci_execute</function> to show the execution mode.</entry>
<entry>void *<varname>connection</varname>, char *<varname>client_id</varname>, void *<varname>statement</varname>, unsigned int <varname>mode</varname></entry>
</row>
</tbody>
</tgroup>
</table>
<para>
These probes are useful for tracing OCI8 scripts.
</para>
<para>
The <varname>connection</varname> and <varname>statement</varname>
are the pointers to internal structures used for tracking PHP
connections and executed statements.
</para>
<para>
The <varname>client_id</varname> is the value set
by <function>oci_set_client_identifier</function>.
</para>
<para>
</para>
<para>
</para>
<para>
</para>
<para>
Core PHP also has static probes.
See <link linkend="features.dtrace.static-probes">DTrace Static
Probes in Core PHP</link>.
</para>
<table>
<title>Internal Debugging DTrace Probes in OCI8</title>
<tgroup cols="2">
<thead>
<row>
<entry>Probe Name</entry>
</row>
</thead>
<tbody>
<row>
<entry><literal>oci8-connect-expiry</literal></entry>
</row>
<row>
<entry><literal>oci8-connect-lookup</literal></entry>
</row>
<row>
<entry><literal>oci8-connect-p-dtor-close</literal></entry>
</row>
<row>
<entry><literal>oci8-connect-p-dtor-release</literal></entry>
</row>
<row>
<entry><literal>oci8-connect-type</literal></entry>
</row>
<row>
<entry><literal>oci8-sesspool-create</literal></entry>
</row>
<row>
<entry><literal>oci8-sesspool-stats</literal></entry>
</row>
<row>
<entry><literal>oci8-sesspool-type</literal></entry>
</row>
</tbody>
</tgroup>
</table>
<para>
These probes are useful for OCI8 maintainers. Refer to the OCI8 source code for arguments and to see when the will fire.
</para>
</section>
<section>
<title>Listing DTrace Static Probes in PHP OCI8</title>
<para>
To list available probes, start a PHP process and then run:
<informalexample>
<programlisting>
<![CDATA[
# dtrace -l
]]>
</programlisting>
</informalexample>
</para>
<para>
The output will be similar to:
<informalexample>
<programlisting>
<![CDATA[
ID PROVIDER MODULE FUNCTION NAME
[ . . . ]
17 phpoci22116 oci8.so php_oci_dtrace_check_connection oci8-check-connection
18 phpoci22116 oci8.so php_oci_do_connect oci8-connect-entry
19 phpoci22116 oci8.so php_oci_persistent_helper oci8-connect-expiry
20 phpoci22116 oci8.so php_oci_do_connect_ex oci8-connect-lookup
21 phpoci22116 oci8.so php_oci_pconnection_list_np_dtor oci8-connect-p-dtor-close
22 phpoci22116 oci8.so php_oci_pconnection_list_np_dtor oci8-connect-p-dtor-release
23 phpoci22116 oci8.so php_oci_do_connect oci8-connect-return
24 phpoci22116 oci8.so php_oci_do_connect_ex oci8-connect-type
25 phpoci22116 oci8.so php_oci_connection_close oci8-connection-close
26 phpoci22116 oci8.so php_oci_error oci8-error
27 phpoci22116 oci8.so php_oci_statement_execute oci8-execute-mode
28 phpoci22116 oci8.so php_oci_create_spool oci8-sesspool-create
29 phpoci22116 oci8.so php_oci_create_session oci8-sesspool-stats
30 phpoci22116 oci8.so php_oci_create_session oci8-sesspool-type
31 phpoci22116 oci8.so php_oci_statement_create oci8-sqltext
]]>
</programlisting>
</informalexample>
</para>
<para>
The Provider column values consist of <literal>phpoci</literal> and
the process id of the currently running PHP process.
</para>
<para>
The Function column refers to PHP's internal C implementation
function names where each provider is located.
</para>
<para>
If a PHP process is not running, then no PHP probes will be shown.
</para>
</section>
<section>
<title>DTrace with PHP OCI8 Example</title>
<para>
This example shows the basics of the DTrace D scripting language.
<example>
<title><filename>user_oci8_probes.d</filename> for tracing all user-level PHP OCI8 Static Probes with DTrace</title>
<programlisting>
<![CDATA[
#!/usr/sbin/dtrace -Zs
#pragma D option quiet
php*:::oci8-connect-entry
{
printf("%lld: PHP connect-entry\n", walltimestamp);
printf(" credentials=\"%s@%s\"\n", arg0 ? copyinstr(arg0) : "", arg1 ? copyinstr(arg1) : "");
printf(" charset=\"%s\"\n", arg2 ? copyinstr(arg2) : "");
printf(" session_mode=%ld\n", (long)arg3);
printf(" persistent=%d\n", (int)arg4);
printf(" exclusive=%d\n", (int)arg5);
}
php*:::oci8-connect-return
{
printf("%lld: PHP oci8-connect-return\n", walltimestamp);
printf(" connection=0x%p\n", (void *)arg0);
}
php*:::oci8-connection-close
{
printf("%lld: PHP oci8-connect-close\n", walltimestamp);
printf(" connection=0x%p\n", (void *)arg0);
}
php*:::oci8-error
{
printf("%lld: PHP oci8-error\n", walltimestamp);
printf(" status=%d\n", (int)arg0);
printf(" errcode=%ld\n", (long)arg1);
}
php*:::oci8-check-connection
{
printf("%lld: PHP oci8-check-connection\n", walltimestamp);
printf(" connection=0x%p\n", (void *)arg0);
printf(" client_id=\"%s\"\n", arg1 ? copyinstr(arg1) : "");
printf(" is_open=%d\n", arg2);
printf(" errcode=%ld\n", (long)arg3);
printf(" server_status=%lu\n", (unsigned long)arg4);
}
php*:::oci8-sqltext
{
printf("%lld: PHP oci8-sqltext\n", walltimestamp);
printf(" connection=0x%p\n", (void *)arg0);
printf(" client_id=\"%s\"\n", arg1 ? copyinstr(arg1) : "");
printf(" statement=0x%p\n", (void *)arg2);
printf(" sql=\"%s\"\n", arg3 ? copyinstr(arg3) : "");
}
php*:::oci8-execute-mode
{
printf("%lld: PHP oci8-execute-mode\n", walltimestamp);
printf(" connection=0x%p\n", (void *)arg0);
printf(" client_id=\"%s\"\n", arg1 ? copyinstr(arg1) : "");
printf(" statement=0x%p\n", (void *)arg2);
printf(" mode=0x%x\n", arg3);
}
]]>
</programlisting>
</example>
</para>
<para>
This script uses the <literal>-Z</literal> option to
<filename>dtrace</filename>, allowing it to be run when there is no
PHP process executing. If this option were omitted the script
would immediately terminate when no PHP executable was running
because it knows none of the probes to be monitored are in
existence.
</para>
<para>
On multi-CPU machines the probe ordering might not appear to be
sequential. This depends on which CPU was processing the probes,
and how threads migrate across CPUs. Displaying probe time stamps
helps reduce confusion.
</para>
<para>
The script traces all user-level PHP OCI8 static probe points
throughout the duration of a running PHP script. Run the D script:
<informalexample>
<programlisting>
<![CDATA[
# ./user_oci8_probes.d
]]>
</programlisting>
</informalexample>
</para>
<para>
Run a PHP script or application. The monitoring D script will
output each probe's arguments as it fires. For example, a simple
PHP script that queries a table might produce the following trace
output:
<informalexample>
<programlisting>
<![CDATA[
1381794982092854582: PHP connect-entry
credentials="hr@localhost/pdborcl"
charset=""
session_mode=0
persistent=0
exclusive=0
1381794982183158766: PHP oci8-connect-return
connection=0x7f4a7907bfb8
1381794982183594576: PHP oci8-sqltext
connection=0x7f4a7907bfb8
client_id="Chris"
statement=0x7f4a7907c2a0
sql="select * from employees"
1381794982183783706: PHP oci8-execute-mode
connection=0x7f4a7907bfb8
client_id="Chris"
statement=0x7f4a7907c2a0
mode=0x20
1381794982444344390: PHP oci8-connect-close
connection=0x7f4a7907bfb8
]]>
</programlisting>
</informalexample>
</para>
<para>
When monitoring is complete, the D script can be terminated with a
<keycombo action='simul'><keycap>CTRL</keycap><keycap>C</keycap></keycombo>.
</para>
</section>
<section>
&reftitle.seealso;
<simplelist>
<member><link linkend="features.dtrace">DTrace Dynamic Tracing</link></member>
</simplelist>
</section>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
|