Merge "KernelWakelockReader: reuse buffer when parsing"

am: 89e09c3918

Change-Id: I91a9577d618c64239dd7755d710a98ce085c05ba
This commit is contained in:
Tri Vo
2019-10-09 16:10:44 -07:00
committed by android-build-merger

View File

@@ -29,6 +29,7 @@ import com.android.internal.annotations.VisibleForTesting;
import java.io.File;
import java.io.FileInputStream;
import java.util.Arrays;
import java.util.Iterator;
/**
@@ -66,6 +67,7 @@ public class KernelWakelockReader {
private final String[] mProcWakelocksName = new String[3];
private final long[] mProcWakelocksData = new long[3];
private ISuspendControlService mSuspendControlService = null;
private byte[] mKernelWakelockBuffer = new byte[32 * 1024];
/**
* Reads kernel wakelock stats and updates the staleStats with the new information.
@@ -84,7 +86,7 @@ public class KernelWakelockReader {
}
return removeOldStats(staleStats);
} else {
byte[] buffer = new byte[32*1024];
Arrays.fill(mKernelWakelockBuffer, (byte) 0);
int len = 0;
boolean wakeup_sources;
final long startTime = SystemClock.uptimeMillis();
@@ -107,7 +109,8 @@ public class KernelWakelockReader {
}
int cnt;
while ((cnt = is.read(buffer, len, buffer.length - len)) > 0) {
while ((cnt = is.read(mKernelWakelockBuffer, len,
mKernelWakelockBuffer.length - len)) > 0) {
len += cnt;
}
@@ -125,12 +128,13 @@ public class KernelWakelockReader {
}
if (len > 0) {
if (len >= buffer.length) {
Slog.wtf(TAG, "Kernel wake locks exceeded buffer size " + buffer.length);
if (len >= mKernelWakelockBuffer.length) {
Slog.wtf(TAG, "Kernel wake locks exceeded mKernelWakelockBuffer size "
+ mKernelWakelockBuffer.length);
}
int i;
for (i=0; i<len; i++) {
if (buffer[i] == '\0') {
if (mKernelWakelockBuffer[i] == '\0') {
len = i;
break;
}
@@ -143,7 +147,7 @@ public class KernelWakelockReader {
Slog.w(TAG, "Failed to get Native wakelock stats from SystemSuspend");
}
// Get kernel wakelock stats
parseProcWakelocks(buffer, len, wakeup_sources, staleStats);
parseProcWakelocks(mKernelWakelockBuffer, len, wakeup_sources, staleStats);
return removeOldStats(staleStats);
}
}