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

Commit f3ddbb68 authored by Sudheer Shanka's avatar Sudheer Shanka Committed by android-build-merger
Browse files

Merge "Avoid excessive logging when the necessary proc file is unavailable."...

Merge "Avoid excessive logging when the necessary proc file is unavailable." into oc-dev am: ab17493e
am: 599bc3f1

Change-Id: I3ad80361f65f6de1f06f9758219d02272b300c68
parents 18faa022 599bc3f1
Loading
Loading
Loading
Loading
+11 −0
Original line number Original line Diff line number Diff line
@@ -53,10 +53,21 @@ public class KernelUidCpuFreqTimeReader {


    private SparseArray<long[]> mLastUidCpuFreqTimeMs = new SparseArray<>();
    private SparseArray<long[]> mLastUidCpuFreqTimeMs = new SparseArray<>();


    // We check the existence of proc file a few times (just in case it is not ready yet when we
    // start reading) and if it is not available, we simply ignore further read requests.
    private static final int TOTAL_READ_ERROR_COUNT = 5;
    private int mReadErrorCounter;
    private boolean mProcFileAvailable;

    public void readDelta(@Nullable Callback callback) {
    public void readDelta(@Nullable Callback callback) {
        if (!mProcFileAvailable && mReadErrorCounter >= TOTAL_READ_ERROR_COUNT) {
            return;
        }
        try (BufferedReader reader = new BufferedReader(new FileReader(UID_TIMES_PROC_FILE))) {
        try (BufferedReader reader = new BufferedReader(new FileReader(UID_TIMES_PROC_FILE))) {
            readDelta(reader, callback);
            readDelta(reader, callback);
            mProcFileAvailable = true;
        } catch (IOException e) {
        } catch (IOException e) {
            mReadErrorCounter++;
            Slog.e(TAG, "Failed to read " + UID_TIMES_PROC_FILE + ": " + e);
            Slog.e(TAG, "Failed to read " + UID_TIMES_PROC_FILE + ": " + e);
        }
        }
    }
    }