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

Commit e19f2cf1 authored by Olivier Gaillard's avatar Olivier Gaillard Committed by Android (Google) Code Review
Browse files

Merge "Add pullers for debugging."

parents c5f10b97 18d45220
Loading
Loading
Loading
Loading
+39 −1
Original line number Diff line number Diff line
@@ -212,7 +212,7 @@ message Atom {
    }

    // Pulled events will start at field 10000.
    // Next: 10043
    // Next: 10048
    oneof pulled {
        WifiBytesTransfer wifi_bytes_transfer = 10000;
        WifiBytesTransferByFgBg wifi_bytes_transfer_by_fg_bg = 10001;
@@ -260,6 +260,8 @@ message Atom {
        BatteryLevel battery_level = 10043;
        BuildInformation build_information = 10044;
        BatteryCycleCount battery_cycle_count = 10045;
        DebugElapsedClock debug_elapsed_clock = 10046;
        DebugFailingElapsedClock debug_failing_elapsed_clock = 10047;
    }

    // DO NOT USE field numbers above 100,000 in AOSP.
@@ -4557,3 +4559,39 @@ message UsbContaminantReported {
    optional string id = 1;
    optional android.service.usb.ContaminantPresenceStatus status = 2;
}

/**
 * This atom is for debugging purpose.
 */
message DebugElapsedClock {
    // Monotically increasing value for each pull.
    optional int64 pull_count = 1;
    // Time from System.elapsedRealtime.
    optional int64 elapsed_clock_millis = 2;
    // Time from System.elapsedRealtime.
    optional int64 same_elapsed_clock_millis = 3;
    // Diff between current elapsed time and elapsed time from previous pull.
    optional int64 elapsed_clock_diff_millis = 4;

    enum Type {
      TYPE_UNKNOWN = 0;
      ALWAYS_PRESENT = 1;
      PRESENT_ON_ODD_PULLS = 2;
    }
    // Type of behavior for the pulled data.
    optional Type type = 5;
}

/**
 * This atom is for debugging purpose.
 */
message DebugFailingElapsedClock {
    // Monotically increasing value for each pull.
    optional int64 pull_count = 1;
    // Time from System.elapsedRealtime.
    optional int64 elapsed_clock_millis = 2;
    // Time from System.elapsedRealtime.
    optional int64 same_elapsed_clock_millis = 3;
    // Diff between current elapsed time and elapsed time from previous pull.
    optional int64 elapsed_clock_diff_millis = 4;
}
+8 −0
Original line number Diff line number Diff line
@@ -209,6 +209,14 @@ const std::map<int, PullAtomInfo> StatsPullerManager::kAllPullAtomInfo = {
        {android::util::DEVICE_CALCULATED_POWER_BLAME_OTHER,
         {.puller = new StatsCompanionServicePuller(
                  android::util::DEVICE_CALCULATED_POWER_BLAME_OTHER)}},
        // DebugElapsedClock.
        {android::util::DEBUG_ELAPSED_CLOCK,
         {.additiveFields = {1, 2, 3, 4},
          .puller = new StatsCompanionServicePuller(android::util::DEBUG_ELAPSED_CLOCK)}},
        // DebugFailingElapsedClock.
        {android::util::DEBUG_FAILING_ELAPSED_CLOCK,
         {.additiveFields = {1, 2, 3, 4},
          .puller = new StatsCompanionServicePuller(android::util::DEBUG_FAILING_ELAPSED_CLOCK)}},
        // BuildInformation.
        {android::util::BUILD_INFORMATION,
         {.puller = new StatsCompanionServicePuller(android::util::BUILD_INFORMATION)}},
+62 −0
Original line number Diff line number Diff line
@@ -246,6 +246,10 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
    @Nullable
    private final KernelCpuThreadReader mKernelCpuThreadReader;

    private long mDebugElapsedClockPreviousValue = 0;
    private long mDebugElapsedClockPullCount = 0;
    private long mDebugFailingElapsedClockPreviousValue = 0;
    private long mDebugFailingElapsedClockPullCount = 0;
    private BatteryStatsHelper mBatteryStatsHelper = null;
    private static final int MAX_BATTERY_STATS_HELPER_FREQUENCY_MS = 1000;
    private long mBatteryStatsHelperTimestampMs = -MAX_BATTERY_STATS_HELPER_FREQUENCY_MS;
@@ -1726,6 +1730,56 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
        }
    }

    private void pullDebugElapsedClock(int tagId,
            long elapsedNanos, final long wallClockNanos, List<StatsLogEventWrapper> pulledData) {
        final long elapsedMillis = SystemClock.elapsedRealtime();
        final long clockDiffMillis = mDebugElapsedClockPreviousValue == 0
                ? 0 : elapsedMillis - mDebugElapsedClockPreviousValue;

        StatsLogEventWrapper e = new StatsLogEventWrapper(tagId, elapsedNanos, wallClockNanos);
        e.writeLong(mDebugElapsedClockPullCount);
        e.writeLong(elapsedMillis);
        // Log it twice to be able to test multi-value aggregation from ValueMetric.
        e.writeLong(elapsedMillis);
        e.writeLong(clockDiffMillis);
        e.writeInt(1 /* always set */);
        pulledData.add(e);

        if (mDebugElapsedClockPullCount % 2 == 1) {
            StatsLogEventWrapper e2 = new StatsLogEventWrapper(tagId, elapsedNanos, wallClockNanos);
            e2.writeLong(mDebugElapsedClockPullCount);
            e2.writeLong(elapsedMillis);
            // Log it twice to be able to test multi-value aggregation from ValueMetric.
            e2.writeLong(elapsedMillis);
            e2.writeLong(clockDiffMillis);
            e2.writeInt(2 /* set on odd pulls */);
            pulledData.add(e2);
        }

        mDebugElapsedClockPullCount++;
        mDebugElapsedClockPreviousValue = elapsedMillis;
    }

    private void pullDebugFailingElapsedClock(int tagId,
            long elapsedNanos, final long wallClockNanos, List<StatsLogEventWrapper> pulledData) {
        StatsLogEventWrapper e = new StatsLogEventWrapper(tagId, elapsedNanos, wallClockNanos);
        final long elapsedMillis = SystemClock.elapsedRealtime();
        // Fails every 10 buckets.
        if (mDebugFailingElapsedClockPullCount++ % 10 == 0) {
            mDebugFailingElapsedClockPreviousValue = elapsedMillis;
            throw new RuntimeException("Failing debug elapsed clock");
        }

        e.writeLong(mDebugFailingElapsedClockPullCount);
        e.writeLong(elapsedMillis);
        // Log it twice to be able to test multi-value aggregation from ValueMetric.
        e.writeLong(elapsedMillis);
        e.writeLong(mDebugFailingElapsedClockPreviousValue == 0
                ? 0 : elapsedMillis - mDebugFailingElapsedClockPreviousValue);
        mDebugFailingElapsedClockPreviousValue = elapsedMillis;
        pulledData.add(e);
    }

    /**
     * Pulls various data.
     */
@@ -1892,6 +1946,14 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
                pullTemperature(tagId, elapsedNanos, wallClockNanos, ret);
                break;
            }
            case StatsLog.DEBUG_ELAPSED_CLOCK: {
                pullDebugElapsedClock(tagId, elapsedNanos, wallClockNanos, ret);
                break;
            }
            case StatsLog.DEBUG_FAILING_ELAPSED_CLOCK: {
                pullDebugFailingElapsedClock(tagId, elapsedNanos, wallClockNanos, ret);
                break;
            }
            default:
                Slog.w(TAG, "No such tagId data as " + tagId);
                return null;