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

Commit 1c572559 authored by Soonil Nagarkar's avatar Soonil Nagarkar
Browse files

Improve dumpsys formatting

Make dumpsys readable.

Test: n/a
Change-Id: Ie1701227b8dddaee7636c37f97c9469729e499c3
parent 1aaa574c
Loading
Loading
Loading
Loading
+335 −352
Original line number Diff line number Diff line
@@ -43,15 +43,15 @@ public class GnssMetrics {
    private static final String TAG = GnssMetrics.class.getSimpleName();

    /* Constant which indicates GPS signal quality is as yet unknown */
  public static final int GPS_SIGNAL_QUALITY_UNKNOWN =
    private static final int GPS_SIGNAL_QUALITY_UNKNOWN =
            ServerLocationProtoEnums.GPS_SIGNAL_QUALITY_UNKNOWN; // -1

    /* Constant which indicates GPS signal quality is poor */
  public static final int GPS_SIGNAL_QUALITY_POOR =
    private static final int GPS_SIGNAL_QUALITY_POOR =
            ServerLocationProtoEnums.GPS_SIGNAL_QUALITY_POOR; // 0

    /* Constant which indicates GPS signal quality is good */
  public static final int GPS_SIGNAL_QUALITY_GOOD =
    private static final int GPS_SIGNAL_QUALITY_GOOD =
            ServerLocationProtoEnums.GPS_SIGNAL_QUALITY_GOOD; // 1

    /* Number of GPS signal quality levels */
@@ -61,81 +61,72 @@ public class GnssMetrics {
    private static final int DEFAULT_TIME_BETWEEN_FIXES_MILLISECS = 1000;

    /* The time since boot when logging started */
  private String logStartInElapsedRealTime;
    private String mLogStartInElapsedRealTime;

    /* GNSS power metrics */
    private GnssPowerMetrics mGnssPowerMetrics;

    /**
     * A boolean array indicating whether the constellation types have been used in fix.
     */
    /* A boolean array indicating whether the constellation types have been used in fix. */
    private boolean[] mConstellationTypes;
    /** Location failure statistics */
    private Statistics mLocationFailureStatistics;
    /** Time to first fix statistics */
    private Statistics mTimeToFirstFixSecStatistics;
    /** Position accuracy statistics */
    private Statistics mPositionAccuracyMeterStatistics;
    /** Top 4 average CN0 statistics */
    private Statistics mTopFourAverageCn0Statistics;

  /** Constructor */
    public GnssMetrics(IBatteryStats stats) {
        mGnssPowerMetrics = new GnssPowerMetrics(stats);
    locationFailureStatistics = new Statistics();
    timeToFirstFixSecStatistics = new Statistics();
    positionAccuracyMeterStatistics = new Statistics();
    topFourAverageCn0Statistics = new Statistics();
        mLocationFailureStatistics = new Statistics();
        mTimeToFirstFixSecStatistics = new Statistics();
        mPositionAccuracyMeterStatistics = new Statistics();
        mTopFourAverageCn0Statistics = new Statistics();
        reset();
    }

    /**
     * Logs the status of a location report received from the HAL
   *
   * @param isSuccessful
     */
    public void logReceivedLocationStatus(boolean isSuccessful) {
        if (!isSuccessful) {
      locationFailureStatistics.addItem(1.0);
            mLocationFailureStatistics.addItem(1.0);
            return;
        }
    locationFailureStatistics.addItem(0.0);
    return;
        mLocationFailureStatistics.addItem(0.0);
    }

    /**
     * Logs missed reports
   *
   * @param desiredTimeBetweenFixesMilliSeconds
   * @param actualTimeBetweenFixesMilliSeconds
     */
    public void logMissedReports(int desiredTimeBetweenFixesMilliSeconds,
            int actualTimeBetweenFixesMilliSeconds) {
    int numReportMissed = (actualTimeBetweenFixesMilliSeconds /
        Math.max(DEFAULT_TIME_BETWEEN_FIXES_MILLISECS, desiredTimeBetweenFixesMilliSeconds)) - 1;
        int numReportMissed = (actualTimeBetweenFixesMilliSeconds / Math.max(
                DEFAULT_TIME_BETWEEN_FIXES_MILLISECS, desiredTimeBetweenFixesMilliSeconds)) - 1;
        if (numReportMissed > 0) {
            for (int i = 0; i < numReportMissed; i++) {
        locationFailureStatistics.addItem(1.0);
                mLocationFailureStatistics.addItem(1.0);
            }
        }
    return;
    }

    /**
     * Logs time to first fix
   *
   * @param timeToFirstFixMilliSeconds
     */
    public void logTimeToFirstFixMilliSecs(int timeToFirstFixMilliSeconds) {
    timeToFirstFixSecStatistics.addItem((double) (timeToFirstFixMilliSeconds/1000));
    return;
        mTimeToFirstFixSecStatistics.addItem((double) (timeToFirstFixMilliSeconds / 1000));
    }

    /**
     * Logs position accuracy
   *
   * @param positionAccuracyMeters
     */
    public void logPositionAccuracyMeters(float positionAccuracyMeters) {
    positionAccuracyMeterStatistics.addItem((double) positionAccuracyMeters);
    return;
        mPositionAccuracyMeterStatistics.addItem((double) positionAccuracyMeters);
    }

  /*
    /**
     * Logs CN0 when at least 4 SVs are available
  *
     */
    public void logCn0(float[] cn0s, int numSv) {
        if (numSv == 0 || cn0s == null || cn0s.length == 0 || cn0s.length < numSv) {
@@ -156,12 +147,10 @@ public class GnssMetrics {
                top4AvgCn0 += (double) cn0Array[i];
            }
            top4AvgCn0 /= 4;
      topFourAverageCn0Statistics.addItem(top4AvgCn0);
            mTopFourAverageCn0Statistics.addItem(top4AvgCn0);
        }
    return;
    }


    /**
     * Logs that a constellation type has been observed.
     */
@@ -175,31 +164,30 @@ public class GnssMetrics {

    /**
     * Dumps GNSS metrics as a proto string
   * @return
     */
    public String dumpGnssMetricsAsProtoString() {
        GnssLog msg = new GnssLog();
    if (locationFailureStatistics.getCount() > 0) {
      msg.numLocationReportProcessed = locationFailureStatistics.getCount();
      msg.percentageLocationFailure = (int) (100.0 * locationFailureStatistics.getMean());
    }
    if (timeToFirstFixSecStatistics.getCount() > 0) {
      msg.numTimeToFirstFixProcessed = timeToFirstFixSecStatistics.getCount();
      msg.meanTimeToFirstFixSecs = (int) timeToFirstFixSecStatistics.getMean();
      msg.standardDeviationTimeToFirstFixSecs
          = (int) timeToFirstFixSecStatistics.getStandardDeviation();
    }
    if (positionAccuracyMeterStatistics.getCount() > 0) {
      msg.numPositionAccuracyProcessed = positionAccuracyMeterStatistics.getCount();
      msg.meanPositionAccuracyMeters = (int) positionAccuracyMeterStatistics.getMean();
      msg.standardDeviationPositionAccuracyMeters
          = (int) positionAccuracyMeterStatistics.getStandardDeviation();
    }
    if (topFourAverageCn0Statistics.getCount() > 0) {
      msg.numTopFourAverageCn0Processed = topFourAverageCn0Statistics.getCount();
      msg.meanTopFourAverageCn0DbHz = topFourAverageCn0Statistics.getMean();
      msg.standardDeviationTopFourAverageCn0DbHz
          = topFourAverageCn0Statistics.getStandardDeviation();
        if (mLocationFailureStatistics.getCount() > 0) {
            msg.numLocationReportProcessed = mLocationFailureStatistics.getCount();
            msg.percentageLocationFailure = (int) (100.0 * mLocationFailureStatistics.getMean());
        }
        if (mTimeToFirstFixSecStatistics.getCount() > 0) {
            msg.numTimeToFirstFixProcessed = mTimeToFirstFixSecStatistics.getCount();
            msg.meanTimeToFirstFixSecs = (int) mTimeToFirstFixSecStatistics.getMean();
            msg.standardDeviationTimeToFirstFixSecs =
                    (int) mTimeToFirstFixSecStatistics.getStandardDeviation();
        }
        if (mPositionAccuracyMeterStatistics.getCount() > 0) {
            msg.numPositionAccuracyProcessed = mPositionAccuracyMeterStatistics.getCount();
            msg.meanPositionAccuracyMeters = (int) mPositionAccuracyMeterStatistics.getMean();
            msg.standardDeviationPositionAccuracyMeters =
                    (int) mPositionAccuracyMeterStatistics.getStandardDeviation();
        }
        if (mTopFourAverageCn0Statistics.getCount() > 0) {
            msg.numTopFourAverageCn0Processed = mTopFourAverageCn0Statistics.getCount();
            msg.meanTopFourAverageCn0DbHz = mTopFourAverageCn0Statistics.getMean();
            msg.standardDeviationTopFourAverageCn0DbHz =
                    mTopFourAverageCn0Statistics.getStandardDeviation();
        }
        msg.powerMetrics = mGnssPowerMetrics.buildProto();
        msg.hardwareRevision = SystemProperties.get("ro.boot.revision", "");
@@ -216,38 +204,39 @@ public class GnssMetrics {
    public String dumpGnssMetricsAsText() {
        StringBuilder s = new StringBuilder();
        s.append("GNSS_KPI_START").append('\n');
    s.append("  KPI logging start time: ").append(logStartInElapsedRealTime).append("\n");
        s.append("  KPI logging start time: ").append(mLogStartInElapsedRealTime).append("\n");
        s.append("  KPI logging end time: ");
        TimeUtils.formatDuration(SystemClock.elapsedRealtimeNanos() / 1000000L, s);
        s.append("\n");
        s.append("  Number of location reports: ").append(
        locationFailureStatistics.getCount()).append("\n");
    if (locationFailureStatistics.getCount() > 0) {
                mLocationFailureStatistics.getCount()).append("\n");
        if (mLocationFailureStatistics.getCount() > 0) {
            s.append("  Percentage location failure: ").append(
          100.0 * locationFailureStatistics.getMean()).append("\n");
                    100.0 * mLocationFailureStatistics.getMean()).append("\n");
        }
        s.append("  Number of TTFF reports: ").append(
        timeToFirstFixSecStatistics.getCount()).append("\n");
    if (timeToFirstFixSecStatistics.getCount() > 0) {
      s.append("  TTFF mean (sec): ").append(timeToFirstFixSecStatistics.getMean()).append("\n");
                mTimeToFirstFixSecStatistics.getCount()).append("\n");
        if (mTimeToFirstFixSecStatistics.getCount() > 0) {
            s.append("  TTFF mean (sec): ").append(mTimeToFirstFixSecStatistics.getMean()).append(
                    "\n");
            s.append("  TTFF standard deviation (sec): ").append(
          timeToFirstFixSecStatistics.getStandardDeviation()).append("\n");
                    mTimeToFirstFixSecStatistics.getStandardDeviation()).append("\n");
        }
        s.append("  Number of position accuracy reports: ").append(
        positionAccuracyMeterStatistics.getCount()).append("\n");
    if (positionAccuracyMeterStatistics.getCount() > 0) {
                mPositionAccuracyMeterStatistics.getCount()).append("\n");
        if (mPositionAccuracyMeterStatistics.getCount() > 0) {
            s.append("  Position accuracy mean (m): ").append(
          positionAccuracyMeterStatistics.getMean()).append("\n");
                    mPositionAccuracyMeterStatistics.getMean()).append("\n");
            s.append("  Position accuracy standard deviation (m): ").append(
          positionAccuracyMeterStatistics.getStandardDeviation()).append("\n");
                    mPositionAccuracyMeterStatistics.getStandardDeviation()).append("\n");
        }
        s.append("  Number of CN0 reports: ").append(
        topFourAverageCn0Statistics.getCount()).append("\n");
    if (topFourAverageCn0Statistics.getCount() > 0) {
                mTopFourAverageCn0Statistics.getCount()).append("\n");
        if (mTopFourAverageCn0Statistics.getCount() > 0) {
            s.append("  Top 4 Avg CN0 mean (dB-Hz): ").append(
          topFourAverageCn0Statistics.getMean()).append("\n");
                    mTopFourAverageCn0Statistics.getMean()).append("\n");
            s.append("  Top 4 Avg CN0 standard deviation (dB-Hz): ").append(
          topFourAverageCn0Statistics.getStandardDeviation()).append("\n");
                    mTopFourAverageCn0Statistics.getStandardDeviation()).append("\n");
        }
        s.append("  Used-in-fix constellation types: ");
        for (int i = 0; i < mConstellationTypes.length; i++) {
@@ -260,97 +249,86 @@ public class GnssMetrics {
        GpsBatteryStats stats = mGnssPowerMetrics.getGpsBatteryStats();
        if (stats != null) {
            s.append("Power Metrics").append("\n");
      s.append("  Time on battery (min): "
          + stats.getLoggingDurationMs() / ((double) DateUtils.MINUTE_IN_MILLIS)).append("\n");
            s.append("  Time on battery (min): ").append(
                    stats.getLoggingDurationMs() / ((double) DateUtils.MINUTE_IN_MILLIS)).append(
                    "\n");
            long[] t = stats.getTimeInGpsSignalQualityLevel();
            if (t != null && t.length == NUM_GPS_SIGNAL_QUALITY_LEVELS) {
        s.append("  Amount of time (while on battery) Top 4 Avg CN0 > " +
            Double.toString(GnssPowerMetrics.POOR_TOP_FOUR_AVG_CN0_THRESHOLD_DB_HZ) +
            " dB-Hz (min): ").append(t[1] / ((double) DateUtils.MINUTE_IN_MILLIS)).append("\n");
        s.append("  Amount of time (while on battery) Top 4 Avg CN0 <= " +
            Double.toString(GnssPowerMetrics.POOR_TOP_FOUR_AVG_CN0_THRESHOLD_DB_HZ) +
            " dB-Hz (min): ").append(t[0] / ((double) DateUtils.MINUTE_IN_MILLIS)).append("\n");
                s.append("  Amount of time (while on battery) Top 4 Avg CN0 > "
                        + GnssPowerMetrics.POOR_TOP_FOUR_AVG_CN0_THRESHOLD_DB_HZ
                        + " dB-Hz (min): ").append(
                        t[1] / ((double) DateUtils.MINUTE_IN_MILLIS)).append("\n");
                s.append("  Amount of time (while on battery) Top 4 Avg CN0 <= "
                        + GnssPowerMetrics.POOR_TOP_FOUR_AVG_CN0_THRESHOLD_DB_HZ
                        + " dB-Hz (min): ").append(
                        t[0] / ((double) DateUtils.MINUTE_IN_MILLIS)).append("\n");
            }
            s.append("  Energy consumed while on battery (mAh): ").append(
          stats.getEnergyConsumedMaMs() / ((double) DateUtils.HOUR_IN_MILLIS)).append("\n");
                    stats.getEnergyConsumedMaMs() / ((double) DateUtils.HOUR_IN_MILLIS)).append(
                    "\n");
        }
    s.append("Hardware Version: " + SystemProperties.get("ro.boot.revision", "")).append("\n");
        s.append("Hardware Version: ").append(SystemProperties.get("ro.boot.revision", "")).append(
                "\n");
        return s.toString();
    }

    private void reset() {
        StringBuilder s = new StringBuilder();
        TimeUtils.formatDuration(SystemClock.elapsedRealtimeNanos() / 1000000L, s);
        mLogStartInElapsedRealTime = s.toString();
        mLocationFailureStatistics.reset();
        mTimeToFirstFixSecStatistics.reset();
        mPositionAccuracyMeterStatistics.reset();
        mTopFourAverageCn0Statistics.reset();
        resetConstellationTypes();
    }

    /** Resets {@link #mConstellationTypes} as an all-false boolean array. */
    public void resetConstellationTypes() {
        mConstellationTypes = new boolean[GnssStatus.CONSTELLATION_COUNT];
    }

    /** Class for storing statistics */
    private class Statistics {

        private int mCount;
        private double mSum;
        private double mSumSquare;

        /** Resets statistics */
        public void reset() {
      count = 0;
      sum = 0.0;
      sumSquare = 0.0;
            mCount = 0;
            mSum = 0.0;
            mSumSquare = 0.0;
        }

        /** Adds an item */
        public void addItem(double item) {
      count++;
      sum += item;
      sumSquare += item * item;
            mCount++;
            mSum += item;
            mSumSquare += item * item;
        }

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

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

        /** Returns standard deviation */
        public double getStandardDeviation() {
      double m = sum/count;
            double m = mSum / mCount;
            m = m * m;
      double v = sumSquare/count;
            double v = mSumSquare / mCount;
            if (v > m) {
                return Math.sqrt(v - m);
            }
            return 0;
        }

    private int count;
    private double sum;
    private double sumSquare;
  }

  /** Location failure statistics */
  private Statistics locationFailureStatistics;

  /** Time to first fix statistics */
  private Statistics timeToFirstFixSecStatistics;

  /** Position accuracy statistics */
  private Statistics positionAccuracyMeterStatistics;

  /** Top 4 average CN0 statistics */
  private Statistics topFourAverageCn0Statistics;

  /**
   * Resets GNSS metrics
   */
  private void reset() {
    StringBuilder s = new StringBuilder();
    TimeUtils.formatDuration(SystemClock.elapsedRealtimeNanos() / 1000000L, s);
    logStartInElapsedRealTime = s.toString();
    locationFailureStatistics.reset();
    timeToFirstFixSecStatistics.reset();
    positionAccuracyMeterStatistics.reset();
    topFourAverageCn0Statistics.reset();
        resetConstellationTypes();
    return;
  }

    /** Resets {@link #mConstellationTypes} as an all-false boolean array. */
    public void resetConstellationTypes() {
        mConstellationTypes = new boolean[GnssStatus.CONSTELLATION_COUNT];
    }

    /* Class for handling GNSS power related metrics */
@@ -371,9 +349,10 @@ public class GnssMetrics {
        /* Last reported signal quality bin (based on Top Four Average CN0) */
        private int mLastSignalLevel;

    public GnssPowerMetrics(IBatteryStats stats) {
        private GnssPowerMetrics(IBatteryStats stats) {
            mBatteryStats = stats;
      // Used to initialize the variable to a very small value (unachievable in practice) so that
            // Used to initialize the variable to a very small value (unachievable in practice)
          // so that
            // the first CNO report will trigger an update to BatteryStats
            mLastAverageCn0 = -100.0;
            mLastSignalLevel = GPS_SIGNAL_QUALITY_UNKNOWN;
@@ -381,6 +360,7 @@ public class GnssMetrics {

        /**
         * Builds power metrics proto buf. This is included in the gnss proto buf.
         *
         * @return PowerMetrics
         */
        public PowerMetrics buildProto() {
@@ -388,7 +368,8 @@ public class GnssMetrics {
            GpsBatteryStats stats = mGnssPowerMetrics.getGpsBatteryStats();
            if (stats != null) {
                p.loggingDurationMs = stats.getLoggingDurationMs();
        p.energyConsumedMah = stats.getEnergyConsumedMaMs() / ((double) DateUtils.HOUR_IN_MILLIS);
                p.energyConsumedMah =
                        stats.getEnergyConsumedMaMs() / ((double) DateUtils.HOUR_IN_MILLIS);
                long[] t = stats.getTimeInGpsSignalQualityLevel();
                p.timeInSignalQualityLevelMs = new long[t.length];
                for (int i = 0; i < t.length; i++) {
@@ -400,6 +381,7 @@ public class GnssMetrics {

        /**
         * Returns the GPS power stats
         *
         * @return GpsBatteryStats
         */
        public GpsBatteryStats getGpsBatteryStats() {
@@ -412,9 +394,11 @@ public class GnssMetrics {
        }

        /**
     * Reports signal quality to BatteryStats. Signal quality is based on Top four average CN0. If
         * Reports signal quality to BatteryStats. Signal quality is based on Top four average CN0.
         * If
         * the number of SVs seen is less than 4, then signal quality is the average CN0.
     * Changes are reported only if the average CN0 changes by more than REPORTING_THRESHOLD_DB_HZ.
         * Changes are reported only if the average CN0 changes by more than
         * REPORTING_THRESHOLD_DB_HZ.
         */
        public void reportSignalQuality(float[] ascendingCN0Array, int numSv) {
            double avgCn0 = 0.0;
@@ -438,7 +422,6 @@ public class GnssMetrics {
            } catch (Exception e) {
                Log.w(TAG, "Exception", e);
            }
      return;
        }

        /**
+101 −68

File changed.

Preview size limit exceeded, changes collapsed.

+10 −16
Original line number Diff line number Diff line
@@ -16,11 +16,6 @@

package com.android.server.location;

import java.io.PrintWriter;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import android.app.AppOpsManager;
import android.app.PendingIntent;
import android.content.ContentResolver;
@@ -44,6 +39,11 @@ import android.util.Slog;
import com.android.server.LocationManagerService;
import com.android.server.PendingIntentUtils;

import java.io.PrintWriter;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class GeofenceManager implements LocationListener, PendingIntent.OnFinished {
    private static final String TAG = "GeofenceManager";
    private static final boolean D = LocationManagerService.D;
@@ -79,13 +79,13 @@ public class GeofenceManager implements LocationListener, PendingIntent.OnFinish
    private final GeofenceHandler mHandler;
    private final LocationBlacklist mBlacklist;

    private Object mLock = new Object();
    private final Object mLock = new Object();

    // access to members below is synchronized on mLock
    /**
     * A list containing all registered geofences.
     */
    private List<GeofenceState> mFences = new LinkedList<GeofenceState>();
    private List<GeofenceState> mFences = new LinkedList<>();

    /**
     * This is set true when we have an active request for {@link Location} updates via
@@ -272,8 +272,8 @@ public class GeofenceManager implements LocationListener, PendingIntent.OnFinish
     */
    // Runs on the handler.
    private void updateFences() {
        List<PendingIntent> enterIntents = new LinkedList<PendingIntent>();
        List<PendingIntent> exitIntents = new LinkedList<PendingIntent>();
        List<PendingIntent> enterIntents = new LinkedList<>();
        List<PendingIntent> exitIntents = new LinkedList<>();

        synchronized (mLock) {
            mPendingUpdate = false;
@@ -446,14 +446,8 @@ public class GeofenceManager implements LocationListener, PendingIntent.OnFinish
    }

    public void dump(PrintWriter pw) {
        pw.println("  Geofences:");

        for (GeofenceState state : mFences) {
            pw.append("    ");
            pw.append(state.mPackageName);
            pw.append(" ");
            pw.append(state.mFence.toString());
            pw.append("\n");
            pw.println(state.mPackageName + " " + state.mFence);
        }
    }

+10 −9
Original line number Diff line number Diff line
@@ -2204,7 +2204,8 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
            s.append("]\n");
        }
        s.append(mGnssMetrics.dumpGnssMetricsAsText());
        s.append("  native internal state: ").append(native_get_internal_state());
        s.append("native internal state: \n");
        s.append("  ").append(native_get_internal_state());
        s.append("\n");
        pw.append(s);
    }
+2 −2

File changed.

Contains only whitespace changes.

+1 −1

File changed.

Contains only whitespace changes.

+1 −1

File changed.

Contains only whitespace changes.

Loading