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

Commit ef0904ea authored by Ruchir Rastogi's avatar Ruchir Rastogi
Browse files

Move GnssStats puller to binder thread

Pass direct executor to setPullAtomCallback. This causes the puller to
run directly on the binder thread, as opposed to the Background thread,
which could be busy with other work.

This change means that the puller can be executed concurrently. To
properly handle that, the Statistics class is made thread-safe.

Test: adb shell cmd stats pull-source 10074
Bug: 157186182
Change-Id: I6c0940fd4ed231f9d962981cc1f9e8c983c48f7f
parent 5ea18c90
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ import android.util.TimeUtils;
import com.android.internal.app.IBatteryStats;
import com.android.internal.location.nano.GnssLogsProto.GnssLog;
import com.android.internal.location.nano.GnssLogsProto.PowerMetrics;
import com.android.internal.os.BackgroundThread;
import com.android.internal.util.ConcurrentUtils;
import com.android.internal.util.FrameworkStatsLog;

import java.util.ArrayList;
@@ -465,7 +465,7 @@ public class GnssMetrics {
        mConstellationTypes = new boolean[GnssStatus.CONSTELLATION_COUNT];
    }

    /** Class for storing statistics */
    /** Thread-safe class for storing statistics */
    private static class Statistics {

        private int mCount;
@@ -474,7 +474,7 @@ public class GnssMetrics {
        private long mLongSum;

        /** Resets statistics */
        public void reset() {
        public synchronized void reset() {
            mCount = 0;
            mSum = 0.0;
            mSumSquare = 0.0;
@@ -482,7 +482,7 @@ public class GnssMetrics {
        }

        /** Adds an item */
        public void addItem(double item) {
        public synchronized void addItem(double item) {
            mCount++;
            mSum += item;
            mSumSquare += item * item;
@@ -490,17 +490,17 @@ public class GnssMetrics {
        }

        /** Returns number of items added */
        public int getCount() {
        public synchronized int getCount() {
            return mCount;
        }

        /** Returns mean */
        public double getMean() {
        public synchronized double getMean() {
            return mSum / mCount;
        }

        /** Returns standard deviation */
        public double getStandardDeviation() {
        public synchronized double getStandardDeviation() {
            double m = mSum / mCount;
            m = m * m;
            double v = mSumSquare / mCount;
@@ -511,7 +511,7 @@ public class GnssMetrics {
        }

        /** Returns long sum */
        public long getLongSum() {
        public synchronized long getLongSum() {
            return mLongSum;
        }
    }
@@ -625,7 +625,7 @@ public class GnssMetrics {
        mStatsManager.setPullAtomCallback(
                FrameworkStatsLog.GNSS_STATS,
                null, // use default PullAtomMetadata values
                BackgroundThread.getExecutor(), pullAtomCallback);
                ConcurrentUtils.DIRECT_EXECUTOR, pullAtomCallback);
    }

    /**