From 622fa53c64c75d7daaec2aa914b754e5bd17a395 Mon Sep 17 00:00:00 2001 From: Eric House Date: Thu, 25 Apr 2019 11:54:11 -0700 Subject: [PATCH] always log stack of lock held more than 1 minute (DEBUG only) I'm seeing deadlocks in a non-reproducible way and need to get at the source. This should log the stacks of long-held locks, and notify via Toast (when possible) when it occurs. --- .../main/java/org/eehouse/android/xw4/GameLock.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameLock.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameLock.java index f6e1d09c8..9a7720e32 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameLock.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameLock.java @@ -261,11 +261,17 @@ public class GameLock implements AutoCloseable, Serializable { private void logIfNull( GameLock result, String fmt, Object... args ) { - if ( DEBUG_LOCKS && null == result ) { + if ( BuildConfig.DEBUG && null == result ) { String func = new Formatter().format( fmt, args ).toString(); Log.d( TAG, "%s.%s => null", this, func ); + Owner curOwner = mOwners.peek(); Log.d( TAG, "Unable to lock; cur owner: %s; would-be owner: %s", - mOwners.peek(), new Owner() ); + curOwner, new Owner() ); + + long heldMS = System.currentTimeMillis() - curOwner.mStamp; + if ( heldMS > (60 * 1000) ) { // 1 minute's a long time + DbgUtils.showf( "GameLock: logged owner held for %d seconds!", heldMS / 1000 ); + } } } }