From c3318aa3dd1fe2a117248e2191d68643dee243f0 Mon Sep 17 00:00:00 2001 From: Hugo Benichi Date: Tue, 5 Sep 2017 13:25:07 +0900 Subject: [PATCH] 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 26bcfa19d01758c86a8f43a5b39673cd5866d2f3) Change-Id: I4d6bb43110916b440819813b478523546ac5570e --- .../java/com/android/server/ConnectivityService.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index 874303d39c88..60476447ca49 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -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 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)); } -- 2.11.0