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

Commit d14e690e authored by Blake Kragten's avatar Blake Kragten
Browse files

Add GnssPowerStats Metrics

Adding energy consumption values metrics. These report different levels
of GNSS functionality to get a better understanding of GNSS energy usage.

Design doc: http://doc/1tgHcXFH2hF50PZyJopSwcO5aDC2yCSlqhBmAyThcMJk

Bug: 174181772
Test: atest GnssPowerStatsTests
Change-Id: I73183b5a89e66c314c3884177e9115c507e9dc96
parent 31d065f5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -81,7 +81,7 @@ public class GnssManagerService {
        mGnssNative = gnssNative;

        mGnssMetrics = new GnssMetrics(mContext, IBatteryStats.Stub.asInterface(
                ServiceManager.getService(BatteryStats.SERVICE_NAME)));
                ServiceManager.getService(BatteryStats.SERVICE_NAME)), mGnssNative);

        mGnssLocationProvider = new GnssLocationProvider(mContext, injector, mGnssNative,
                mGnssMetrics);
+75 −22
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import com.android.internal.location.nano.GnssLogsProto.GnssLog;
import com.android.internal.location.nano.GnssLogsProto.PowerMetrics;
import com.android.internal.util.ConcurrentUtils;
import com.android.internal.util.FrameworkStatsLog;
import com.android.server.location.gnss.hal.GnssNative;

import java.util.ArrayList;
import java.util.Arrays;
@@ -52,11 +53,14 @@ public class GnssMetrics {

    /** Default time between location fixes (in millisecs) */
    private static final int DEFAULT_TIME_BETWEEN_FIXES_MILLISECS = 1000;
    private static final int CONVERT_MILLI_TO_MICRO = 1000;
    private static final int VENDOR_SPECIFIC_POWER_MODES_SIZE = 10;

    /** Frequency range of GPS L5, Galileo E5a, QZSS J5 frequency band */
    private static final double L5_CARRIER_FREQ_RANGE_LOW_HZ = 1164 * 1e6;
    private static final double L5_CARRIER_FREQ_RANGE_HIGH_HZ = 1189 * 1e6;


    private long mLogStartInElapsedRealtimeMs;

    GnssPowerMetrics mGnssPowerMetrics;
@@ -88,8 +92,10 @@ public class GnssMetrics {
    long mL5SvStatusReportsUsedInFix;

    private final StatsManager mStatsManager;
    private final GnssNative mGnssNative;

    public GnssMetrics(Context context, IBatteryStats stats) {
    public GnssMetrics(Context context, IBatteryStats stats, GnssNative gnssNative) {
        mGnssNative = gnssNative;
        mGnssPowerMetrics = new GnssPowerMetrics(stats);
        mLocationFailureStatistics = new Statistics();
        mTimeToFirstFixSecStatistics = new Statistics();
@@ -432,7 +438,8 @@ public class GnssMetrics {
        private double mSumSquare;
        private long mLongSum;

        Statistics() {}
        Statistics() {
        }

        /** Resets statistics */
        public synchronized void reset() {
@@ -585,6 +592,10 @@ public class GnssMetrics {
                FrameworkStatsLog.GNSS_STATS,
                null, // use default PullAtomMetadata values
                ConcurrentUtils.DIRECT_EXECUTOR, pullAtomCallback);
        mStatsManager.setPullAtomCallback(
                FrameworkStatsLog.GNSS_POWER_STATS,
                null, // use default PullAtomMetadata values
                ConcurrentUtils.DIRECT_EXECUTOR, pullAtomCallback);
    }

    /**
@@ -593,13 +604,12 @@ public class GnssMetrics {
     */
    private class StatsPullAtomCallbackImpl implements StatsManager.StatsPullAtomCallback {

        StatsPullAtomCallbackImpl() {}
        StatsPullAtomCallbackImpl() {
        }

        @Override
        public int onPullAtom(int atomTag, List<StatsEvent> data) {
            if (atomTag != FrameworkStatsLog.GNSS_STATS) {
                throw new UnsupportedOperationException("Unknown tagId = " + atomTag);
            }
            if (atomTag == FrameworkStatsLog.GNSS_STATS) {
                data.add(FrameworkStatsLog.buildStatsEvent(atomTag,
                        mLocationFailureReportsStatistics.getCount(),
                        mLocationFailureReportsStatistics.getLongSum(),
@@ -611,7 +621,50 @@ public class GnssMetrics {
                        mTopFourAverageCn0DbmHzReportsStatistics.getLongSum(),
                        mL5TopFourAverageCn0DbmHzReportsStatistics.getCount(),
                        mL5TopFourAverageCn0DbmHzReportsStatistics.getLongSum(), mSvStatusReports,
                    mSvStatusReportsUsedInFix, mL5SvStatusReports, mL5SvStatusReportsUsedInFix));
                        mSvStatusReportsUsedInFix, mL5SvStatusReports,
                        mL5SvStatusReportsUsedInFix));
            } else if (atomTag == FrameworkStatsLog.GNSS_POWER_STATS) {
                mGnssNative.requestPowerStats();
                GnssPowerStats gnssPowerStats = mGnssNative.getPowerStats();
                if (gnssPowerStats == null) {
                    return StatsManager.PULL_SKIP;
                }
                double[] otherModesEnergyMilliJoule = new double[VENDOR_SPECIFIC_POWER_MODES_SIZE];
                double[] tempGnssPowerStatsOtherModes =
                        gnssPowerStats.getOtherModesEnergyMilliJoule();
                if (tempGnssPowerStatsOtherModes.length < VENDOR_SPECIFIC_POWER_MODES_SIZE) {
                    System.arraycopy(tempGnssPowerStatsOtherModes, 0,
                            otherModesEnergyMilliJoule, 0,
                            tempGnssPowerStatsOtherModes.length);
                } else {
                    System.arraycopy(tempGnssPowerStatsOtherModes, 0,
                            otherModesEnergyMilliJoule, 0,
                            VENDOR_SPECIFIC_POWER_MODES_SIZE);
                }
                data.add(FrameworkStatsLog.buildStatsEvent(atomTag,
                        (long) (gnssPowerStats.getElapsedRealtimeUncertaintyNanos()),
                        (long) (gnssPowerStats.getTotalEnergyMilliJoule() * CONVERT_MILLI_TO_MICRO),
                        (long) (gnssPowerStats.getSinglebandTrackingModeEnergyMilliJoule()
                                * CONVERT_MILLI_TO_MICRO),
                        (long) (gnssPowerStats.getMultibandTrackingModeEnergyMilliJoule()
                                * CONVERT_MILLI_TO_MICRO),
                        (long) (gnssPowerStats.getSinglebandAcquisitionModeEnergyMilliJoule()
                                * CONVERT_MILLI_TO_MICRO),
                        (long) (gnssPowerStats.getMultibandAcquisitionModeEnergyMilliJoule()
                                * CONVERT_MILLI_TO_MICRO),
                        (long) (otherModesEnergyMilliJoule[0] * CONVERT_MILLI_TO_MICRO),
                        (long) (otherModesEnergyMilliJoule[1] * CONVERT_MILLI_TO_MICRO),
                        (long) (otherModesEnergyMilliJoule[2] * CONVERT_MILLI_TO_MICRO),
                        (long) (otherModesEnergyMilliJoule[3] * CONVERT_MILLI_TO_MICRO),
                        (long) (otherModesEnergyMilliJoule[4] * CONVERT_MILLI_TO_MICRO),
                        (long) (otherModesEnergyMilliJoule[5] * CONVERT_MILLI_TO_MICRO),
                        (long) (otherModesEnergyMilliJoule[6] * CONVERT_MILLI_TO_MICRO),
                        (long) (otherModesEnergyMilliJoule[7] * CONVERT_MILLI_TO_MICRO),
                        (long) (otherModesEnergyMilliJoule[8] * CONVERT_MILLI_TO_MICRO),
                        (long) (otherModesEnergyMilliJoule[9] * CONVERT_MILLI_TO_MICRO)));
            } else {
                throw new UnsupportedOperationException("Unknown tagId = " + atomTag);
            }
            return StatsManager.PULL_SUCCESS;
        }
    }