ConnectivityService: improve wakelock logging
This patch adds the following wakelock related counters to connectivity
service dumps included in bug reports:
- total number of wakelok acquisitions and releases
- total cumulative wakelock duration
- longest time the lock was held
Bug: 65085354
Test: runtest frameworks-net, also manually dumped connectivity service
and check new logging
Merged-In: I8f67750c2eea73abf3d44f7f6df484427a8ea3f9
Merged-In: I93c0eb7c8add966378647400e11e33765d952345
Merged-In: Iabe99993001e069b8a8077533bca1fa7fb2f59ba
(cherry picked from commit 88f49acd03)
Change-Id: I4d6bb43110916b440819813b478523546ac5570e
This commit is contained in:
@@ -458,6 +458,11 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
|
||||
private static final int MAX_WAKELOCK_LOGS = 20;
|
||||
private final LocalLog mWakelockLogs = new LocalLog(MAX_WAKELOCK_LOGS);
|
||||
private int mTotalWakelockAcquisitions = 0;
|
||||
private int mTotalWakelockReleases = 0;
|
||||
private long mTotalWakelockDurationMs = 0;
|
||||
private long mMaxWakelockDurationMs = 0;
|
||||
private long mLastWakeLockAcquireTimestamp = 0;
|
||||
|
||||
// Array of <Network,ReadOnlyLocalLogs> tracking network validation and results
|
||||
private static final int MAX_VALIDATION_LOGS = 10;
|
||||
@@ -1959,6 +1964,14 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
pw.println();
|
||||
pw.println("NetTransition WakeLock activity (most recent first):");
|
||||
pw.increaseIndent();
|
||||
pw.println("total acquisitions: " + mTotalWakelockAcquisitions);
|
||||
pw.println("total releases: " + mTotalWakelockReleases);
|
||||
pw.println("cumulative duration: " + (mTotalWakelockDurationMs / 1000) + "s");
|
||||
pw.println("longest duration: " + (mMaxWakelockDurationMs / 1000) + "s");
|
||||
if (mTotalWakelockAcquisitions > mTotalWakelockReleases) {
|
||||
long duration = SystemClock.elapsedRealtime() - mLastWakeLockAcquireTimestamp;
|
||||
pw.println("currently holding WakeLock for: " + (duration / 1000) + "s");
|
||||
}
|
||||
mWakelockLogs.reverseDump(fd, pw, args);
|
||||
pw.decreaseIndent();
|
||||
}
|
||||
@@ -3012,6 +3025,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
return;
|
||||
}
|
||||
mNetTransitionWakeLock.acquire();
|
||||
mLastWakeLockAcquireTimestamp = SystemClock.elapsedRealtime();
|
||||
mTotalWakelockAcquisitions++;
|
||||
}
|
||||
mWakelockLogs.log("ACQUIRE for " + forWhom);
|
||||
Message msg = mHandler.obtainMessage(EVENT_EXPIRE_NET_TRANSITION_WAKELOCK);
|
||||
@@ -3044,6 +3059,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
return;
|
||||
}
|
||||
mNetTransitionWakeLock.release();
|
||||
long lockDuration = SystemClock.elapsedRealtime() - mLastWakeLockAcquireTimestamp;
|
||||
mTotalWakelockDurationMs += lockDuration;
|
||||
mMaxWakelockDurationMs = Math.max(mMaxWakelockDurationMs, lockDuration);
|
||||
mTotalWakelockReleases++;
|
||||
}
|
||||
mWakelockLogs.log(String.format("RELEASE (%s)", event));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user