Debugging Perforce Database Locking

Info & Tags

Article #:
630
Created:
01/26/07
Modified:
10/14/08
Tags:
database, locking, p4, p4d

Related Articles

Links

PROBLEM

How can I tell what tables a command is locking?


SOLUTION

By including -Ztrack in your P4 command, you can see what tables a command is accessing, and implicitly locking. In addition to the command's usual output, the "track" information includes the table name and the type of locks obtained on that table.

Example

Running p4 counters with 'track' output.

p4 -Ztrack counters
change = 12193
job = 28
journal = 64
upgrade = 15
--- lapse .032s
--- rpc msgs/size in+out 2+6/0mb+0mb
--- db.counters
---   pages in+out+cached 2+0+1
---   locks read/write 1/0 rows get+pos+scan put+del 0+1+5 0+0
--- db.user
---   pages in+out+cached 3+2+2
---   locks read/write 0/1 rows get+pos+scan put+del 1+0+0 1+0
--- db.group
---   pages in+out+cached 2+0+1
---   locks read/write 1/0 rows get+pos+scan put+del 0+2+3 0+0
--- db.domain
---   pages in+out+cached 2+0+1
---   locks read/write 0/1 rows get+pos+scan put+del 1+0+0 0+0
--- db.view
---   pages in+out+cached 3+0+2
---   locks read/write 1/0 rows get+pos+scan put+del 0+1+17 0+0
--- db.protect
---   pages in+out+cached 2+0+1
---   locks read/write 1/0 rows get+pos+scan put+del 0+1+12 0+0
--- db.monitor
---   pages in+out+cached 3+4+2
---   locks read/write 0/2 rows get+pos+scan put+del 0+0+0 1+1
If you just need a list of tables locked by a given command, you can reduce this output in various ways using pattern-matching utilities such as "grep" and "findstr".  For example:
p4 -Ztrack counters | grep "\--- db."
--- db.counters
--- db.user
--- db.group
--- db.domain
--- db.view
--- db.protect
--- db.monitor
Notes

The Server Performance Tracking information was introduced in the 2005.2 release. The method above shows how to enable the tracking for individual commands using The Perforce Command-Line Client. It is possible to enable tracking on the server, in which case the additional detail is written to the server log file. To enable tracking on the server set P4DEBUG in the Perforce Server environment, or include -Vtrack=x (where "x" is the number that determines the level of tracking) in the command line that starts the Perforce server.

If using releases earlier than 2005.2, the dbstat flag provides similar information.
p4 -Zdbstat counters
There are a variety of system tools for detecting file locks such as lsof, truss and FileMon.exe.