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

Commit 21489b34 authored by Suprabh Shukla's avatar Suprabh Shukla
Browse files

Switching StatLogger to uptime

Uptime is a better estimate of time spent in cpu. Adding uptimeNanos to
SystemClock to get finer timestamps.

Test: Manual:
`adb shell dumpsys alarm` should show sensible information under 'Stats'
printed at the end.

Bug: 162791194
Change-Id: I4f1c9d41c53ec03fc414730d38fd7a2233bb0569
parent 370e885c
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -177,6 +177,15 @@ public final class SystemClock {
    @CriticalNative
    native public static long uptimeMillis();

    /**
     * Returns nanoseconds since boot, not counting time spent in deep sleep.
     *
     * @return nanoseconds of non-sleep uptime since boot.
     * @hide
     */
    @CriticalNative
    public static native long uptimeNanos();

    /**
     * Return {@link Clock} that starts at system boot, not counting time spent
     * in deep sleep.
+1 −1
Original line number Diff line number Diff line
@@ -84,7 +84,7 @@ public class StatLogger {
     * give it back to the {@link #logDurationStat(int, long)}} after the event.
     */
    public long getTime() {
        return SystemClock.elapsedRealtimeNanos() / 1000;
        return SystemClock.uptimeNanos() / 1000;
    }

    /**
+5 −2
Original line number Diff line number Diff line
@@ -37,10 +37,12 @@ namespace android {
static_assert(std::is_same<int64_t, jlong>::value, "jlong isn't an int64_t");
static_assert(std::is_same<decltype(uptimeMillis()), int64_t>::value,
        "uptimeMillis signature change, expected int64_t return value");
static_assert(std::is_same<decltype(uptimeNanos()), int64_t>::value,
        "uptimeNanos signature change, expected int64_t return value");
static_assert(std::is_same<decltype(elapsedRealtime()), int64_t>::value,
        "uptimeMillis signature change, expected int64_t return value");
        "elapsedRealtime signature change, expected int64_t return value");
static_assert(std::is_same<decltype(elapsedRealtimeNano()), int64_t>::value,
        "uptimeMillis signature change, expected int64_t return value");
        "elapsedRealtimeNano signature change, expected int64_t return value");

/*
 * native public static long currentThreadTimeMillis();
@@ -76,6 +78,7 @@ static const JNINativeMethod gMethods[] = {
    // All of these are @CriticalNative, so we can defer directly to SystemClock.h for
    // some of these
    { "uptimeMillis", "()J", (void*) uptimeMillis },
    { "uptimeNanos", "()J", (void*) uptimeNanos },
    { "elapsedRealtime", "()J", (void*) elapsedRealtime },
    { "elapsedRealtimeNanos", "()J", (void*) elapsedRealtimeNano },