Log global JobScheduler state changes.

Log state changes of constraints that apply to all jobs. These
constraints only need to be logged once (when they change) instead of
for each individual job and allow us to analyze behavior when
JobScheduler believes the device is in various states.

Keep the individual job constraint change logging off.

Bug: 129954980
Bug: 242611030
Test: `statsd_testdrive 514`
Change-Id: Idf331749601db6ed6f767d5649667519046208ae
Merged-In: Idf331749601db6ed6f767d5649667519046208ae
This commit is contained in:
Kweku Adams
2022-09-09 18:47:08 +00:00
parent 60e003dd44
commit af4bbfa7d4
5 changed files with 38 additions and 3 deletions

View File

@@ -68,6 +68,11 @@ public final class BatteryController extends RestrictingController {
*/
private final ArraySet<JobStatus> mChangedJobs = new ArraySet<>();
@GuardedBy("mLock")
private Boolean mLastReportedStatsdBatteryNotLow = null;
@GuardedBy("mLock")
private Boolean mLastReportedStatsdStablePower = null;
public BatteryController(JobSchedulerService service) {
super(service);
mPowerTracker = new PowerTracker();
@@ -173,6 +178,19 @@ public final class BatteryController extends RestrictingController {
Slog.d(TAG, "maybeReportNewChargingStateLocked: "
+ powerConnected + "/" + stablePower + "/" + batteryNotLow);
}
if (mLastReportedStatsdStablePower == null
|| mLastReportedStatsdStablePower != stablePower) {
logDeviceWideConstraintStateToStatsd(JobStatus.CONSTRAINT_CHARGING, stablePower);
mLastReportedStatsdStablePower = stablePower;
}
if (mLastReportedStatsdBatteryNotLow == null
|| mLastReportedStatsdBatteryNotLow != stablePower) {
logDeviceWideConstraintStateToStatsd(JobStatus.CONSTRAINT_BATTERY_NOT_LOW,
batteryNotLow);
mLastReportedStatsdBatteryNotLow = batteryNotLow;
}
final long nowElapsed = sElapsedRealtimeClock.millis();
for (int i = mTrackedTasks.size() - 1; i >= 0; i--) {
final JobStatus ts = mTrackedTasks.valueAt(i);

View File

@@ -153,6 +153,8 @@ public final class DeviceIdleJobsController extends StateController {
changed = true;
}
mDeviceIdleMode = enabled;
logDeviceWideConstraintStateToStatsd(JobStatus.CONSTRAINT_DEVICE_NOT_DOZING,
!mDeviceIdleMode);
if (DEBUG) Slog.d(TAG, "mDeviceIdleMode=" + mDeviceIdleMode);
mDeviceIdleUpdateFunctor.prepare();
if (enabled) {

View File

@@ -93,6 +93,8 @@ public final class IdleController extends RestrictingController implements Idlen
@Override
public void reportNewIdleState(boolean isIdle) {
synchronized (mLock) {
logDeviceWideConstraintStateToStatsd(JobStatus.CONSTRAINT_IDLE, isIdle);
final long nowElapsed = sElapsedRealtimeClock.millis();
for (int i = mTrackedTasks.size()-1; i >= 0; i--) {
mTrackedTasks.valueAt(i).setIdleConstraintSatisfied(nowElapsed, isIdle);

View File

@@ -151,13 +151,12 @@ public final class JobStatus {
*/
private static final int STATSD_CONSTRAINTS_TO_LOG = CONSTRAINT_CONTENT_TRIGGER
| CONSTRAINT_DEADLINE
| CONSTRAINT_IDLE
| CONSTRAINT_PREFETCH
| CONSTRAINT_TARE_WEALTH
| CONSTRAINT_TIMING_DELAY
| CONSTRAINT_WITHIN_QUOTA;
// TODO(b/129954980)
// TODO(b/129954980): ensure this doesn't spam statsd, especially at boot
private static final boolean STATS_LOG_ENABLED = false;
// No override.
@@ -1864,7 +1863,7 @@ public final class JobStatus {
}
/** Returns a {@link JobServerProtoEnums.Constraint} enum value for the given constraint. */
private int getProtoConstraint(int constraint) {
static int getProtoConstraint(int constraint) {
switch (constraint) {
case CONSTRAINT_BACKGROUND_NOT_RESTRICTED:
return JobServerProtoEnums.CONSTRAINT_BACKGROUND_NOT_RESTRICTED;
@@ -1882,8 +1881,12 @@ public final class JobStatus {
return JobServerProtoEnums.CONSTRAINT_DEVICE_NOT_DOZING;
case CONSTRAINT_IDLE:
return JobServerProtoEnums.CONSTRAINT_IDLE;
case CONSTRAINT_PREFETCH:
return JobServerProtoEnums.CONSTRAINT_PREFETCH;
case CONSTRAINT_STORAGE_NOT_LOW:
return JobServerProtoEnums.CONSTRAINT_STORAGE_NOT_LOW;
case CONSTRAINT_TARE_WEALTH:
return JobServerProtoEnums.CONSTRAINT_TARE_WEALTH;
case CONSTRAINT_TIMING_DELAY:
return JobServerProtoEnums.CONSTRAINT_TIMING_DELAY;
case CONSTRAINT_WITHIN_QUOTA:

View File

@@ -26,6 +26,7 @@ import android.util.Slog;
import android.util.proto.ProtoOutputStream;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.FrameworkStatsLog;
import com.android.server.job.JobSchedulerService;
import com.android.server.job.JobSchedulerService.Constants;
import com.android.server.job.StateChangedListener;
@@ -165,6 +166,15 @@ public abstract class StateController {
return mService.areComponentsInPlaceLocked(jobStatus);
}
protected void logDeviceWideConstraintStateToStatsd(int constraint, boolean satisfied) {
FrameworkStatsLog.write(
FrameworkStatsLog.DEVICE_WIDE_JOB_CONSTRAINT_CHANGED,
JobStatus.getProtoConstraint(constraint),
satisfied
? FrameworkStatsLog.DEVICE_WIDE_JOB_CONSTRAINT_CHANGED__STATE__SATISFIED
: FrameworkStatsLog.DEVICE_WIDE_JOB_CONSTRAINT_CHANGED__STATE__UNSATISFIED);
}
public abstract void dumpControllerStateLocked(IndentingPrintWriter pw,
Predicate<JobStatus> predicate);
public void dumpControllerStateLocked(ProtoOutputStream proto, long fieldId,