Example of Displaying Lock Contention Information
The following example shows how to display recorded lock contention information.
showLockContentions(); vars oa : ObjectArray; o : Object; lci : LockContentionInfo; ts : TimeStamp; avgWaitTime : Decimal[10,1]; begin create oa transient; system.beginLockContentionStats(10000); process.sleep(60000); //record 1 minute of lock activity system.getLockContentionStats(oa, 10000, 5, ts); write "FIRST MINUTE"; foreach o in oa do lci := o.LockContentionInfo; write CrLf & "Object= " & lci.target.String; write "Contentions= " & lci.totalContentions.String; avgWaitTime := (lci.totalWaitTime / lci.totalContentions); write "Average wait time= " & avgWaitTime.String; endforeach; oa.purge; //Repeat system.clearLockContentionStats(); process.sleep(60000); //record 1 minute of lock activity system.getLockContentionStats(oa, 10000, 5, ts); write CrLf & "SECOND MINUTE"; foreach o in oa do lci := o.LockContentionInfo; write CrLf & "Object= " & lci.target.String; write "Contentions= " & lci.totalContentions.String; avgWaitTime := (lci.totalWaitTime / lci.totalContentions); write "Average wait time= " & avgWaitTime.String; endforeach; oa.purge; system.endLockContentionStats(); epilog delete oa; end;
The output from the LockContentionInfo method shown in the previous example is as follows.
FIRST MINUTE Object= Branch/2631.1 Contentions= 8 Average wait time= 4516.0 Object= Account/2635.2 Contentions= 6 Average wait time= 3531.0 SECOND MINUTE Object= Branch/2631.1 Contentions= 9 Average wait time= 2640.0 Object= Account/2635.1 Contentions= 6 Average wait time= 2250.0 Object= Account/2635.2 Contentions= 6 Average wait time= 1937.0 Object= Account/2635.3 Contentions= 8 Average wait time= 5046.0