Allow usagestats for multiple pkgs to be dumped.
+ Skip dumping database summaries when dumping data for specific pkgs. Bug: 145420790 Test: manual Change-Id: If4ac1008ffc73ad4b3227c0a407323b43547a6b8
This commit is contained in:
@@ -147,7 +147,7 @@ public interface AppStandbyInternal {
|
||||
|
||||
void postReportExemptedSyncStart(String packageName, int userId);
|
||||
|
||||
void dumpUser(IndentingPrintWriter idpw, int userId, String pkg);
|
||||
void dumpUser(IndentingPrintWriter idpw, int userId, List<String> pkgs);
|
||||
|
||||
void dumpState(String[] args, PrintWriter pw);
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ import android.util.TimeUtils;
|
||||
import android.util.Xml;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.util.CollectionUtils;
|
||||
import com.android.internal.util.FastXmlSerializer;
|
||||
import com.android.internal.util.IndentingPrintWriter;
|
||||
|
||||
@@ -58,6 +59,7 @@ import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Keeps track of recent active state changes in apps.
|
||||
@@ -721,7 +723,7 @@ public class AppIdleHistory {
|
||||
}
|
||||
}
|
||||
|
||||
public void dump(IndentingPrintWriter idpw, int userId, String pkg) {
|
||||
public void dump(IndentingPrintWriter idpw, int userId, List<String> pkgs) {
|
||||
idpw.println("App Standby States:");
|
||||
idpw.increaseIndent();
|
||||
ArrayMap<String, AppUsageHistory> userHistory = mIdleHistory.get(userId);
|
||||
@@ -733,7 +735,7 @@ public class AppIdleHistory {
|
||||
for (int p = 0; p < P; p++) {
|
||||
final String packageName = userHistory.keyAt(p);
|
||||
final AppUsageHistory appUsageHistory = userHistory.valueAt(p);
|
||||
if (pkg != null && !pkg.equals(packageName)) {
|
||||
if (!CollectionUtils.isEmpty(pkgs) && !pkgs.contains(packageName)) {
|
||||
continue;
|
||||
}
|
||||
idpw.print("package=" + packageName);
|
||||
|
||||
@@ -1505,9 +1505,9 @@ public class AppStandbyController implements AppStandbyInternal {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dumpUser(IndentingPrintWriter idpw, int userId, String pkg) {
|
||||
public void dumpUser(IndentingPrintWriter idpw, int userId, List<String> pkgs) {
|
||||
synchronized (mAppIdleLock) {
|
||||
mAppIdleHistory.dump(idpw, userId, pkg);
|
||||
mAppIdleHistory.dump(idpw, userId, pkgs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -86,6 +86,7 @@ import android.util.SparseIntArray;
|
||||
|
||||
import com.android.internal.content.PackageMonitor;
|
||||
import com.android.internal.os.BackgroundThread;
|
||||
import com.android.internal.util.CollectionUtils;
|
||||
import com.android.internal.util.DumpUtils;
|
||||
import com.android.internal.util.IndentingPrintWriter;
|
||||
import com.android.server.LocalServices;
|
||||
@@ -104,6 +105,7 @@ import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
@@ -1121,7 +1123,7 @@ public class UsageStatsService extends SystemService implements
|
||||
|
||||
boolean checkin = false;
|
||||
boolean compact = false;
|
||||
String pkg = null;
|
||||
final ArrayList<String> pkgs = new ArrayList<>();
|
||||
|
||||
if (args != null) {
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
@@ -1214,8 +1216,7 @@ public class UsageStatsService extends SystemService implements
|
||||
return;
|
||||
} else if (arg != null && !arg.startsWith("-")) {
|
||||
// Anything else that doesn't start with '-' is a pkg to filter
|
||||
pkg = arg;
|
||||
break;
|
||||
pkgs.add(arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1230,15 +1231,15 @@ public class UsageStatsService extends SystemService implements
|
||||
if (checkin) {
|
||||
mUserState.valueAt(i).checkin(idpw);
|
||||
} else {
|
||||
mUserState.valueAt(i).dump(idpw, pkg, compact);
|
||||
mUserState.valueAt(i).dump(idpw, pkgs, compact);
|
||||
idpw.println();
|
||||
}
|
||||
}
|
||||
mAppStandby.dumpUser(idpw, userId, pkg);
|
||||
mAppStandby.dumpUser(idpw, userId, pkgs);
|
||||
idpw.decreaseIndent();
|
||||
}
|
||||
|
||||
if (pkg == null) {
|
||||
if (CollectionUtils.isEmpty(pkgs)) {
|
||||
pw.println();
|
||||
mAppStandby.dumpState(args, pw);
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ import android.util.Slog;
|
||||
import android.util.SparseIntArray;
|
||||
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.internal.util.CollectionUtils;
|
||||
import com.android.internal.util.IndentingPrintWriter;
|
||||
import com.android.server.usage.UsageStatsDatabase.StatCombiner;
|
||||
|
||||
@@ -753,18 +754,21 @@ class UserUsageStatsService {
|
||||
});
|
||||
}
|
||||
|
||||
void dump(IndentingPrintWriter pw, String pkg) {
|
||||
dump(pw, pkg, false);
|
||||
void dump(IndentingPrintWriter pw, List<String> pkgs) {
|
||||
dump(pw, pkgs, false);
|
||||
}
|
||||
void dump(IndentingPrintWriter pw, String pkg, boolean compact) {
|
||||
printLast24HrEvents(pw, !compact, pkg);
|
||||
|
||||
void dump(IndentingPrintWriter pw, List<String> pkgs, boolean compact) {
|
||||
printLast24HrEvents(pw, !compact, pkgs);
|
||||
for (int interval = 0; interval < mCurrentStats.length; interval++) {
|
||||
pw.print("In-memory ");
|
||||
pw.print(intervalToString(interval));
|
||||
pw.println(" stats");
|
||||
printIntervalStats(pw, mCurrentStats[interval], !compact, true, pkg);
|
||||
printIntervalStats(pw, mCurrentStats[interval], !compact, true, pkgs);
|
||||
}
|
||||
if (CollectionUtils.isEmpty(pkgs)) {
|
||||
mDatabase.dump(pw, compact);
|
||||
}
|
||||
mDatabase.dump(pw, compact);
|
||||
}
|
||||
|
||||
void dumpDatabaseInfo(IndentingPrintWriter ipw) {
|
||||
@@ -894,7 +898,8 @@ class UserUsageStatsService {
|
||||
pw.println();
|
||||
}
|
||||
|
||||
void printLast24HrEvents(IndentingPrintWriter pw, boolean prettyDates, final String pkg) {
|
||||
void printLast24HrEvents(IndentingPrintWriter pw, boolean prettyDates,
|
||||
final List<String> pkgs) {
|
||||
final long endTime = System.currentTimeMillis();
|
||||
UnixCalendar yesterday = new UnixCalendar(endTime);
|
||||
yesterday.addDays(-1);
|
||||
@@ -914,7 +919,7 @@ class UserUsageStatsService {
|
||||
}
|
||||
|
||||
Event event = stats.events.get(i);
|
||||
if (pkg != null && !pkg.equals(event.mPackage)) {
|
||||
if (!CollectionUtils.isEmpty(pkgs) && !pkgs.contains(event.mPackage)) {
|
||||
continue;
|
||||
}
|
||||
accumulatedResult.add(event);
|
||||
@@ -958,7 +963,7 @@ class UserUsageStatsService {
|
||||
}
|
||||
|
||||
void printIntervalStats(IndentingPrintWriter pw, IntervalStats stats,
|
||||
boolean prettyDates, boolean skipEvents, String pkg) {
|
||||
boolean prettyDates, boolean skipEvents, List<String> pkgs) {
|
||||
if (prettyDates) {
|
||||
pw.printPair("timeRange", "\"" + DateUtils.formatDateRange(mContext,
|
||||
stats.beginTime, stats.endTime, sDateFormatFlags) + "\"");
|
||||
@@ -974,7 +979,7 @@ class UserUsageStatsService {
|
||||
final int pkgCount = pkgStats.size();
|
||||
for (int i = 0; i < pkgCount; i++) {
|
||||
final UsageStats usageStats = pkgStats.valueAt(i);
|
||||
if (pkg != null && !pkg.equals(usageStats.mPackageName)) {
|
||||
if (!CollectionUtils.isEmpty(pkgs) && !pkgs.contains(usageStats.mPackageName)) {
|
||||
continue;
|
||||
}
|
||||
pw.printPair("package", usageStats.mPackageName);
|
||||
@@ -998,7 +1003,7 @@ class UserUsageStatsService {
|
||||
pw.println("ChooserCounts");
|
||||
pw.increaseIndent();
|
||||
for (UsageStats usageStats : pkgStats.values()) {
|
||||
if (pkg != null && !pkg.equals(usageStats.mPackageName)) {
|
||||
if (!CollectionUtils.isEmpty(pkgs) && !pkgs.contains(usageStats.mPackageName)) {
|
||||
continue;
|
||||
}
|
||||
pw.printPair("package", usageStats.mPackageName);
|
||||
@@ -1023,7 +1028,7 @@ class UserUsageStatsService {
|
||||
}
|
||||
pw.decreaseIndent();
|
||||
|
||||
if (pkg == null) {
|
||||
if (CollectionUtils.isEmpty(pkgs)) {
|
||||
pw.println("configurations");
|
||||
pw.increaseIndent();
|
||||
final ArrayMap<Configuration, ConfigurationStats> configStats = stats.configurations;
|
||||
@@ -1060,7 +1065,7 @@ class UserUsageStatsService {
|
||||
final int eventCount = events != null ? events.size() : 0;
|
||||
for (int i = 0; i < eventCount; i++) {
|
||||
final Event event = events.get(i);
|
||||
if (pkg != null && !pkg.equals(event.mPackage)) {
|
||||
if (!CollectionUtils.isEmpty(pkgs) && !pkgs.contains(event.mPackage)) {
|
||||
continue;
|
||||
}
|
||||
printEvent(pw, event, prettyDates);
|
||||
|
||||
Reference in New Issue
Block a user