@@ -101,6 +101,16 @@ public Long initialValue() {
101101 private final AtomicLong timeStampOfLastReadLockReportMs = new AtomicLong (0 );
102102 /** Longest time (ms) a read lock was held since the last report. */
103103 private final AtomicLong longestReadLockHeldIntervalMs = new AtomicLong (0 );
104+ /**
105+ * The number of time the read lock
106+ * has been held longer than the threshold.
107+ */
108+ private final AtomicLong numReadLockLongHold = new AtomicLong (0 );
109+ /**
110+ * The number of time the write lock
111+ * has been held for longer than the threshold.
112+ */
113+ private final AtomicLong numWriteLockLongHold = new AtomicLong (0 );
104114
105115 @ VisibleForTesting
106116 static final String OP_NAME_OTHER = "OTHER" ;
@@ -168,6 +178,7 @@ public void readUnlock(String opName) {
168178 final long readLockIntervalMs =
169179 TimeUnit .NANOSECONDS .toMillis (readLockIntervalNanos );
170180 if (needReport && readLockIntervalMs >= this .readLockReportingThresholdMs ) {
181+ numReadLockLongHold .incrementAndGet ();
171182 long localLongestReadLock ;
172183 do {
173184 localLongestReadLock = longestReadLockHeldIntervalMs .get ();
@@ -224,6 +235,7 @@ public void writeUnlock(String opName) {
224235 LogAction logAction = LogThrottlingHelper .DO_NOT_LOG ;
225236 if (needReport &&
226237 writeLockIntervalMs >= this .writeLockReportingThresholdMs ) {
238+ numWriteLockLongHold .incrementAndGet ();
227239 logAction = writeLockReportLogger
228240 .record ("write" , currentTimeMs , writeLockIntervalMs );
229241 }
@@ -263,6 +275,28 @@ public Condition newWriteLockCondition() {
263275 return coarseLock .writeLock ().newCondition ();
264276 }
265277
278+ /**
279+ * Returns the number of time the read lock
280+ * has been held longer than the threshold.
281+ *
282+ * @return long - Number of time the read lock
283+ * has been held longer than the threshold
284+ */
285+ public long getNumOfReadLockLongHold () {
286+ return numReadLockLongHold .get ();
287+ }
288+
289+ /**
290+ * Returns the number of time the write lock
291+ * has been held longer than the threshold.
292+ *
293+ * @return long - Number of time the write lock
294+ * has been held longer than the threshold.
295+ */
296+ public long getNumOfWriteLockLongHold () {
297+ return numWriteLockLongHold .get ();
298+ }
299+
266300 /**
267301 * Returns the QueueLength of waiting threads.
268302 *
0 commit comments