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

Commit 73597dcb authored by Tej Singh's avatar Tej Singh
Browse files

Statsd update for native puller api feedback

Update statsd to take in times in milliseconds instead of nanoseconds.

Also make appropriate updates for graphics stats, odpm, subsystem sleep
state, and LibStatsPullTests

Test: atest LibStatsPullTests
Test: bit statsd_test:*
Bug: 150788562
Change-Id: I593552d6c50bb4dcb89ca9cc1c737781653e7cc5
parent 32d9a6bb
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -196,7 +196,7 @@ interface IStatsd {
     *
     * Enforces the REGISTER_STATS_PULL_ATOM permission.
     */
    oneway void registerNativePullAtomCallback(int atomTag, long coolDownNs, long timeoutNs,
    oneway void registerNativePullAtomCallback(int atomTag, long coolDownMillis, long timeoutMillis,
                           in int[] additiveFields, IPullAtomCallback pullerCallback);

    /**
+12 −15
Original line number Diff line number Diff line
@@ -44,30 +44,27 @@ static AStatsManager_PullAtomCallbackReturn pullAtomCallback(int32_t atomTag, AS
    return sPullReturnVal;
}

extern "C"
JNIEXPORT void JNICALL
Java_com_android_internal_os_statsd_libstats_LibStatsPullTests_registerStatsPuller(
        JNIEnv* /*env*/, jobject /* this */, jint atomTag, jlong timeoutNs, jlong coolDownNs,
        jint pullRetVal, jlong latencyMillis, int atomsPerPull)
{
extern "C" JNIEXPORT void JNICALL
Java_com_android_internal_os_statsd_libstats_LibStatsPullTests_setStatsPuller(
        JNIEnv* /*env*/, jobject /* this */, jint atomTag, jlong timeoutMillis,
        jlong coolDownMillis, jint pullRetVal, jlong latencyMillis, int atomsPerPull) {
    sAtomTag = atomTag;
    sPullReturnVal = pullRetVal;
    sLatencyMillis = latencyMillis;
    sAtomsPerPull = atomsPerPull;
    sNumPulls = 0;
    AStatsManager_PullAtomMetadata* metadata = AStatsManager_PullAtomMetadata_obtain();
    AStatsManager_PullAtomMetadata_setCoolDownNs(metadata, coolDownNs);
    AStatsManager_PullAtomMetadata_setTimeoutNs(metadata, timeoutNs);
    AStatsManager_PullAtomMetadata_setCoolDownMillis(metadata, coolDownMillis);
    AStatsManager_PullAtomMetadata_setTimeoutMillis(metadata, timeoutMillis);

    AStatsManager_registerPullAtomCallback(sAtomTag, &pullAtomCallback, metadata, nullptr);
    AStatsManager_setPullAtomCallback(sAtomTag, metadata, &pullAtomCallback, nullptr);
    AStatsManager_PullAtomMetadata_release(metadata);
}

extern "C"
JNIEXPORT void JNICALL
Java_com_android_internal_os_statsd_libstats_LibStatsPullTests_unregisterStatsPuller(
        JNIEnv* /*env*/, jobject /* this */, jint /*atomTag*/)
{
    AStatsManager_unregisterPullAtomCallback(sAtomTag);
extern "C" JNIEXPORT void JNICALL
Java_com_android_internal_os_statsd_libstats_LibStatsPullTests_clearStatsPuller(JNIEnv* /*env*/,
                                                                                jobject /* this */,
                                                                                jint /*atomTag*/) {
    AStatsManager_clearPullAtomCallback(sAtomTag);
}
} // namespace
+19 −19
Original line number Diff line number Diff line
@@ -58,8 +58,8 @@ public class LibStatsPullTests {
    private static int sPullReturnValue;
    private static long sConfigId;
    private static long sPullLatencyMillis;
    private static long sPullTimeoutNs;
    private static long sCoolDownNs;
    private static long sPullTimeoutMillis;
    private static long sCoolDownMillis;
    private static int sAtomsPerPull;

    static {
@@ -75,8 +75,8 @@ public class LibStatsPullTests {
        assertThat(InstrumentationRegistry.getInstrumentation()).isNotNull();
        sPullReturnValue = StatsManager.PULL_SUCCESS;
        sPullLatencyMillis = 0;
        sPullTimeoutNs = 10_000_000_000L;
        sCoolDownNs = 1_000_000_000L;
        sPullTimeoutMillis = 10_000L;
        sCoolDownMillis = 1_000L;
        sAtomsPerPull = 1;
    }

@@ -85,7 +85,7 @@ public class LibStatsPullTests {
     */
    @After
    public void tearDown() throws Exception {
        unregisterStatsPuller(PULL_ATOM_TAG);
        clearStatsPuller(PULL_ATOM_TAG);
        StatsManager statsManager = (StatsManager) mContext.getSystemService(
                Context.STATS_MANAGER);
        statsManager.removeConfig(sConfigId);
@@ -102,14 +102,14 @@ public class LibStatsPullTests {
        createAndAddConfigToStatsd(statsManager);

        // Add the puller.
        registerStatsPuller(PULL_ATOM_TAG, sPullTimeoutNs, sCoolDownNs, sPullReturnValue,
        setStatsPuller(PULL_ATOM_TAG, sPullTimeoutMillis, sCoolDownMillis, sPullReturnValue,
                sPullLatencyMillis, sAtomsPerPull);
        Thread.sleep(SHORT_SLEEP_MILLIS);
        StatsLog.logStart(APP_BREADCRUMB_LABEL);
        // Let the current bucket finish.
        Thread.sleep(LONG_SLEEP_MILLIS);
        List<Atom> data = StatsConfigUtils.getGaugeMetricDataList(statsManager, sConfigId);
        unregisterStatsPuller(PULL_ATOM_TAG);
        clearStatsPuller(PULL_ATOM_TAG);
        assertThat(data.size()).isEqualTo(1);
        TestAtoms.PullCallbackAtomWrapper atomWrapper = null;
        try {
@@ -135,14 +135,14 @@ public class LibStatsPullTests {
        createAndAddConfigToStatsd(statsManager);
        sPullReturnValue = StatsManager.PULL_SKIP;
        // Add the puller.
        registerStatsPuller(PULL_ATOM_TAG, sPullTimeoutNs, sCoolDownNs, sPullReturnValue,
        setStatsPuller(PULL_ATOM_TAG, sPullTimeoutMillis, sCoolDownMillis, sPullReturnValue,
                sPullLatencyMillis, sAtomsPerPull);
        Thread.sleep(SHORT_SLEEP_MILLIS);
        StatsLog.logStart(APP_BREADCRUMB_LABEL);
        // Let the current bucket finish.
        Thread.sleep(LONG_SLEEP_MILLIS);
        List<Atom> data = StatsConfigUtils.getGaugeMetricDataList(statsManager, sConfigId);
        unregisterStatsPuller(PULL_ATOM_TAG);
        clearStatsPuller(PULL_ATOM_TAG);
        assertThat(data.size()).isEqualTo(0);
    }

@@ -157,17 +157,17 @@ public class LibStatsPullTests {
        // The puller will sleep for 1.5 sec.
        sPullLatencyMillis = 1_500;
        // 1 second timeout
        sPullTimeoutNs = 1_000_000_000;
        sPullTimeoutMillis = 1_000;

        // Add the puller.
        registerStatsPuller(PULL_ATOM_TAG, sPullTimeoutNs, sCoolDownNs, sPullReturnValue,
        setStatsPuller(PULL_ATOM_TAG, sPullTimeoutMillis, sCoolDownMillis, sPullReturnValue,
                sPullLatencyMillis, sAtomsPerPull);
        Thread.sleep(SHORT_SLEEP_MILLIS);
        StatsLog.logStart(APP_BREADCRUMB_LABEL);
        // Let the current bucket finish and the pull timeout.
        Thread.sleep(sPullLatencyMillis * 2);
        List<Atom> data = StatsConfigUtils.getGaugeMetricDataList(statsManager, sConfigId);
        unregisterStatsPuller(PULL_ATOM_TAG);
        clearStatsPuller(PULL_ATOM_TAG);
        assertThat(data.size()).isEqualTo(0);
    }

@@ -181,9 +181,9 @@ public class LibStatsPullTests {
        createAndAddConfigToStatsd(statsManager);

        // Set the cooldown to 10 seconds
        sCoolDownNs = 10_000_000_000L;
        sCoolDownMillis = 10_000L;
        // Add the puller.
        registerStatsPuller(PULL_ATOM_TAG, sPullTimeoutNs, sCoolDownNs, sPullReturnValue,
        setStatsPuller(PULL_ATOM_TAG, sPullTimeoutMillis, sCoolDownMillis, sPullReturnValue,
                sPullLatencyMillis, sAtomsPerPull);

        Thread.sleep(SHORT_SLEEP_MILLIS);
@@ -192,7 +192,7 @@ public class LibStatsPullTests {
        StatsLog.logStart(APP_BREADCRUMB_LABEL);
        Thread.sleep(LONG_SLEEP_MILLIS);
        List<Atom> data = StatsConfigUtils.getGaugeMetricDataList(statsManager, sConfigId);
        unregisterStatsPuller(PULL_ATOM_TAG);
        clearStatsPuller(PULL_ATOM_TAG);
        assertThat(data.size()).isEqualTo(2);
        for (int i = 0; i < data.size(); i++) {
            TestAtoms.PullCallbackAtomWrapper atomWrapper = null;
@@ -221,7 +221,7 @@ public class LibStatsPullTests {
        createAndAddConfigToStatsd(statsManager);
        sAtomsPerPull = 1000;
        // Add the puller.
        registerStatsPuller(PULL_ATOM_TAG, sPullTimeoutNs, sCoolDownNs, sPullReturnValue,
        setStatsPuller(PULL_ATOM_TAG, sPullTimeoutMillis, sCoolDownMillis, sPullReturnValue,
                sPullLatencyMillis, sAtomsPerPull);

        Thread.sleep(SHORT_SLEEP_MILLIS);
@@ -229,7 +229,7 @@ public class LibStatsPullTests {
        // Let the current bucket finish.
        Thread.sleep(LONG_SLEEP_MILLIS);
        List<Atom> data = StatsConfigUtils.getGaugeMetricDataList(statsManager, sConfigId);
        unregisterStatsPuller(PULL_ATOM_TAG);
        clearStatsPuller(PULL_ATOM_TAG);
        assertThat(data.size()).isEqualTo(sAtomsPerPull);

        for (int i = 0; i < data.size(); i++) {
@@ -276,9 +276,9 @@ public class LibStatsPullTests {
        assertThat(StatsConfigUtils.verifyValidConfigExists(statsManager, sConfigId)).isTrue();
    }

    private native void registerStatsPuller(int atomTag, long timeoutNs, long coolDownNs,
    private native void setStatsPuller(int atomTag, long timeoutMillis, long coolDownMillis,
            int pullReturnVal, long latencyMillis, int atomPerPull);

    private native void unregisterStatsPuller(int atomTag);
    private native void clearStatsPuller(int atomTag);
}
+6 −4
Original line number Diff line number Diff line
@@ -1209,8 +1209,9 @@ Status StatsService::registerPullAtomCallback(int32_t uid, int32_t atomTag, int6
    return Status::ok();
}

Status StatsService::registerNativePullAtomCallback(int32_t atomTag, int64_t coolDownNs,
                                    int64_t timeoutNs, const std::vector<int32_t>& additiveFields,
Status StatsService::registerNativePullAtomCallback(
        int32_t atomTag, int64_t coolDownMillis, int64_t timeoutMillis,
        const std::vector<int32_t>& additiveFields,
        const shared_ptr<IPullAtomCallback>& pullerCallback) {
    if (!checkPermission(kPermissionRegisterPullAtom)) {
        return exception(
@@ -1220,7 +1221,8 @@ Status StatsService::registerNativePullAtomCallback(int32_t atomTag, int64_t coo
    }
    VLOG("StatsService::registerNativePullAtomCallback called.");
    int32_t uid = AIBinder_getCallingUid();
    mPullerManager->RegisterPullAtomCallback(uid, atomTag, coolDownNs, timeoutNs, additiveFields,
    mPullerManager->RegisterPullAtomCallback(uid, atomTag, MillisToNano(coolDownMillis),
                                             MillisToNano(timeoutMillis), additiveFields,
                                             pullerCallback);
    return Status::ok();
}
+3 −2
Original line number Diff line number Diff line
@@ -175,8 +175,9 @@ public:
    /**
     * Binder call to register a callback function for a pulled atom.
     */
    virtual Status registerNativePullAtomCallback(int32_t atomTag, int64_t coolDownNs,
            int64_t timeoutNs, const std::vector<int32_t>& additiveFields,
    virtual Status registerNativePullAtomCallback(
            int32_t atomTag, int64_t coolDownMillis, int64_t timeoutMillis,
            const std::vector<int32_t>& additiveFields,
            const shared_ptr<IPullAtomCallback>& pullerCallback) override;

    /**
Loading