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

Commit 7e913029 authored by qingqi's avatar qingqi Committed by Qingqi Lei
Browse files

Shorten cooldown time service state metrics

Test: m, manually inspect metric log
Bug: 310630240
Change-Id: I1c7e40d516b2647e5fc3b34301518b269cb38aff
parent b0e5784d
Loading
Loading
Loading
Loading
+31 −5
Original line number Original line Diff line number Diff line
@@ -53,6 +53,7 @@ import static com.android.internal.telephony.TelephonyStatsLog.UCE_EVENT_STATS;
import static com.android.internal.telephony.TelephonyStatsLog.VOICE_CALL_RAT_USAGE;
import static com.android.internal.telephony.TelephonyStatsLog.VOICE_CALL_RAT_USAGE;
import static com.android.internal.telephony.TelephonyStatsLog.VOICE_CALL_SESSION;
import static com.android.internal.telephony.TelephonyStatsLog.VOICE_CALL_SESSION;
import static com.android.internal.telephony.TelephonyStatsLog.VOICE_CALL_SESSION__CALL_DURATION__CALL_DURATION_UNKNOWN;
import static com.android.internal.telephony.TelephonyStatsLog.VOICE_CALL_SESSION__CALL_DURATION__CALL_DURATION_UNKNOWN;
import static com.android.internal.telephony.util.TelephonyUtils.IS_DEBUGGABLE;


import android.app.StatsManager;
import android.app.StatsManager;
import android.content.Context;
import android.content.Context;
@@ -135,6 +136,15 @@ public class MetricsCollector implements StatsManager.StatsPullAtomCallback {
    private static final long MIN_COOLDOWN_MILLIS =
    private static final long MIN_COOLDOWN_MILLIS =
            DBG ? 10L * MILLIS_PER_SECOND : 23L * MILLIS_PER_HOUR;
            DBG ? 10L * MILLIS_PER_SECOND : 23L * MILLIS_PER_HOUR;


    /**
     * Sets atom pull cool down to 4 minutes for userdebug build.
     *
     * <p>Applies to certain atoms: CellularServiceState.
     */
    private static final long CELL_SERVICE_MIN_COOLDOWN_MILLIS =
            DBG ? 10L * MILLIS_PER_SECOND :
                    IS_DEBUGGABLE ? 4L * MILLIS_PER_MINUTE : 23L * MILLIS_PER_HOUR;

    /**
    /**
     * Buckets with less than these many calls will be dropped.
     * Buckets with less than these many calls will be dropped.
     *
     *
@@ -142,10 +152,18 @@ public class MetricsCollector implements StatsManager.StatsPullAtomCallback {
     */
     */
    private static final long MIN_CALLS_PER_BUCKET = DBG ? 0L : 5L;
    private static final long MIN_CALLS_PER_BUCKET = DBG ? 0L : 5L;


    /** Bucket size in milliseconds to round call durations into. */
    /** Bucket size in milliseconds to round call durations info. */
    private static final long DURATION_BUCKET_MILLIS =
    private static final long DURATION_BUCKET_MILLIS =
            DBG ? 2L * MILLIS_PER_SECOND : 5L * MILLIS_PER_MINUTE;
            DBG ? 2L * MILLIS_PER_SECOND : 5L * MILLIS_PER_MINUTE;


    /**
     * Sets smaller bucket size to round call durations for userdebug build.
     *
     * <p>Applies to certain atoms: CellularServiceState.
     */
    private static final long CELL_SERVICE_DURATION_BUCKET_MILLIS =
            DBG || IS_DEBUGGABLE ? 2L * MILLIS_PER_SECOND : 5L * MILLIS_PER_MINUTE;

    private final PersistAtomsStorage mStorage;
    private final PersistAtomsStorage mStorage;
    private final DeviceStateHelper mDeviceStateHelper;
    private final DeviceStateHelper mDeviceStateHelper;
    private final StatsManager mStatsManager;
    private final StatsManager mStatsManager;
@@ -510,7 +528,7 @@ public class MetricsCollector implements StatsManager.StatsPullAtomCallback {
        // Include the latest durations
        // Include the latest durations
        concludeServiceStateStats();
        concludeServiceStateStats();
        CellularServiceState[] persistAtoms =
        CellularServiceState[] persistAtoms =
                mStorage.getCellularServiceStates(MIN_COOLDOWN_MILLIS);
                mStorage.getCellularServiceStates(CELL_SERVICE_MIN_COOLDOWN_MILLIS);
        if (persistAtoms != null) {
        if (persistAtoms != null) {
            // list is already shuffled when instances were inserted
            // list is already shuffled when instances were inserted
            Arrays.stream(persistAtoms)
            Arrays.stream(persistAtoms)
@@ -930,7 +948,8 @@ public class MetricsCollector implements StatsManager.StatsPullAtomCallback {
                state.simSlotIndex,
                state.simSlotIndex,
                state.isMultiSim,
                state.isMultiSim,
                state.carrierId,
                state.carrierId,
                roundAndConvertMillisToSeconds(state.totalTimeMillis),
                roundAndConvertMillisToSeconds(state.totalTimeMillis,
                        CELL_SERVICE_DURATION_BUCKET_MILLIS),
                state.isEmergencyOnly,
                state.isEmergencyOnly,
                state.isInternetPdnUp,
                state.isInternetPdnUp,
                state.foldState,
                state.foldState,
@@ -1364,8 +1383,15 @@ public class MetricsCollector implements StatsManager.StatsPullAtomCallback {
     * Rounds the duration and converts it from milliseconds to seconds.
     * Rounds the duration and converts it from milliseconds to seconds.
     */
     */
    private static int roundAndConvertMillisToSeconds(long valueMillis) {
    private static int roundAndConvertMillisToSeconds(long valueMillis) {
        long roundedValueMillis = Math.round((double) valueMillis / DURATION_BUCKET_MILLIS)
        return roundAndConvertMillisToSeconds(valueMillis, DURATION_BUCKET_MILLIS);
                * DURATION_BUCKET_MILLIS;
    }

    /**
     * Rounds the duration and converts it from milliseconds to seconds.
     */
    private static int roundAndConvertMillisToSeconds(long valueMillis, long durationBucketSize) {
        long roundedValueMillis = Math.round((double) valueMillis / durationBucketSize)
                * durationBucketSize;
        return (int) (roundedValueMillis / MILLIS_PER_SECOND);
        return (int) (roundedValueMillis / MILLIS_PER_SECOND);
    }
    }


+5 −1
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@ import static com.android.internal.telephony.TelephonyStatsLog.SIM_SLOT_STATE;
import static com.android.internal.telephony.TelephonyStatsLog.SUPPORTED_RADIO_ACCESS_FAMILY;
import static com.android.internal.telephony.TelephonyStatsLog.SUPPORTED_RADIO_ACCESS_FAMILY;
import static com.android.internal.telephony.TelephonyStatsLog.VOICE_CALL_RAT_USAGE;
import static com.android.internal.telephony.TelephonyStatsLog.VOICE_CALL_RAT_USAGE;
import static com.android.internal.telephony.TelephonyStatsLog.VOICE_CALL_SESSION;
import static com.android.internal.telephony.TelephonyStatsLog.VOICE_CALL_SESSION;
import static com.android.internal.telephony.util.TelephonyUtils.IS_DEBUGGABLE;


import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertThat;


@@ -67,6 +68,8 @@ public class MetricsCollectorTest extends TelephonyTest {
                    .setCoolDownMillis(24L * 3600L * 1000L)
                    .setCoolDownMillis(24L * 3600L * 1000L)
                    .build();
                    .build();
    private static final long MIN_COOLDOWN_MILLIS = 23L * 3600L * 1000L;
    private static final long MIN_COOLDOWN_MILLIS = 23L * 3600L * 1000L;
    private static final long CELL_SERVICE_MIN_COOLDOWN_MILLIS =
            IS_DEBUGGABLE ? 4L *  60L * 1000L : MIN_COOLDOWN_MILLIS;
    private static final long MIN_CALLS_PER_BUCKET = 5L;
    private static final long MIN_CALLS_PER_BUCKET = 5L;


    // NOTE: these fields are currently 32-bit internally and padded to 64-bit by TelephonyManager
    // NOTE: these fields are currently 32-bit internally and padded to 64-bit by TelephonyManager
@@ -398,7 +401,8 @@ public class MetricsCollectorTest extends TelephonyTest {


        assertThat(actualAtoms).hasSize(0);
        assertThat(actualAtoms).hasSize(0);
        assertThat(result).isEqualTo(StatsManager.PULL_SKIP);
        assertThat(result).isEqualTo(StatsManager.PULL_SKIP);
        verify(mPersistAtomsStorage, times(1)).getCellularServiceStates(eq(MIN_COOLDOWN_MILLIS));
        verify(mPersistAtomsStorage, times(1)).getCellularServiceStates(
                eq(CELL_SERVICE_MIN_COOLDOWN_MILLIS));
        verifyNoMoreInteractions(mPersistAtomsStorage);
        verifyNoMoreInteractions(mPersistAtomsStorage);
    }
    }