1- <!-- $PostgreSQL: pgsql/doc/src/sgml/monitoring.sgml,v 1.65 2009/03/23 01:52:38 tgl Exp $ -->
1+ <!-- $PostgreSQL: pgsql/doc/src/sgml/monitoring.sgml,v 1.66 2009/03/28 00:10:23 tgl Exp $ -->
22
33<chapter id="monitoring">
44 <title>Monitoring Database Activity</title>
@@ -1051,7 +1051,8 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS procpid,
10511051 <para>
10521052 A number of standard probes are provided in the source code,
10531053 as shown in <xref linkend="dtrace-probe-point-table">.
1054- More can certainly be added to enhance PostgreSQL's observability.
1054+ More can certainly be added to enhance <productname>PostgreSQL</>'s
1055+ observability.
10551056 </para>
10561057
10571058 <table id="dtrace-probe-point-table">
@@ -1605,8 +1606,9 @@ Total time (ns) 2312105013
16051606 <step>
16061607 <para>
16071608 Include <filename>pg_trace.h</> if it is not already present in the
1608- module(s) containing the probe points, and insert TRACE_POSTGRESQL
1609- probe macros at the desired locations in the source code
1609+ module(s) containing the probe points, and insert
1610+ <literal>TRACE_POSTGRESQL</> probe macros at the desired locations
1611+ in the source code
16101612 </para>
16111613 </step>
16121614
@@ -1628,38 +1630,31 @@ Total time (ns) 2312105013
16281630 <procedure>
16291631 <step>
16301632 <para>
1631- Decide that the probe will be named transaction-start and requires
1632- a parameter of type LocalTransactionId
1633+ Decide that the probe will be named<literal> transaction-start</> and
1634+ requires a parameter of type LocalTransactionId
16331635 </para>
16341636 </step>
16351637
16361638 <step>
16371639 <para>
16381640 Add the probe definition to <filename>src/backend/utils/probes.d</>:
16391641<programlisting>
1640- ...
16411642 probe transaction__start(LocalTransactionId);
1642- ...
16431643</programlisting>
16441644 Note the use of the double underline in the probe name. In a DTrace
16451645 script using the probe, the double underline needs to be replaced with a
1646- hyphen.
1647- </para>
1648-
1649- <para>
1650- You should take care that the data types specified for the probe
1651- parameters match the data types of the variables used in the macro.
1652- Otherwise, you will get compilation errors.
1646+ hyphen, so <literal>transaction-start</> is the name to document for
1647+ users.
16531648 </para>
16541649 </step>
16551650
16561651 <step>
16571652 <para>
1658- At compile time, transaction__start is converted to a macro called
1659- TRACE_POSTGRESQL_TRANSACTION_START (note the underscores are single
1660- here), which is available by including <filename>pg_trace.h</>.
1661- Add the macro call to the appropriate location in the source code.
1662- In this case, it looks like the following:
1653+ At compile time,<literal> transaction__start</> is converted to a macro
1654+ called <literal> TRACE_POSTGRESQL_TRANSACTION_START</> (notice the
1655+ underscores are single here), which is available by including
1656+ <filename>pg_trace.h</>. Add the macro call to the appropriate location
1657+ in the source code. In this case, it looks like the following:
16631658
16641659<programlisting>
16651660 TRACE_POSTGRESQL_TRANSACTION_START(vxid.localTransactionId);
@@ -1685,6 +1680,44 @@ Total time (ns) 2312105013
16851680 </step>
16861681 </procedure>
16871682
1683+ <para>
1684+ There are a few things to be careful about when adding trace macros
1685+ to the C code:
1686+
1687+ <itemizedlist>
1688+ <listitem>
1689+ <para>
1690+ You should take care that the data types specified for a probe's
1691+ parameters match the data types of the variables used in the macro.
1692+ Otherwise, you will get compilation errors.
1693+ </para>
1694+ </listitem>
1695+
1696+
1697+ <listitem>
1698+ <para>
1699+ On most platforms, if <productname>PostgreSQL</productname> is
1700+ built with <option>--enable-dtrace</>, the arguments to a trace
1701+ macro will be evaluated whenever control passes through the
1702+ macro, <emphasis>even if no tracing is being done</>. This is
1703+ usually not worth worrying about if you are just reporting the
1704+ values of a few local variables. But beware of putting expensive
1705+ function calls into the arguments. If you need to do that,
1706+ consider protecting the macro with a check to see if the trace
1707+ is actually enabled:
1708+
1709+ <programlisting>
1710+ if (TRACE_POSTGRESQL_TRANSACTION_START_ENABLED())
1711+ TRACE_POSTGRESQL_TRANSACTION_START(some_function(...));
1712+ </programlisting>
1713+
1714+ Each trace macro has a corresponding <literal>ENABLED</> macro.
1715+ </para>
1716+ </listitem>
1717+ </itemizedlist>
1718+
1719+ </para>
1720+
16881721 </sect2>
16891722
16901723 </sect1>