Dump snapshot statistics in the bugreport

Also remove the corked function which is not used anymore
in the SnapshotStatistics.

Bug: 247671650
Test: adb shell dumpsys package
Change-Id: I11806d279171cfdce1c80bc310ab317b255a16df
This commit is contained in:
Rhed Jao
2022-10-12 19:05:54 +08:00
parent a918fd1767
commit c9090f283a
3 changed files with 15 additions and 34 deletions

View File

@@ -26,6 +26,7 @@ import android.content.ComponentName;
import android.content.pm.FeatureInfo;
import android.content.pm.PackageManager;
import android.os.Binder;
import android.os.SystemClock;
import android.os.UserHandle;
import android.os.incremental.PerUidReadTimeouts;
import android.service.pm.PackageServiceDumpProto;
@@ -60,6 +61,7 @@ final class DumpHelper {
private final ArrayMap<String, FeatureInfo> mAvailableFeatures;
private final ArraySet<String> mProtectedBroadcasts;
private final PerUidReadTimeouts[] mPerUidReadTimeouts;
private final SnapshotStatistics mSnapshotStatistics;
DumpHelper(
PermissionManagerServiceInternal permissionManager,
@@ -70,7 +72,8 @@ final class DumpHelper {
ChangedPackagesTracker changedPackagesTracker,
ArrayMap<String, FeatureInfo> availableFeatures,
ArraySet<String> protectedBroadcasts,
PerUidReadTimeouts[] perUidReadTimeouts) {
PerUidReadTimeouts[] perUidReadTimeouts,
SnapshotStatistics snapshotStatistics) {
mPermissionManager = permissionManager;
mStorageEventHelper = storageEventHelper;
mDomainVerificationManager = domainVerificationManager;
@@ -81,6 +84,7 @@ final class DumpHelper {
mAvailableFeatures = availableFeatures;
mProtectedBroadcasts = protectedBroadcasts;
mPerUidReadTimeouts = perUidReadTimeouts;
mSnapshotStatistics = snapshotStatistics;
}
@NeverCompile // Avoid size overhead of debugging code.
@@ -585,6 +589,9 @@ final class DumpHelper {
if (dumpState.onTitlePrinted()) {
pw.println();
}
pw.println("Snapshot statistics:");
mSnapshotStatistics.dump(pw, " " /* indent */, SystemClock.currentTimeMicro(),
snapshot.getUsed(), dumpState.isBrief());
}
if (!checkin

View File

@@ -6031,7 +6031,7 @@ public class PackageManagerService implements PackageSender, TestUtilityService
new DumpHelper(mPermissionManager, mStorageEventHelper,
mDomainVerificationManager, mInstallerService, mRequiredVerifierPackages,
knownPackages, mChangedPackagesTracker, availableFeatures, protectedBroadcasts,
getPerUidReadTimeouts(snapshot)
getPerUidReadTimeouts(snapshot), mSnapshotStatistics
).doDump(snapshot, fd, pw, args);
}
}

View File

@@ -239,11 +239,6 @@ public class SnapshotStatistics {
*/
public int mTotalUsed = 0;
/**
* The total number of times a snapshot was bypassed because corking was in effect.
*/
public int mTotalCorked = 0;
/**
* The total number of builds that count as big, which means they took longer than
* SNAPSHOT_BIG_BUILD_TIME_NS.
@@ -297,13 +292,6 @@ public class SnapshotStatistics {
}
}
/**
* Record a cork.
*/
private void corked() {
mTotalCorked++;
}
private Stats(long now) {
mStartTimeUs = now;
mTimes = new int[mTimeBins.count()];
@@ -321,7 +309,6 @@ public class SnapshotStatistics {
mUsed = Arrays.copyOf(orig.mUsed, orig.mUsed.length);
mTotalBuilds = orig.mTotalBuilds;
mTotalUsed = orig.mTotalUsed;
mTotalCorked = orig.mTotalCorked;
mBigBuilds = orig.mBigBuilds;
mShortLived = orig.mShortLived;
mTotalTimeUs = orig.mTotalTimeUs;
@@ -379,7 +366,6 @@ public class SnapshotStatistics {
* Dump the summary statistics record. Choose the header or the data.
* number of builds
* number of uses
* number of corks
* number of big builds
* number of short lifetimes
* cumulative build time, in seconds
@@ -388,13 +374,13 @@ public class SnapshotStatistics {
private void dumpStats(PrintWriter pw, String indent, long now, boolean header) {
dumpPrefix(pw, indent, now, header, "Summary stats");
if (header) {
pw.format(Locale.US, " %10s %10s %10s %10s %10s %10s %10s",
"TotBlds", "TotUsed", "TotCork", "BigBlds", "ShortLvd",
pw.format(Locale.US, " %10s %10s %10s %10s %10s %10s",
"TotBlds", "TotUsed", "BigBlds", "ShortLvd",
"TotTime", "MaxTime");
} else {
pw.format(Locale.US,
" %10d %10d %10d %10d %10d %10d %10d",
mTotalBuilds, mTotalUsed, mTotalCorked, mBigBuilds, mShortLived,
" %10d %10d %10d %10d %10d %10d",
mTotalBuilds, mTotalUsed, mBigBuilds, mShortLived,
mTotalTimeUs / 1000, mMaxBuildTimeUs / 1000);
}
pw.println();
@@ -558,16 +544,6 @@ public class SnapshotStatistics {
}
}
/**
* Record a corked snapshot request.
*/
public final void corked() {
synchronized (mLock) {
mShort[0].corked();
mLong[0].corked();
}
}
/**
* Roll a stats array. Shift the elements up an index and create a new element at
* index zero. The old element zero is completed with the specified time.
@@ -624,8 +600,7 @@ public class SnapshotStatistics {
* Dump the statistics. The format is compatible with the PackageManager dumpsys
* output.
*/
public void dump(PrintWriter pw, String indent, long now, int unrecorded,
int corkLevel, boolean brief) {
public void dump(PrintWriter pw, String indent, long now, int unrecorded, boolean brief) {
// Grab the raw statistics under lock, but print them outside of the lock.
Stats[] l;
Stats[] s;
@@ -635,8 +610,7 @@ public class SnapshotStatistics {
s = Arrays.copyOf(mShort, mShort.length);
s[0] = new Stats(s[0]);
}
pw.format(Locale.US, "%s Unrecorded-hits: %d Cork-level: %d", indent,
unrecorded, corkLevel);
pw.format(Locale.US, "%s Unrecorded-hits: %d", indent, unrecorded);
pw.println();
dump(pw, indent, now, l, s, "stats");
if (brief) {