Merge "Set number of foreground services in statsd atom LmkKillOccurred."

This commit is contained in:
Hui Yu
2022-08-15 16:19:28 +00:00
committed by Android (Google) Code Review
3 changed files with 39 additions and 4 deletions

View File

@@ -50,7 +50,8 @@ public final class LmkdStatsReporter {
* Logs the event when LMKD kills a process to reduce memory pressure.
* Code: LMK_KILL_OCCURRED = 51
*/
public static void logKillOccurred(DataInputStream inputData) {
public static void logKillOccurred(DataInputStream inputData, int totalForegroundServices,
int procsWithForegroundServices) {
try {
final long pgFault = inputData.readLong();
final long pgMajFault = inputData.readLong();
@@ -67,11 +68,10 @@ public final class LmkdStatsReporter {
final int thrashing = inputData.readInt();
final int maxThrashing = inputData.readInt();
final String procName = inputData.readUTF();
FrameworkStatsLog.write(FrameworkStatsLog.LMK_KILL_OCCURRED, uid, procName, oomScore,
pgFault, pgMajFault, rssInBytes, cacheInBytes, swapInBytes, processStartTimeNS,
minOomScore, freeMemKb, freeSwapKb, mapKillReason(killReason), thrashing,
maxThrashing);
maxThrashing, totalForegroundServices, procsWithForegroundServices);
} catch (IOException e) {
Slog.e(TAG, "Invalid buffer data. Failed to log LMK_KILL_OCCURRED");
return;

View File

@@ -814,7 +814,12 @@ public final class ProcessList {
< LmkdStatsReporter.KILL_OCCURRED_MSG_SIZE) {
return false;
}
LmkdStatsReporter.logKillOccurred(inputData);
Pair<Integer, Integer> temp = getNumForegroundServices();
final int totalForegroundServices = temp.first;
final int procsWithForegroundServices = temp.second;
LmkdStatsReporter.logKillOccurred(inputData,
totalForegroundServices,
procsWithForegroundServices);
return true;
case LMK_STATE_CHANGED:
if (receivedLen
@@ -5123,6 +5128,26 @@ public final class ProcessList {
}
}
/**
* Get the number of foreground services in all processes and number of processes that have
* foreground service within.
*/
Pair<Integer, Integer> getNumForegroundServices() {
int numForegroundServices = 0;
int procs = 0;
synchronized (mService) {
for (int i = 0, size = mLruProcesses.size(); i < size; i++) {
ProcessRecord pr = mLruProcesses.get(i);
int numFgs = pr.mServices.getNumForegroundServices();
if (numFgs > 0) {
numForegroundServices += numFgs;
procs++;
}
}
}
return new Pair<>(numForegroundServices, procs);
}
private final class ImperceptibleKillRunner extends IUidObserver.Stub {
private static final String EXTRA_PID = "pid";
private static final String EXTRA_UID = "uid";

View File

@@ -180,6 +180,16 @@ final class ProcessServiceRecord {
mRepFgServiceTypes = foregroundServiceTypes;
}
int getNumForegroundServices() {
int count = 0;
for (int i = 0, serviceCount = mServices.size(); i < serviceCount; i++) {
if (mServices.valueAt(i).isForeground) {
count++;
}
}
return count;
}
void updateHasTopStartedAlmostPerceptibleServices() {
mHasTopStartedAlmostPerceptibleServices = false;
mLastTopStartedAlmostPerceptibleBindRequestUptimeMs = 0;