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 $ -->
2
2
3
3
<chapter id="monitoring">
4
4
<title>Monitoring Database Activity</title>
@@ -1051,7 +1051,8 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS procpid,
1051
1051
<para>
1052
1052
A number of standard probes are provided in the source code,
1053
1053
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.
1055
1056
</para>
1056
1057
1057
1058
<table id="dtrace-probe-point-table">
@@ -1605,8 +1606,9 @@ Total time (ns) 2312105013
1605
1606
<step>
1606
1607
<para>
1607
1608
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
1610
1612
</para>
1611
1613
</step>
1612
1614
@@ -1628,38 +1630,31 @@ Total time (ns) 2312105013
1628
1630
<procedure>
1629
1631
<step>
1630
1632
<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
1633
1635
</para>
1634
1636
</step>
1635
1637
1636
1638
<step>
1637
1639
<para>
1638
1640
Add the probe definition to <filename>src/backend/utils/probes.d</>:
1639
1641
<programlisting>
1640
- ...
1641
1642
probe transaction__start(LocalTransactionId);
1642
- ...
1643
1643
</programlisting>
1644
1644
Note the use of the double underline in the probe name. In a DTrace
1645
1645
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.
1653
1648
</para>
1654
1649
</step>
1655
1650
1656
1651
<step>
1657
1652
<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:
1663
1658
1664
1659
<programlisting>
1665
1660
TRACE_POSTGRESQL_TRANSACTION_START(vxid.localTransactionId);
@@ -1685,6 +1680,44 @@ Total time (ns) 2312105013
1685
1680
</step>
1686
1681
</procedure>
1687
1682
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
+
1688
1721
</sect2>
1689
1722
1690
1723
</sect1>