Log deferred jobs metrics to batterystats
Log the deferred jobs event count, number of deferred jobs,
time since last job execution and break those down into
different time-since buckets in case the average becomes
too noisy.
Bug: 70297451
Test: dumpsys batterystats --checkin
Change-Id: Iafad6137989246f203a623ce1511140d4eac35b0
diff --git a/services/core/java/com/android/server/job/JobSchedulerService.java b/services/core/java/com/android/server/job/JobSchedulerService.java
index c33d7f4..05c7f19 100644
--- a/services/core/java/com/android/server/job/JobSchedulerService.java
+++ b/services/core/java/com/android/server/job/JobSchedulerService.java
@@ -49,6 +49,7 @@
import android.database.ContentObserver;
import android.net.Uri;
import android.os.BatteryStats;
+import android.os.BatteryStatsInternal;
import android.os.Binder;
import android.os.Handler;
import android.os.Looper;
@@ -62,6 +63,7 @@
import android.os.UserHandle;
import android.os.UserManagerInternal;
import android.provider.Settings;
+import android.text.format.DateUtils;
import android.util.KeyValueListParser;
import android.util.Slog;
import android.util.SparseArray;
@@ -2282,14 +2284,20 @@
return;
}
- final long sinceLast = sElapsedRealtimeClock.millis() -
- mUsageStats.getTimeSinceLastJobRun(packageName, userId);
+ long sinceLast = mUsageStats.getTimeSinceLastJobRun(packageName, userId);
+ if (sinceLast > 2 * DateUtils.DAY_IN_MILLIS) {
+ // Too long ago, not worth logging
+ sinceLast = 0L;
+ }
final DeferredJobCounter counter = new DeferredJobCounter();
synchronized (mLock) {
mJobs.forEachJobForSourceUid(uid, counter);
}
-
- mUsageStats.reportAppJobState(packageName, userId, counter.numDeferred(), sinceLast);
+ if (counter.numDeferred() > 0 || sinceLast > 0) {
+ BatteryStatsInternal mBatteryStatsInternal = LocalServices.getService
+ (BatteryStatsInternal.class);
+ mBatteryStatsInternal.noteJobsDeferred(uid, counter.numDeferred(), sinceLast);
+ }
}
}