|
- transaction__start
+ transaction-start
(int transactionId)
The start of a new transaction.
|
- transaction__commit
+ transaction-commit
(int transactionId)
The successful completion of a transaction.
|
- transaction__abort
+ transaction-abort
(int transactionId)
The unsuccessful completion of a transaction.
|
- lwlock__acquire
+ lwlock-acquire
(int lockid, int mode)
An LWLock has been acquired.
|
- lwlock__release
+ lwlock-release
(int lockid, int mode)
An LWLock has been released.
|
- lwlock__startwait
+ lwlock-startwait
(int lockid, int mode)
An LWLock was not immediately available and a backend
has begun to wait for the lock to become available.
|
- lwlock__endwait
+ lwlock-endwait
(int lockid, int mode)
A backend has been released from its wait for an LWLock.
|
- lwlock__condacquire
+ lwlock-condacquire
(int lockid, int mode)
An LWLock was successfully acquired when the caller specified no
waiting.
|
- lwlock__condacquire__fail
+ lwlock-condacquire-fail
(int lockid, int mode)
An LWLock was not successfully acquired when the caller specified
no waiting.
|
- lock__startwait
+ lock-startwait
(int locktag_field2, int lockmode)
A request for a heavyweight lock (lmgr lock) has begun to wait
because the lock is not available.
|
- lock__endwait
+ lock-endwait
(int locktag_field2, int lockmode)
A request for a heavyweight lock (lmgr lock) has finished waiting
(i.e., has acquired the lock).
-
Using Trace Points
+
Using Probes
The example below shows a DTrace script for analyzing transaction
self->ts=0;
}
- 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:
-# ./txn_count.d `pgrep -n postgres`
+# ./txn_count.d `pgrep -n postgres` or ./txn_count.d <PID>
^C
Start 71
- You should remember that trace programs need to be carefully written and
+ You should remember that DTrace scripts need to be carefully written and
debugged prior to their use, otherwise the trace information collected might
be meaningless. In most cases where problems are found it is the
instrumentation that is at fault, not the underlying system. When
-
Defining Trace Points
+
Defining New Probes
- New trace points can be defined within the code wherever the developer
- desires, though this will require a recompilation.
+ New probes can be defined within the code wherever the developer
+ desires, though this will require a recompilation. Below are the steps
+ for inserting new probes:
- A trace point can be inserted by using one of the
- trace macros. These are chosen according to how many variables will
- be made available for inspection at that trace point. Tracing the
- occurrence of an event can be achieved with a single line, using
- just the trace point name, e.g.:
-PG_TRACE (my__new__trace__point);
-
- More complex trace points can be provided with one or more variables
- for inspection by the dynamic tracing utility by using the
- PG_TRACE>n> macro that corresponds to the number
- of parameters after the trace point name:
+
+ Decide on probe names and data to be made available through the probes
+
+
+
+
+ Add the probe definitons to src/backend/src/utils/probes.d>
+
+
+
+
+ Insert a one-line probe macros at the desired locations in the source code
+
+
+
+
+ Recompile and verify that the new probes are available
+
+
+
+
+
+
Example:
+ Here is an example of how you would add a probe to trace all new transactions by transaction ID.
+
+
+
+
+ Name the probe transaction-start and give it a parameter of type integer (type of transaction ID)
+
+
+
+
+ Add probe transaction__start(int);
to
+ src/backend/src/utils/probes.d>, and it should look like the following:
-PG_TRACE3 (my__complex__event, varX, varY, varZ);
+provider postgresql {
+ ...
+ probe transaction__start(int);
+ ...
+ };
- 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.
+
+
+ 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.
+
+
+
+
+ At compile time, transaction__start is converted to a macro called
+ TRACE_POSTGRESQL_TRANSACTION_START, and it resides in
+ 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:
+
+
static void
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);
-
- PG_TRACE1(transaction__start, s->transactionId);
+ TRACE_POSTGRESQL_TRANSACTION_START(vxid.localTransactionId);
...
}
- Note how the transaction ID is made available to the dynamic tracing
- utility.
-
+ Note how the transaction ID is made available to the dynamic tracing
+ utility.
+
+
- The dynamic tracing utility might require you to further define these trace
- points. For example, DTrace requires you to add new probes to the file
- src/backend/utils/probes.d> as shown here:
-provider postgresql {
- ...
- probe transaction__start(int);
- ...
- };
-
-
+
+ After recompiling and running the new binary, check that your newly added
+ probe is available by executing the following DTrace command, and you
+ should see similar output.
+
+# dtrace -ln transaction-start
+ ID PROVIDER MODULE FUNCTION NAME
+18705 postgresql49878 postgres StartTransactionCommand transaction-start
+18755 postgresql49877 postgres StartTransactionCommand transaction-start
+18805 postgresql49876 postgres StartTransactionCommand transaction-start
+18855 postgresql49875 postgres StartTransactionCommand transaction-start
+18986 postgresql49873 postgres StartTransactionCommand transaction-start
+
+
+
+
- You should take care that the data types specified for the probe arguments
- match the data types of the variables used in the 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:
-dtrace -l -n transaction-start
-
-