Merge "Add Standby Bucket and job duration to ScheduledJobStateChanged atom." into qt-dev

This commit is contained in:
Ben Murdoch
2019-05-20 08:18:34 +00:00
committed by Android (Google) Code Review
5 changed files with 30 additions and 9 deletions

View File

@@ -750,6 +750,22 @@ message ScheduledJobStateChanged {
// This is only applicable when the state is FINISHED. // This is only applicable when the state is FINISHED.
// The default value is STOP_REASON_UNKNOWN. // The default value is STOP_REASON_UNKNOWN.
optional android.app.job.StopReasonEnum stop_reason = 4; optional android.app.job.StopReasonEnum stop_reason = 4;
// The standby bucket of the app that scheduled the job. These match the framework constants
// defined in JobSchedulerService.java with the addition of UNKNOWN using -1, as ACTIVE is
// already assigned 0.
enum Bucket {
UNKNOWN = -1;
ACTIVE = 0;
WORKING_SET = 1;
FREQUENT = 2;
RARE = 3;
NEVER = 4;
}
optional Bucket standby_bucket = 5 [default = UNKNOWN];
// The job id (as assigned by the app).
optional int32 job_id = 6;
} }
/** /**

View File

@@ -71,8 +71,8 @@ interface IBatteryStats {
void noteSyncStart(String name, int uid); void noteSyncStart(String name, int uid);
void noteSyncFinish(String name, int uid); void noteSyncFinish(String name, int uid);
void noteJobStart(String name, int uid); void noteJobStart(String name, int uid, int standbyBucket, int jobid);
void noteJobFinish(String name, int uid, int stopReason); void noteJobFinish(String name, int uid, int stopReason, int standbyBucket, int jobid);
void noteStartWakelock(int uid, int pid, String name, String historyName, void noteStartWakelock(int uid, int pid, String name, String historyName,
int type, boolean unimportantForLogging); int type, boolean unimportantForLogging);

View File

@@ -467,23 +467,25 @@ public final class BatteryStatsService extends IBatteryStats.Stub
} }
} }
public void noteJobStart(String name, int uid) { /** A scheduled job was started. */
public void noteJobStart(String name, int uid, int standbyBucket, int jobid) {
enforceCallingPermission(); enforceCallingPermission();
synchronized (mStats) { synchronized (mStats) {
mStats.noteJobStartLocked(name, uid); mStats.noteJobStartLocked(name, uid);
StatsLog.write_non_chained(StatsLog.SCHEDULED_JOB_STATE_CHANGED, uid, null, StatsLog.write_non_chained(StatsLog.SCHEDULED_JOB_STATE_CHANGED, uid, null,
name, StatsLog.SCHEDULED_JOB_STATE_CHANGED__STATE__STARTED, name, StatsLog.SCHEDULED_JOB_STATE_CHANGED__STATE__STARTED,
JobProtoEnums.STOP_REASON_UNKNOWN); JobProtoEnums.STOP_REASON_UNKNOWN, standbyBucket, jobid);
} }
} }
public void noteJobFinish(String name, int uid, int stopReason) { /** A scheduled job was finished. */
public void noteJobFinish(String name, int uid, int stopReason, int standbyBucket, int jobid) {
enforceCallingPermission(); enforceCallingPermission();
synchronized (mStats) { synchronized (mStats) {
mStats.noteJobFinishLocked(name, uid, stopReason); mStats.noteJobFinishLocked(name, uid, stopReason);
StatsLog.write_non_chained(StatsLog.SCHEDULED_JOB_STATE_CHANGED, uid, null, StatsLog.write_non_chained(StatsLog.SCHEDULED_JOB_STATE_CHANGED, uid, null,
name, StatsLog.SCHEDULED_JOB_STATE_CHANGED__STATE__FINISHED, name, StatsLog.SCHEDULED_JOB_STATE_CHANGED__STATE__FINISHED,
stopReason); stopReason, standbyBucket, jobid);
} }
} }

View File

@@ -1057,7 +1057,8 @@ public class JobSchedulerService extends com.android.server.SystemService
StatsLog.write_non_chained(StatsLog.SCHEDULED_JOB_STATE_CHANGED, StatsLog.write_non_chained(StatsLog.SCHEDULED_JOB_STATE_CHANGED,
uId, null, jobStatus.getBatteryName(), uId, null, jobStatus.getBatteryName(),
StatsLog.SCHEDULED_JOB_STATE_CHANGED__STATE__SCHEDULED, StatsLog.SCHEDULED_JOB_STATE_CHANGED__STATE__SCHEDULED,
JobProtoEnums.STOP_REASON_CANCELLED); JobProtoEnums.STOP_REASON_CANCELLED, jobStatus.getStandbyBucket(),
jobStatus.getJobId());
// If the job is immediately ready to run, then we can just immediately // If the job is immediately ready to run, then we can just immediately
// put it in the pending list and try to schedule it. This is especially // put it in the pending list and try to schedule it. This is especially

View File

@@ -265,7 +265,8 @@ public final class JobServiceContext implements ServiceConnection {
} }
mJobPackageTracker.noteActive(job); mJobPackageTracker.noteActive(job);
try { try {
mBatteryStats.noteJobStart(job.getBatteryName(), job.getSourceUid()); mBatteryStats.noteJobStart(job.getBatteryName(), job.getSourceUid(),
job.getStandbyBucket(), job.getJobId());
} catch (RemoteException e) { } catch (RemoteException e) {
// Whatever. // Whatever.
} }
@@ -774,7 +775,8 @@ public final class JobServiceContext implements ServiceConnection {
mJobPackageTracker.noteInactive(completedJob, mParams.getStopReason(), reason); mJobPackageTracker.noteInactive(completedJob, mParams.getStopReason(), reason);
try { try {
mBatteryStats.noteJobFinish(mRunningJob.getBatteryName(), mBatteryStats.noteJobFinish(mRunningJob.getBatteryName(),
mRunningJob.getSourceUid(), mParams.getStopReason()); mRunningJob.getSourceUid(), mParams.getStopReason(),
mRunningJob.getStandbyBucket(), mRunningJob.getJobId());
} catch (RemoteException e) { } catch (RemoteException e) {
// Whatever. // Whatever.
} }