A system and method is provided for measuring lock usage in a
non-intrusive manner. Measurements are performed only when a lock is
contended. When a lock is requested and the lock is available (i.e., is
not contended), the only data gathered is a counter that is incremented
to keep track of the number of times the particular lock was requested.
When a lock is contended, an operating system trace hook is requested.
The trace hook records data such as the timestamp that the requestor
requested the lock, the request count, a stack traceback to identify the
function corresponding to the requestor, and the address of the lock that
was requested. Post-operative processing analyzes the recorded trace hook
data to identify contended locks and processes that may not be
efficiently using locks.