Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
c111a721
Commit
c111a721
authored
Mar 25, 2008
by
Neil Conway
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update documentation for recent DTrace changes. Patch from Robert Lor.
parent
220db7cc
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
131 additions
and
81 deletions
+131
-81
doc/src/sgml/installation.sgml
doc/src/sgml/installation.sgml
+3
-3
doc/src/sgml/monitoring.sgml
doc/src/sgml/monitoring.sgml
+128
-78
No files found.
doc/src/sgml/installation.sgml
View file @
c111a721
<
!-- $PostgreSQL: pgsql/doc/src/sgml/installation.sgml,v 1.30
4 2008/03/10 20:06:27 tgl
Exp $ -->
<
!-- $PostgreSQL: pgsql/doc/src/sgml/installation.sgml,v 1.30
5 2008/03/25 22:50:27 neilc
Exp $ -->
<
chapter
id
=
"installation"
>
<
chapter
id
=
"installation"
>
<
title
><
![%standalone-include[<productname>PostgreSQL</>]]>
<
title
><
![%standalone-include[<productname>PostgreSQL</>]]>
...
@@ -1193,8 +1193,8 @@ su - postgres
...
@@ -1193,8 +1193,8 @@ su - postgres
<
primary
>
DTrace
</
primary
>
<
primary
>
DTrace
</
primary
>
</
indexterm
>
</
indexterm
>
Compiles
with
support
for
the
dynamic
tracing
tool
DTrace
.
Compiles
with
support
for
the
dynamic
tracing
tool
DTrace
.
Operating
system
support
for
DTrace
is
currently
only
Operating
system
support
for
DTrace
is
currently
available
in
available
in
Solaris
.
Solaris
and
Mac
OS
X
Leopard
.
</
para
>
</
para
>
<
para
>
<
para
>
...
...
doc/src/sgml/monitoring.sgml
View file @
c111a721
<!-- $PostgreSQL: pgsql/doc/src/sgml/monitoring.sgml,v 1.5
5 2007/11/28 15:42:31 petere
Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/monitoring.sgml,v 1.5
6 2008/03/25 22:50:27 neilc
Exp $ -->
<chapter id="monitoring">
<chapter id="monitoring">
<title>Monitoring Database Activity</title>
<title>Monitoring Database Activity</title>
...
@@ -947,26 +947,26 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS procpid,
...
@@ -947,26 +947,26 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS procpid,
</para>
</para>
<para>
<para>
A number of
trace points, often called probes,
are already inserted
A number of
probes or trace points
are already inserted
into the source code. By default these probes are
disabled, and
into the source code. By default these probes are
not compiled into the
the user needs to explicitly tell the configure script to make th
e
binary, and the user needs to explicitly tell the configure script to mak
e
probes available in <productname>PostgreSQL</productname>.
the
probes available in <productname>PostgreSQL</productname>.
</para>
</para>
<para>
<para>
Currently, only the DTrace utility is supported, which is
only
available
Currently, only the DTrace utility is supported, which is available
on Solaris Express
and Solaris 10+. It is expected that DTrace will
on Solaris Express
, Solaris 10, and Mac OS X Leopard. It is expected that
be available in the future on FreeBSD and Mac OS X
.
DTrace will be available in the future on FreeBSD
.
Supporting other dynamic tracing utilities is theoretically possible by
Supporting other dynamic tracing utilities is theoretically possible by
changing the definitions for the
<literal>PG_TRACE</>
macros in
changing the definitions for the macros in
<filename>src/include/
pg_trace
.h</>.
<filename>src/include/
utils/probes
.h</>.
</para>
</para>
<sect2 id="compiling-for-trace">
<sect2 id="compiling-for-trace">
<title>Compiling for Dynamic Tracing</title>
<title>Compiling for Dynamic Tracing</title>
<para>
<para>
By default,
trace points are disabled
, so you will need to
By default,
probes are not available
, so you will need to
explicitly tell the configure script to make the probes available
explicitly tell the configure script to make the probes available
in <productname>PostgreSQL</productname>. To include DTrace support
in <productname>PostgreSQL</productname>. To include DTrace support
specify <option>--enable-dtrace</> to configure. See <xref
specify <option>--enable-dtrace</> to configure. See <xref
...
@@ -975,16 +975,16 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS procpid,
...
@@ -975,16 +975,16 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS procpid,
</sect2>
</sect2>
<sect2 id="trace-points">
<sect2 id="trace-points">
<title>Built-in
Trace Point
s</title>
<title>Built-in
Probe
s</title>
<para>
<para>
A few standard
trace point
s are provided in the source code
A few standard
probe
s are provided in the source code
(of course, more can be added as needed for a particular problem).
(of course, more can be added as needed for a particular problem).
These are shown in <xref linkend="trace-point-table">.
These are shown in <xref linkend="trace-point-table">.
</para>
</para>
<table id="trace-point-table">
<table id="trace-point-table">
<title>Built-in
Trace Point
s</title>
<title>Built-in
Probe
s</title>
<tgroup cols="3">
<tgroup cols="3">
<thead>
<thead>
<row>
<row>
...
@@ -996,67 +996,67 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS procpid,
...
@@ -996,67 +996,67 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS procpid,
<tbody>
<tbody>
<row>
<row>
<entry>transaction
__
start</entry>
<entry>transaction
-
start</entry>
<entry>(int transactionId)</entry>
<entry>(int transactionId)</entry>
<entry>The start of a new transaction.</entry>
<entry>The start of a new transaction.</entry>
</row>
</row>
<row>
<row>
<entry>transaction
__
commit</entry>
<entry>transaction
-
commit</entry>
<entry>(int transactionId)</entry>
<entry>(int transactionId)</entry>
<entry>The successful completion of a transaction.</entry>
<entry>The successful completion of a transaction.</entry>
</row>
</row>
<row>
<row>
<entry>transaction
__
abort</entry>
<entry>transaction
-
abort</entry>
<entry>(int transactionId)</entry>
<entry>(int transactionId)</entry>
<entry>The unsuccessful completion of a transaction.</entry>
<entry>The unsuccessful completion of a transaction.</entry>
</row>
</row>
<row>
<row>
<entry>lwlock
__
acquire</entry>
<entry>lwlock
-
acquire</entry>
<entry>(int lockid, int mode)</entry>
<entry>(int lockid, int mode)</entry>
<entry>An LWLock has been acquired.</entry>
<entry>An LWLock has been acquired.</entry>
</row>
</row>
<row>
<row>
<entry>lwlock
__
release</entry>
<entry>lwlock
-
release</entry>
<entry>(int lockid, int mode)</entry>
<entry>(int lockid, int mode)</entry>
<entry>An LWLock has been released.</entry>
<entry>An LWLock has been released.</entry>
</row>
</row>
<row>
<row>
<entry>lwlock
__
startwait</entry>
<entry>lwlock
-
startwait</entry>
<entry>(int lockid, int mode)</entry>
<entry>(int lockid, int mode)</entry>
<entry>An LWLock was not immediately available and a backend
<entry>An LWLock was not immediately available and a backend
has begun to wait for the lock to become available.
has begun to wait for the lock to become available.
</entry>
</entry>
</row>
</row>
<row>
<row>
<entry>lwlock
__
endwait</entry>
<entry>lwlock
-
endwait</entry>
<entry>(int lockid, int mode)</entry>
<entry>(int lockid, int mode)</entry>
<entry>A backend has been released from its wait for an LWLock.
<entry>A backend has been released from its wait for an LWLock.
</entry>
</entry>
</row>
</row>
<row>
<row>
<entry>lwlock
__
condacquire</entry>
<entry>lwlock
-
condacquire</entry>
<entry>(int lockid, int mode)</entry>
<entry>(int lockid, int mode)</entry>
<entry>An LWLock was successfully acquired when the caller specified no
<entry>An LWLock was successfully acquired when the caller specified no
waiting.
waiting.
</entry>
</entry>
</row>
</row>
<row>
<row>
<entry>lwlock
__condacquire__
fail</entry>
<entry>lwlock
-condacquire-
fail</entry>
<entry>(int lockid, int mode)</entry>
<entry>(int lockid, int mode)</entry>
<entry>An LWLock was not successfully acquired when the caller specified
<entry>An LWLock was not successfully acquired when the caller specified
no waiting.
no waiting.
</entry>
</entry>
</row>
</row>
<row>
<row>
<entry>lock
__
startwait</entry>
<entry>lock
-
startwait</entry>
<entry>(int locktag_field2, int lockmode)</entry>
<entry>(int locktag_field2, int lockmode)</entry>
<entry>A request for a heavyweight lock (lmgr lock) has begun to wait
<entry>A request for a heavyweight lock (lmgr lock) has begun to wait
because the lock is not available.
because the lock is not available.
</entry>
</entry>
</row>
</row>
<row>
<row>
<entry>lock
__
endwait</entry>
<entry>lock
-
endwait</entry>
<entry>(int locktag_field2, int lockmode)</entry>
<entry>(int locktag_field2, int lockmode)</entry>
<entry>A request for a heavyweight lock (lmgr lock) has finished waiting
<entry>A request for a heavyweight lock (lmgr lock) has finished waiting
(i.e., has acquired the lock).
(i.e., has acquired the lock).
...
@@ -1068,7 +1068,7 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS procpid,
...
@@ -1068,7 +1068,7 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS procpid,
</sect2>
</sect2>
<sect2 id="using-trace-points">
<sect2 id="using-trace-points">
<title>Using
Trace Point
s</title>
<title>Using
Probe
s</title>
<para>
<para>
The example below shows a DTrace script for analyzing transaction
The example below shows a DTrace script for analyzing transaction
...
@@ -1096,11 +1096,9 @@ postgresql$1:::transaction-commit
...
@@ -1096,11 +1096,9 @@ postgresql$1:::transaction-commit
self->ts=0;
self->ts=0;
}
}
</programlisting>
</programlisting>
Note how the double underline in trace point names needs to
be replaced by a hyphen when using D script.
When executed, the example D script gives output such as:
When executed, the example D script gives output such as:
<screen>
<screen>
# ./txn_count.d `pgrep -n postgres`
# ./txn_count.d `pgrep -n postgres`
or ./txn_count.d <PID>
^C
^C
Start 71
Start 71
...
@@ -1109,7 +1107,7 @@ Total time (ns) 2312105013
...
@@ -1109,7 +1107,7 @@ Total time (ns) 2312105013
</screen>
</screen>
</para>
</para>
<para>
<para>
You should remember that
trace program
s need to be carefully written and
You should remember that
DTrace script
s need to be carefully written and
debugged prior to their use, otherwise the trace information collected might
debugged prior to their use, otherwise the trace information collected might
be meaningless. In most cases where problems are found it is the
be meaningless. In most cases where problems are found it is the
instrumentation that is at fault, not the underlying system. When
instrumentation that is at fault, not the underlying system. When
...
@@ -1119,30 +1117,86 @@ Total time (ns) 2312105013
...
@@ -1119,30 +1117,86 @@ Total time (ns) 2312105013
</sect2>
</sect2>
<sect2 id="defining-trace-points">
<sect2 id="defining-trace-points">
<title>Defining
Trace Point
s</title>
<title>Defining
New Probe
s</title>
<para>
<para>
New trace points can be defined within the code wherever the developer
New probes can be defined within the code wherever the developer
desires, though this will require a recompilation.
desires, though this will require a recompilation. Below are the steps
for inserting new probes:
</para>
</para>
<procedure>
<step>
<para>
<para>
A trace point can be inserted by using one of the
Decide on probe names and data to be made available through the probes
trace macros. These are chosen according to how many variables will
</para>
be made available for inspection at that trace point. Tracing the
</step>
occurrence of an event can be achieved with a single line, using
just the trace point name, e.g.:
<step>
<programlisting>
<para>
PG_TRACE (my__new__trace__point);
Add the probe definitons to <filename>src/backend/src/utils/probes.d</>
</programlisting>
</para>
More complex trace points can be provided with one or more variables
</step>
for inspection by the dynamic tracing utility by using the
<literal>PG_TRACE</><replaceable>n</> macro that corresponds to the number
<step>
of parameters after the trace point name:
<para>
Insert a one-line probe macros at the desired locations in the source code
</para>
</step>
<step>
<para>
Recompile and verify that the new probes are available
</para>
</step>
</procedure>
<formalpara>
<title>Example:</title>
<para>
Here is an example of how you would add a probe to trace all new transactions by transaction ID.
</para>
</formalpara>
<procedure>
<step>
<para>
Name the probe transaction-start and give it a parameter of type integer (type of transaction ID)
</para>
</step>
<step>
<para>
Add <quote>probe transaction__start(int);</quote> to
<filename>src/backend/src/utils/probes.d</>, and it should look like the following:
<programlisting>
<programlisting>
PG_TRACE3 (my__complex__event, varX, varY, varZ);
provider postgresql {
...
probe transaction__start(int);
...
};
</programlisting>
</programlisting>
The definition of the transaction__start trace point is shown below:
Note the use of the double underline in the probe name. In the DTrace
script, the double underline needs to be replaced with a hyphen.
</para>
<para>
You should take care that the data types specified for the probe arguments
match the data types of the variables used in the macro. Otherwise, you
will get compilation errors.
</para>
</step>
<step>
<para>
At compile time, transaction__start is converted to a macro called
TRACE_POSTGRESQL_TRANSACTION_START, and it resides in
<filename>src/backend/src/utils/probes.h</>. Before recompiling, add
the single line macro to the appropriate location in the source code.
In this case, it looks like the following:
</para>
<para>
<programlisting>
<programlisting>
static void
static void
StartTransaction(void)
StartTransaction(void)
...
@@ -1150,13 +1204,13 @@ StartTransaction(void)
...
@@ -1150,13 +1204,13 @@ StartTransaction(void)
...
...
/*
/*
* generate a new transaction id
* Advertise it in the proc array. We assume assignment of
* LocalTransactionID is atomic, and the backendId should be set already.
*/
*/
s->transactionId = GetNewTransactionId(false);
Assert(MyProc->backendId == vxid.backendId);
MyProc->lxid = vxid.localTransactionId;
XactLockTableInsert(s->transactionId);
TRACE_POSTGRESQL_TRANSACTION_START(vxid.localTransactionId);
PG_TRACE1(transaction__start, s->transactionId);
...
...
}
}
...
@@ -1164,30 +1218,26 @@ StartTransaction(void)
...
@@ -1164,30 +1218,26 @@ StartTransaction(void)
Note how the transaction ID is made available to the dynamic tracing
Note how the transaction ID is made available to the dynamic tracing
utility.
utility.
</para>
</para>
</step>
<step>
<para>
<para>
The dynamic tracing utility might require you to further define these trace
After recompiling and running the new binary, check that your newly added
points. For example, DTrace requires you to add new probes to the file
probe is available by executing the following DTrace command, and you
<filename>src/backend/utils/probes.d</> as shown here:
should see similar output.
<programlisting>
<screen>
provider postgresql {
# dtrace -ln transaction-start
...
ID PROVIDER MODULE FUNCTION NAME
probe transaction__start(int);
18705 postgresql49878 postgres StartTransactionCommand transaction-start
...
18755 postgresql49877 postgres StartTransactionCommand transaction-start
};
18805 postgresql49876 postgres StartTransactionCommand transaction-start
</programlisting>
18855 postgresql49875 postgres StartTransactionCommand transaction-start
18986 postgresql49873 postgres StartTransactionCommand transaction-start
</screen>
</para>
</para>
</step>
</procedure>
<para>
You should take care that the data types specified for the probe arguments
match the data types of the variables used in the <literal>PG_TRACE</>
macro. This is not checked at compile time. You can check that your newly
added trace point is available by recompiling, then running the new binary,
and as root, executing a DTrace command such as:
<programlisting>
dtrace -l -n transaction-start
</programlisting>
</para>
</sect2>
</sect2>
</sect1>
</sect1>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment