use of com.android.internal.app.procstats.ProcessStats in project packages_apps_Settings by Spark-Rom.
the class ProcStatsData method load.
private void load() {
try {
ParcelFileDescriptor pfd = mProcessStats.getStatsOverTime(mDuration);
mStats = new ProcessStats(false);
InputStream is = new ParcelFileDescriptor.AutoCloseInputStream(pfd);
mStats.read(is);
try {
is.close();
} catch (IOException e) {
}
if (mStats.mReadError != null) {
Log.w(TAG, "Failure reading process stats: " + mStats.mReadError);
}
} catch (RemoteException e) {
Log.e(TAG, "RemoteException:", e);
}
}
use of com.android.internal.app.procstats.ProcessStats in project platform_frameworks_base by android.
the class ProcessStatsService method readLocked.
boolean readLocked(ProcessStats stats, AtomicFile file) {
try {
FileInputStream stream = file.openRead();
stats.read(stream);
stream.close();
if (stats.mReadError != null) {
Slog.w(TAG, "Ignoring existing stats; " + stats.mReadError);
if (DEBUG) {
ArrayMap<String, SparseArray<ProcessState>> procMap = stats.mProcesses.getMap();
final int NPROC = procMap.size();
for (int ip = 0; ip < NPROC; ip++) {
Slog.w(TAG, "Process: " + procMap.keyAt(ip));
SparseArray<ProcessState> uids = procMap.valueAt(ip);
final int NUID = uids.size();
for (int iu = 0; iu < NUID; iu++) {
Slog.w(TAG, " Uid " + uids.keyAt(iu) + ": " + uids.valueAt(iu));
}
}
ArrayMap<String, SparseArray<SparseArray<ProcessStats.PackageState>>> pkgMap = stats.mPackages.getMap();
final int NPKG = pkgMap.size();
for (int ip = 0; ip < NPKG; ip++) {
Slog.w(TAG, "Package: " + pkgMap.keyAt(ip));
SparseArray<SparseArray<ProcessStats.PackageState>> uids = pkgMap.valueAt(ip);
final int NUID = uids.size();
for (int iu = 0; iu < NUID; iu++) {
Slog.w(TAG, " Uid: " + uids.keyAt(iu));
SparseArray<ProcessStats.PackageState> vers = uids.valueAt(iu);
final int NVERS = vers.size();
for (int iv = 0; iv < NVERS; iv++) {
Slog.w(TAG, " Vers: " + vers.keyAt(iv));
ProcessStats.PackageState pkgState = vers.valueAt(iv);
final int NPROCS = pkgState.mProcesses.size();
for (int iproc = 0; iproc < NPROCS; iproc++) {
Slog.w(TAG, " Process " + pkgState.mProcesses.keyAt(iproc) + ": " + pkgState.mProcesses.valueAt(iproc));
}
final int NSRVS = pkgState.mServices.size();
for (int isvc = 0; isvc < NSRVS; isvc++) {
Slog.w(TAG, " Service " + pkgState.mServices.keyAt(isvc) + ": " + pkgState.mServices.valueAt(isvc));
}
}
}
}
}
return false;
}
} catch (Throwable e) {
stats.mReadError = "caught exception: " + e;
Slog.e(TAG, "Error reading process statistics", e);
return false;
}
return true;
}
use of com.android.internal.app.procstats.ProcessStats in project platform_frameworks_base by android.
the class ProcessStatsService method dumpAggregatedStats.
private void dumpAggregatedStats(PrintWriter pw, long aggregateHours, long now, String reqPackage, boolean isCompact, boolean dumpDetails, boolean dumpFullDetails, boolean dumpAll, boolean activeOnly) {
ParcelFileDescriptor pfd = getStatsOverTime(aggregateHours * 60 * 60 * 1000 - (ProcessStats.COMMIT_PERIOD / 2));
if (pfd == null) {
pw.println("Unable to build stats!");
return;
}
ProcessStats stats = new ProcessStats(false);
InputStream stream = new ParcelFileDescriptor.AutoCloseInputStream(pfd);
stats.read(stream);
if (stats.mReadError != null) {
pw.print("Failure reading: ");
pw.println(stats.mReadError);
return;
}
if (isCompact) {
stats.dumpCheckinLocked(pw, reqPackage);
} else {
if (dumpDetails || dumpFullDetails) {
stats.dumpLocked(pw, reqPackage, now, !dumpFullDetails, dumpAll, activeOnly);
} else {
stats.dumpSummaryLocked(pw, reqPackage, now, activeOnly);
}
}
}
use of com.android.internal.app.procstats.ProcessStats in project platform_frameworks_base by android.
the class ProcessStatsService method dumpInner.
private void dumpInner(FileDescriptor fd, PrintWriter pw, String[] args) {
final long now = SystemClock.uptimeMillis();
boolean isCheckin = false;
boolean isCompact = false;
boolean isCsv = false;
boolean currentOnly = false;
boolean dumpDetails = false;
boolean dumpFullDetails = false;
boolean dumpAll = false;
boolean quit = false;
int aggregateHours = 0;
int lastIndex = 0;
int maxNum = 2;
boolean activeOnly = false;
String reqPackage = null;
boolean csvSepScreenStats = false;
int[] csvScreenStats = new int[] { ProcessStats.ADJ_SCREEN_OFF, ProcessStats.ADJ_SCREEN_ON };
boolean csvSepMemStats = false;
int[] csvMemStats = new int[] { ProcessStats.ADJ_MEM_FACTOR_CRITICAL };
boolean csvSepProcStats = true;
int[] csvProcStats = ProcessStats.ALL_PROC_STATES;
if (args != null) {
for (int i = 0; i < args.length; i++) {
String arg = args[i];
if ("--checkin".equals(arg)) {
isCheckin = true;
} else if ("-c".equals(arg)) {
isCompact = true;
} else if ("--csv".equals(arg)) {
isCsv = true;
} else if ("--csv-screen".equals(arg)) {
i++;
if (i >= args.length) {
pw.println("Error: argument required for --csv-screen");
dumpHelp(pw);
return;
}
boolean[] sep = new boolean[1];
String[] error = new String[1];
csvScreenStats = parseStateList(DumpUtils.ADJ_SCREEN_NAMES_CSV, ProcessStats.ADJ_SCREEN_MOD, args[i], sep, error);
if (csvScreenStats == null) {
pw.println("Error in \"" + args[i] + "\": " + error[0]);
dumpHelp(pw);
return;
}
csvSepScreenStats = sep[0];
} else if ("--csv-mem".equals(arg)) {
i++;
if (i >= args.length) {
pw.println("Error: argument required for --csv-mem");
dumpHelp(pw);
return;
}
boolean[] sep = new boolean[1];
String[] error = new String[1];
csvMemStats = parseStateList(DumpUtils.ADJ_MEM_NAMES_CSV, 1, args[i], sep, error);
if (csvMemStats == null) {
pw.println("Error in \"" + args[i] + "\": " + error[0]);
dumpHelp(pw);
return;
}
csvSepMemStats = sep[0];
} else if ("--csv-proc".equals(arg)) {
i++;
if (i >= args.length) {
pw.println("Error: argument required for --csv-proc");
dumpHelp(pw);
return;
}
boolean[] sep = new boolean[1];
String[] error = new String[1];
csvProcStats = parseStateList(DumpUtils.STATE_NAMES_CSV, 1, args[i], sep, error);
if (csvProcStats == null) {
pw.println("Error in \"" + args[i] + "\": " + error[0]);
dumpHelp(pw);
return;
}
csvSepProcStats = sep[0];
} else if ("--details".equals(arg)) {
dumpDetails = true;
} else if ("--full-details".equals(arg)) {
dumpFullDetails = true;
} else if ("--hours".equals(arg)) {
i++;
if (i >= args.length) {
pw.println("Error: argument required for --hours");
dumpHelp(pw);
return;
}
try {
aggregateHours = Integer.parseInt(args[i]);
} catch (NumberFormatException e) {
pw.println("Error: --hours argument not an int -- " + args[i]);
dumpHelp(pw);
return;
}
} else if ("--last".equals(arg)) {
i++;
if (i >= args.length) {
pw.println("Error: argument required for --last");
dumpHelp(pw);
return;
}
try {
lastIndex = Integer.parseInt(args[i]);
} catch (NumberFormatException e) {
pw.println("Error: --last argument not an int -- " + args[i]);
dumpHelp(pw);
return;
}
} else if ("--max".equals(arg)) {
i++;
if (i >= args.length) {
pw.println("Error: argument required for --max");
dumpHelp(pw);
return;
}
try {
maxNum = Integer.parseInt(args[i]);
} catch (NumberFormatException e) {
pw.println("Error: --max argument not an int -- " + args[i]);
dumpHelp(pw);
return;
}
} else if ("--active".equals(arg)) {
activeOnly = true;
currentOnly = true;
} else if ("--current".equals(arg)) {
currentOnly = true;
} else if ("--commit".equals(arg)) {
synchronized (mAm) {
mProcessStats.mFlags |= ProcessStats.FLAG_COMPLETE;
writeStateLocked(true, true);
pw.println("Process stats committed.");
quit = true;
}
} else if ("--reset".equals(arg)) {
synchronized (mAm) {
mProcessStats.resetSafely();
pw.println("Process stats reset.");
quit = true;
}
} else if ("--clear".equals(arg)) {
synchronized (mAm) {
mProcessStats.resetSafely();
ArrayList<String> files = getCommittedFiles(0, true, true);
if (files != null) {
for (int fi = 0; fi < files.size(); fi++) {
(new File(files.get(fi))).delete();
}
}
pw.println("All process stats cleared.");
quit = true;
}
} else if ("--write".equals(arg)) {
synchronized (mAm) {
writeStateSyncLocked();
pw.println("Process stats written.");
quit = true;
}
} else if ("--read".equals(arg)) {
synchronized (mAm) {
readLocked(mProcessStats, mFile);
pw.println("Process stats read.");
quit = true;
}
} else if ("--start-testing".equals(arg)) {
synchronized (mAm) {
mAm.setTestPssMode(true);
pw.println("Started high frequency sampling.");
quit = true;
}
} else if ("--stop-testing".equals(arg)) {
synchronized (mAm) {
mAm.setTestPssMode(false);
pw.println("Stopped high frequency sampling.");
quit = true;
}
} else if ("-h".equals(arg)) {
dumpHelp(pw);
return;
} else if ("-a".equals(arg)) {
dumpDetails = true;
dumpAll = true;
} else if (arg.length() > 0 && arg.charAt(0) == '-') {
pw.println("Unknown option: " + arg);
dumpHelp(pw);
return;
} else {
// Not an option, last argument must be a package name.
reqPackage = arg;
// Include all details, since we know we are only going to
// be dumping a smaller set of data. In fact only the details
// contain per-package data, so this is needed to be able
// to dump anything at all when filtering by package.
dumpDetails = true;
}
}
}
if (quit) {
return;
}
if (isCsv) {
pw.print("Processes running summed over");
if (!csvSepScreenStats) {
for (int i = 0; i < csvScreenStats.length; i++) {
pw.print(" ");
DumpUtils.printScreenLabelCsv(pw, csvScreenStats[i]);
}
}
if (!csvSepMemStats) {
for (int i = 0; i < csvMemStats.length; i++) {
pw.print(" ");
DumpUtils.printMemLabelCsv(pw, csvMemStats[i]);
}
}
if (!csvSepProcStats) {
for (int i = 0; i < csvProcStats.length; i++) {
pw.print(" ");
pw.print(DumpUtils.STATE_NAMES_CSV[csvProcStats[i]]);
}
}
pw.println();
synchronized (mAm) {
dumpFilteredProcessesCsvLocked(pw, null, csvSepScreenStats, csvScreenStats, csvSepMemStats, csvMemStats, csvSepProcStats, csvProcStats, now, reqPackage);
/*
dumpFilteredProcessesCsvLocked(pw, "Processes running while critical mem:",
false, new int[] {ADJ_SCREEN_OFF, ADJ_SCREEN_ON},
true, new int[] {ADJ_MEM_FACTOR_CRITICAL},
true, new int[] {STATE_PERSISTENT, STATE_TOP, STATE_FOREGROUND, STATE_VISIBLE,
STATE_PERCEPTIBLE, STATE_BACKUP, STATE_SERVICE, STATE_HOME,
STATE_PREVIOUS, STATE_CACHED},
now, reqPackage);
dumpFilteredProcessesCsvLocked(pw, "Processes running over all mem:",
false, new int[] {ADJ_SCREEN_OFF, ADJ_SCREEN_ON},
false, new int[] {ADJ_MEM_FACTOR_CRITICAL, ADJ_MEM_FACTOR_LOW,
ADJ_MEM_FACTOR_MODERATE, ADJ_MEM_FACTOR_MODERATE},
true, new int[] {STATE_PERSISTENT, STATE_TOP, STATE_FOREGROUND, STATE_VISIBLE,
STATE_PERCEPTIBLE, STATE_BACKUP, STATE_SERVICE, STATE_HOME,
STATE_PREVIOUS, STATE_CACHED},
now, reqPackage);
*/
}
return;
} else if (aggregateHours != 0) {
pw.print("AGGREGATED OVER LAST ");
pw.print(aggregateHours);
pw.println(" HOURS:");
dumpAggregatedStats(pw, aggregateHours, now, reqPackage, isCompact, dumpDetails, dumpFullDetails, dumpAll, activeOnly);
return;
} else if (lastIndex > 0) {
pw.print("LAST STATS AT INDEX ");
pw.print(lastIndex);
pw.println(":");
ArrayList<String> files = getCommittedFiles(0, false, true);
if (lastIndex >= files.size()) {
pw.print("Only have ");
pw.print(files.size());
pw.println(" data sets");
return;
}
AtomicFile file = new AtomicFile(new File(files.get(lastIndex)));
ProcessStats processStats = new ProcessStats(false);
readLocked(processStats, file);
if (processStats.mReadError != null) {
if (isCheckin || isCompact)
pw.print("err,");
pw.print("Failure reading ");
pw.print(files.get(lastIndex));
pw.print("; ");
pw.println(processStats.mReadError);
return;
}
String fileStr = file.getBaseFile().getPath();
boolean checkedIn = fileStr.endsWith(STATE_FILE_CHECKIN_SUFFIX);
if (isCheckin || isCompact) {
// Don't really need to lock because we uniquely own this object.
processStats.dumpCheckinLocked(pw, reqPackage);
} else {
pw.print("COMMITTED STATS FROM ");
pw.print(processStats.mTimePeriodStartClockStr);
if (checkedIn)
pw.print(" (checked in)");
pw.println(":");
if (dumpDetails || dumpFullDetails) {
processStats.dumpLocked(pw, reqPackage, now, !dumpFullDetails, dumpAll, activeOnly);
if (dumpAll) {
pw.print(" mFile=");
pw.println(mFile.getBaseFile());
}
} else {
processStats.dumpSummaryLocked(pw, reqPackage, now, activeOnly);
}
}
return;
}
boolean sepNeeded = false;
if (dumpAll || isCheckin) {
mWriteLock.lock();
try {
ArrayList<String> files = getCommittedFiles(0, false, !isCheckin);
if (files != null) {
int start = isCheckin ? 0 : (files.size() - maxNum);
if (start < 0) {
start = 0;
}
for (int i = start; i < files.size(); i++) {
if (DEBUG)
Slog.d(TAG, "Retrieving state: " + files.get(i));
try {
AtomicFile file = new AtomicFile(new File(files.get(i)));
ProcessStats processStats = new ProcessStats(false);
readLocked(processStats, file);
if (processStats.mReadError != null) {
if (isCheckin || isCompact)
pw.print("err,");
pw.print("Failure reading ");
pw.print(files.get(i));
pw.print("; ");
pw.println(processStats.mReadError);
if (DEBUG)
Slog.d(TAG, "Deleting state: " + files.get(i));
(new File(files.get(i))).delete();
continue;
}
String fileStr = file.getBaseFile().getPath();
boolean checkedIn = fileStr.endsWith(STATE_FILE_CHECKIN_SUFFIX);
if (isCheckin || isCompact) {
// Don't really need to lock because we uniquely own this object.
processStats.dumpCheckinLocked(pw, reqPackage);
} else {
if (sepNeeded) {
pw.println();
} else {
sepNeeded = true;
}
pw.print("COMMITTED STATS FROM ");
pw.print(processStats.mTimePeriodStartClockStr);
if (checkedIn)
pw.print(" (checked in)");
pw.println(":");
// much crud.
if (dumpFullDetails) {
processStats.dumpLocked(pw, reqPackage, now, false, false, activeOnly);
} else {
processStats.dumpSummaryLocked(pw, reqPackage, now, activeOnly);
}
}
if (isCheckin) {
// Rename file suffix to mark that it has checked in.
file.getBaseFile().renameTo(new File(fileStr + STATE_FILE_CHECKIN_SUFFIX));
}
} catch (Throwable e) {
pw.print("**** FAILURE DUMPING STATE: ");
pw.println(files.get(i));
e.printStackTrace(pw);
}
}
}
} finally {
mWriteLock.unlock();
}
}
if (!isCheckin) {
synchronized (mAm) {
if (isCompact) {
mProcessStats.dumpCheckinLocked(pw, reqPackage);
} else {
if (sepNeeded) {
pw.println();
}
pw.println("CURRENT STATS:");
if (dumpDetails || dumpFullDetails) {
mProcessStats.dumpLocked(pw, reqPackage, now, !dumpFullDetails, dumpAll, activeOnly);
if (dumpAll) {
pw.print(" mFile=");
pw.println(mFile.getBaseFile());
}
} else {
mProcessStats.dumpSummaryLocked(pw, reqPackage, now, activeOnly);
}
sepNeeded = true;
}
}
if (!currentOnly) {
if (sepNeeded) {
pw.println();
}
pw.println("AGGREGATED OVER LAST 24 HOURS:");
dumpAggregatedStats(pw, 24, now, reqPackage, isCompact, dumpDetails, dumpFullDetails, dumpAll, activeOnly);
pw.println();
pw.println("AGGREGATED OVER LAST 3 HOURS:");
dumpAggregatedStats(pw, 3, now, reqPackage, isCompact, dumpDetails, dumpFullDetails, dumpAll, activeOnly);
}
}
}
use of com.android.internal.app.procstats.ProcessStats in project android_frameworks_base by DirtyUnicorns.
the class ProcessStatsService method dumpInner.
private void dumpInner(FileDescriptor fd, PrintWriter pw, String[] args) {
final long now = SystemClock.uptimeMillis();
boolean isCheckin = false;
boolean isCompact = false;
boolean isCsv = false;
boolean currentOnly = false;
boolean dumpDetails = false;
boolean dumpFullDetails = false;
boolean dumpAll = false;
boolean quit = false;
int aggregateHours = 0;
int lastIndex = 0;
int maxNum = 2;
boolean activeOnly = false;
String reqPackage = null;
boolean csvSepScreenStats = false;
int[] csvScreenStats = new int[] { ProcessStats.ADJ_SCREEN_OFF, ProcessStats.ADJ_SCREEN_ON };
boolean csvSepMemStats = false;
int[] csvMemStats = new int[] { ProcessStats.ADJ_MEM_FACTOR_CRITICAL };
boolean csvSepProcStats = true;
int[] csvProcStats = ProcessStats.ALL_PROC_STATES;
if (args != null) {
for (int i = 0; i < args.length; i++) {
String arg = args[i];
if ("--checkin".equals(arg)) {
isCheckin = true;
} else if ("-c".equals(arg)) {
isCompact = true;
} else if ("--csv".equals(arg)) {
isCsv = true;
} else if ("--csv-screen".equals(arg)) {
i++;
if (i >= args.length) {
pw.println("Error: argument required for --csv-screen");
dumpHelp(pw);
return;
}
boolean[] sep = new boolean[1];
String[] error = new String[1];
csvScreenStats = parseStateList(DumpUtils.ADJ_SCREEN_NAMES_CSV, ProcessStats.ADJ_SCREEN_MOD, args[i], sep, error);
if (csvScreenStats == null) {
pw.println("Error in \"" + args[i] + "\": " + error[0]);
dumpHelp(pw);
return;
}
csvSepScreenStats = sep[0];
} else if ("--csv-mem".equals(arg)) {
i++;
if (i >= args.length) {
pw.println("Error: argument required for --csv-mem");
dumpHelp(pw);
return;
}
boolean[] sep = new boolean[1];
String[] error = new String[1];
csvMemStats = parseStateList(DumpUtils.ADJ_MEM_NAMES_CSV, 1, args[i], sep, error);
if (csvMemStats == null) {
pw.println("Error in \"" + args[i] + "\": " + error[0]);
dumpHelp(pw);
return;
}
csvSepMemStats = sep[0];
} else if ("--csv-proc".equals(arg)) {
i++;
if (i >= args.length) {
pw.println("Error: argument required for --csv-proc");
dumpHelp(pw);
return;
}
boolean[] sep = new boolean[1];
String[] error = new String[1];
csvProcStats = parseStateList(DumpUtils.STATE_NAMES_CSV, 1, args[i], sep, error);
if (csvProcStats == null) {
pw.println("Error in \"" + args[i] + "\": " + error[0]);
dumpHelp(pw);
return;
}
csvSepProcStats = sep[0];
} else if ("--details".equals(arg)) {
dumpDetails = true;
} else if ("--full-details".equals(arg)) {
dumpFullDetails = true;
} else if ("--hours".equals(arg)) {
i++;
if (i >= args.length) {
pw.println("Error: argument required for --hours");
dumpHelp(pw);
return;
}
try {
aggregateHours = Integer.parseInt(args[i]);
} catch (NumberFormatException e) {
pw.println("Error: --hours argument not an int -- " + args[i]);
dumpHelp(pw);
return;
}
} else if ("--last".equals(arg)) {
i++;
if (i >= args.length) {
pw.println("Error: argument required for --last");
dumpHelp(pw);
return;
}
try {
lastIndex = Integer.parseInt(args[i]);
} catch (NumberFormatException e) {
pw.println("Error: --last argument not an int -- " + args[i]);
dumpHelp(pw);
return;
}
} else if ("--max".equals(arg)) {
i++;
if (i >= args.length) {
pw.println("Error: argument required for --max");
dumpHelp(pw);
return;
}
try {
maxNum = Integer.parseInt(args[i]);
} catch (NumberFormatException e) {
pw.println("Error: --max argument not an int -- " + args[i]);
dumpHelp(pw);
return;
}
} else if ("--active".equals(arg)) {
activeOnly = true;
currentOnly = true;
} else if ("--current".equals(arg)) {
currentOnly = true;
} else if ("--commit".equals(arg)) {
synchronized (mAm) {
mProcessStats.mFlags |= ProcessStats.FLAG_COMPLETE;
writeStateLocked(true, true);
pw.println("Process stats committed.");
quit = true;
}
} else if ("--reset".equals(arg)) {
synchronized (mAm) {
mProcessStats.resetSafely();
pw.println("Process stats reset.");
quit = true;
}
} else if ("--clear".equals(arg)) {
synchronized (mAm) {
mProcessStats.resetSafely();
ArrayList<String> files = getCommittedFiles(0, true, true);
if (files != null) {
for (int fi = 0; fi < files.size(); fi++) {
(new File(files.get(fi))).delete();
}
}
pw.println("All process stats cleared.");
quit = true;
}
} else if ("--write".equals(arg)) {
synchronized (mAm) {
writeStateSyncLocked();
pw.println("Process stats written.");
quit = true;
}
} else if ("--read".equals(arg)) {
synchronized (mAm) {
readLocked(mProcessStats, mFile);
pw.println("Process stats read.");
quit = true;
}
} else if ("--start-testing".equals(arg)) {
synchronized (mAm) {
mAm.setTestPssMode(true);
pw.println("Started high frequency sampling.");
quit = true;
}
} else if ("--stop-testing".equals(arg)) {
synchronized (mAm) {
mAm.setTestPssMode(false);
pw.println("Stopped high frequency sampling.");
quit = true;
}
} else if ("-h".equals(arg)) {
dumpHelp(pw);
return;
} else if ("-a".equals(arg)) {
dumpDetails = true;
dumpAll = true;
} else if (arg.length() > 0 && arg.charAt(0) == '-') {
pw.println("Unknown option: " + arg);
dumpHelp(pw);
return;
} else {
// Not an option, last argument must be a package name.
reqPackage = arg;
// Include all details, since we know we are only going to
// be dumping a smaller set of data. In fact only the details
// contain per-package data, so this is needed to be able
// to dump anything at all when filtering by package.
dumpDetails = true;
}
}
}
if (quit) {
return;
}
if (isCsv) {
pw.print("Processes running summed over");
if (!csvSepScreenStats) {
for (int i = 0; i < csvScreenStats.length; i++) {
pw.print(" ");
DumpUtils.printScreenLabelCsv(pw, csvScreenStats[i]);
}
}
if (!csvSepMemStats) {
for (int i = 0; i < csvMemStats.length; i++) {
pw.print(" ");
DumpUtils.printMemLabelCsv(pw, csvMemStats[i]);
}
}
if (!csvSepProcStats) {
for (int i = 0; i < csvProcStats.length; i++) {
pw.print(" ");
pw.print(DumpUtils.STATE_NAMES_CSV[csvProcStats[i]]);
}
}
pw.println();
synchronized (mAm) {
dumpFilteredProcessesCsvLocked(pw, null, csvSepScreenStats, csvScreenStats, csvSepMemStats, csvMemStats, csvSepProcStats, csvProcStats, now, reqPackage);
/*
dumpFilteredProcessesCsvLocked(pw, "Processes running while critical mem:",
false, new int[] {ADJ_SCREEN_OFF, ADJ_SCREEN_ON},
true, new int[] {ADJ_MEM_FACTOR_CRITICAL},
true, new int[] {STATE_PERSISTENT, STATE_TOP, STATE_FOREGROUND, STATE_VISIBLE,
STATE_PERCEPTIBLE, STATE_BACKUP, STATE_SERVICE, STATE_HOME,
STATE_PREVIOUS, STATE_CACHED},
now, reqPackage);
dumpFilteredProcessesCsvLocked(pw, "Processes running over all mem:",
false, new int[] {ADJ_SCREEN_OFF, ADJ_SCREEN_ON},
false, new int[] {ADJ_MEM_FACTOR_CRITICAL, ADJ_MEM_FACTOR_LOW,
ADJ_MEM_FACTOR_MODERATE, ADJ_MEM_FACTOR_MODERATE},
true, new int[] {STATE_PERSISTENT, STATE_TOP, STATE_FOREGROUND, STATE_VISIBLE,
STATE_PERCEPTIBLE, STATE_BACKUP, STATE_SERVICE, STATE_HOME,
STATE_PREVIOUS, STATE_CACHED},
now, reqPackage);
*/
}
return;
} else if (aggregateHours != 0) {
pw.print("AGGREGATED OVER LAST ");
pw.print(aggregateHours);
pw.println(" HOURS:");
dumpAggregatedStats(pw, aggregateHours, now, reqPackage, isCompact, dumpDetails, dumpFullDetails, dumpAll, activeOnly);
return;
} else if (lastIndex > 0) {
pw.print("LAST STATS AT INDEX ");
pw.print(lastIndex);
pw.println(":");
ArrayList<String> files = getCommittedFiles(0, false, true);
if (lastIndex >= files.size()) {
pw.print("Only have ");
pw.print(files.size());
pw.println(" data sets");
return;
}
AtomicFile file = new AtomicFile(new File(files.get(lastIndex)));
ProcessStats processStats = new ProcessStats(false);
readLocked(processStats, file);
if (processStats.mReadError != null) {
if (isCheckin || isCompact)
pw.print("err,");
pw.print("Failure reading ");
pw.print(files.get(lastIndex));
pw.print("; ");
pw.println(processStats.mReadError);
return;
}
String fileStr = file.getBaseFile().getPath();
boolean checkedIn = fileStr.endsWith(STATE_FILE_CHECKIN_SUFFIX);
if (isCheckin || isCompact) {
// Don't really need to lock because we uniquely own this object.
processStats.dumpCheckinLocked(pw, reqPackage);
} else {
pw.print("COMMITTED STATS FROM ");
pw.print(processStats.mTimePeriodStartClockStr);
if (checkedIn)
pw.print(" (checked in)");
pw.println(":");
if (dumpDetails || dumpFullDetails) {
processStats.dumpLocked(pw, reqPackage, now, !dumpFullDetails, dumpAll, activeOnly);
if (dumpAll) {
pw.print(" mFile=");
pw.println(mFile.getBaseFile());
}
} else {
processStats.dumpSummaryLocked(pw, reqPackage, now, activeOnly);
}
}
return;
}
boolean sepNeeded = false;
if (dumpAll || isCheckin) {
mWriteLock.lock();
try {
ArrayList<String> files = getCommittedFiles(0, false, !isCheckin);
if (files != null) {
int start = isCheckin ? 0 : (files.size() - maxNum);
if (start < 0) {
start = 0;
}
for (int i = start; i < files.size(); i++) {
if (DEBUG)
Slog.d(TAG, "Retrieving state: " + files.get(i));
try {
AtomicFile file = new AtomicFile(new File(files.get(i)));
ProcessStats processStats = new ProcessStats(false);
readLocked(processStats, file);
if (processStats.mReadError != null) {
if (isCheckin || isCompact)
pw.print("err,");
pw.print("Failure reading ");
pw.print(files.get(i));
pw.print("; ");
pw.println(processStats.mReadError);
if (DEBUG)
Slog.d(TAG, "Deleting state: " + files.get(i));
(new File(files.get(i))).delete();
continue;
}
String fileStr = file.getBaseFile().getPath();
boolean checkedIn = fileStr.endsWith(STATE_FILE_CHECKIN_SUFFIX);
if (isCheckin || isCompact) {
// Don't really need to lock because we uniquely own this object.
processStats.dumpCheckinLocked(pw, reqPackage);
} else {
if (sepNeeded) {
pw.println();
} else {
sepNeeded = true;
}
pw.print("COMMITTED STATS FROM ");
pw.print(processStats.mTimePeriodStartClockStr);
if (checkedIn)
pw.print(" (checked in)");
pw.println(":");
// much crud.
if (dumpFullDetails) {
processStats.dumpLocked(pw, reqPackage, now, false, false, activeOnly);
} else {
processStats.dumpSummaryLocked(pw, reqPackage, now, activeOnly);
}
}
if (isCheckin) {
// Rename file suffix to mark that it has checked in.
file.getBaseFile().renameTo(new File(fileStr + STATE_FILE_CHECKIN_SUFFIX));
}
} catch (Throwable e) {
pw.print("**** FAILURE DUMPING STATE: ");
pw.println(files.get(i));
e.printStackTrace(pw);
}
}
}
} finally {
mWriteLock.unlock();
}
}
if (!isCheckin) {
synchronized (mAm) {
if (isCompact) {
mProcessStats.dumpCheckinLocked(pw, reqPackage);
} else {
if (sepNeeded) {
pw.println();
}
pw.println("CURRENT STATS:");
if (dumpDetails || dumpFullDetails) {
mProcessStats.dumpLocked(pw, reqPackage, now, !dumpFullDetails, dumpAll, activeOnly);
if (dumpAll) {
pw.print(" mFile=");
pw.println(mFile.getBaseFile());
}
} else {
mProcessStats.dumpSummaryLocked(pw, reqPackage, now, activeOnly);
}
sepNeeded = true;
}
}
if (!currentOnly) {
if (sepNeeded) {
pw.println();
}
pw.println("AGGREGATED OVER LAST 24 HOURS:");
dumpAggregatedStats(pw, 24, now, reqPackage, isCompact, dumpDetails, dumpFullDetails, dumpAll, activeOnly);
pw.println();
pw.println("AGGREGATED OVER LAST 3 HOURS:");
dumpAggregatedStats(pw, 3, now, reqPackage, isCompact, dumpDetails, dumpFullDetails, dumpAll, activeOnly);
}
}
}
Aggregations