Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 89e09c39 authored by Tri Vo's avatar Tri Vo Committed by Gerrit Code Review
Browse files

Merge "KernelWakelockReader: reuse buffer when parsing"

parents 7ae1299c b9ad9a68
Loading
Loading
Loading
Loading
+10 −6
Original line number Original line Diff line number Diff line
@@ -29,6 +29,7 @@ import com.android.internal.annotations.VisibleForTesting;


import java.io.File;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileInputStream;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Iterator;


/**
/**
@@ -66,6 +67,7 @@ public class KernelWakelockReader {
    private final String[] mProcWakelocksName = new String[3];
    private final String[] mProcWakelocksName = new String[3];
    private final long[] mProcWakelocksData = new long[3];
    private final long[] mProcWakelocksData = new long[3];
    private ISuspendControlService mSuspendControlService = null;
    private ISuspendControlService mSuspendControlService = null;
    private byte[] mKernelWakelockBuffer = new byte[32 * 1024];


    /**
    /**
     * Reads kernel wakelock stats and updates the staleStats with the new information.
     * Reads kernel wakelock stats and updates the staleStats with the new information.
@@ -84,7 +86,7 @@ public class KernelWakelockReader {
            }
            }
            return removeOldStats(staleStats);
            return removeOldStats(staleStats);
        } else {
        } else {
            byte[] buffer = new byte[32*1024];
            Arrays.fill(mKernelWakelockBuffer, (byte) 0);
            int len = 0;
            int len = 0;
            boolean wakeup_sources;
            boolean wakeup_sources;
            final long startTime = SystemClock.uptimeMillis();
            final long startTime = SystemClock.uptimeMillis();
@@ -107,7 +109,8 @@ public class KernelWakelockReader {
                }
                }


                int cnt;
                int cnt;
                while ((cnt = is.read(buffer, len, buffer.length - len)) > 0) {
                while ((cnt = is.read(mKernelWakelockBuffer, len,
                                mKernelWakelockBuffer.length - len)) > 0) {
                    len += cnt;
                    len += cnt;
                }
                }


@@ -125,12 +128,13 @@ public class KernelWakelockReader {
            }
            }


            if (len > 0) {
            if (len > 0) {
                if (len >= buffer.length) {
                if (len >= mKernelWakelockBuffer.length) {
                    Slog.wtf(TAG, "Kernel wake locks exceeded buffer size " + buffer.length);
                    Slog.wtf(TAG, "Kernel wake locks exceeded mKernelWakelockBuffer size "
                            + mKernelWakelockBuffer.length);
                }
                }
                int i;
                int i;
                for (i=0; i<len; i++) {
                for (i=0; i<len; i++) {
                    if (buffer[i] == '\0') {
                    if (mKernelWakelockBuffer[i] == '\0') {
                        len = i;
                        len = i;
                        break;
                        break;
                    }
                    }
@@ -143,7 +147,7 @@ public class KernelWakelockReader {
                Slog.w(TAG, "Failed to get Native wakelock stats from SystemSuspend");
                Slog.w(TAG, "Failed to get Native wakelock stats from SystemSuspend");
            }
            }
            // Get kernel wakelock stats
            // Get kernel wakelock stats
            parseProcWakelocks(buffer, len, wakeup_sources, staleStats);
            parseProcWakelocks(mKernelWakelockBuffer, len, wakeup_sources, staleStats);
            return removeOldStats(staleStats);
            return removeOldStats(staleStats);
        }
        }
    }
    }