Merge "Reduce pss collection amount, improve logging."

This commit is contained in:
TreeHugger Robot
2018-01-29 16:52:08 +00:00
committed by Android (Google) Code Review
39 changed files with 556 additions and 302 deletions

View File

@@ -116,6 +116,8 @@ public final class Debug
/** The proportional set size that is swappable for dalvik heap. */
/** @hide We may want to expose this, eventually. */
public int dalvikSwappablePss;
/** @hide The resident set size for dalvik heap. (Without other Dalvik overhead.) */
public int dalvikRss;
/** The private dirty pages used by dalvik heap. */
public int dalvikPrivateDirty;
/** The shared dirty pages used by dalvik heap. */
@@ -138,6 +140,8 @@ public final class Debug
/** The proportional set size that is swappable for the native heap. */
/** @hide We may want to expose this, eventually. */
public int nativeSwappablePss;
/** @hide The resident set size for the native heap. */
public int nativeRss;
/** The private dirty pages used by the native heap. */
public int nativePrivateDirty;
/** The shared dirty pages used by the native heap. */
@@ -160,6 +164,8 @@ public final class Debug
/** The proportional set size that is swappable for everything else. */
/** @hide We may want to expose this, eventually. */
public int otherSwappablePss;
/** @hide The resident set size for everything else. */
public int otherRss;
/** The private dirty pages used by everything else. */
public int otherPrivateDirty;
/** The shared dirty pages used by everything else. */
@@ -288,24 +294,26 @@ public final class Debug
public static final int NUM_DVK_STATS = 14;
/** @hide */
public static final int NUM_CATEGORIES = 8;
public static final int NUM_CATEGORIES = 9;
/** @hide */
public static final int offsetPss = 0;
public static final int OFFSET_PSS = 0;
/** @hide */
public static final int offsetSwappablePss = 1;
public static final int OFFSET_SWAPPABLE_PSS = 1;
/** @hide */
public static final int offsetPrivateDirty = 2;
public static final int OFFSET_RSS = 2;
/** @hide */
public static final int offsetSharedDirty = 3;
public static final int OFFSET_PRIVATE_DIRTY = 3;
/** @hide */
public static final int offsetPrivateClean = 4;
public static final int OFFSET_SHARED_DIRTY = 4;
/** @hide */
public static final int offsetSharedClean = 5;
public static final int OFFSET_PRIVATE_CLEAN = 5;
/** @hide */
public static final int offsetSwappedOut = 6;
public static final int OFFSET_SHARED_CLEAN = 6;
/** @hide */
public static final int offsetSwappedOutPss = 7;
public static final int OFFSET_SWAPPED_OUT = 7;
/** @hide */
public static final int OFFSET_SWAPPED_OUT_PSS = 8;
private int[] otherStats = new int[(NUM_OTHER_STATS+NUM_DVK_STATS)*NUM_CATEGORIES];
@@ -336,6 +344,13 @@ public final class Debug
return dalvikSwappablePss + nativeSwappablePss + otherSwappablePss;
}
/**
* @hide Return total RSS memory usage in kB.
*/
public int getTotalRss() {
return dalvikRss + nativeRss + otherRss;
}
/**
* Return total private dirty memory usage in kB.
*/
@@ -382,29 +397,32 @@ public final class Debug
/** @hide */
public int getOtherPss(int which) {
return otherStats[which*NUM_CATEGORIES + offsetPss];
return otherStats[which * NUM_CATEGORIES + OFFSET_PSS];
}
/** @hide */
public int getOtherSwappablePss(int which) {
return otherStats[which*NUM_CATEGORIES + offsetSwappablePss];
return otherStats[which * NUM_CATEGORIES + OFFSET_SWAPPABLE_PSS];
}
/** @hide */
public int getOtherRss(int which) {
return otherStats[which * NUM_CATEGORIES + OFFSET_RSS];
}
/** @hide */
public int getOtherPrivateDirty(int which) {
return otherStats[which*NUM_CATEGORIES + offsetPrivateDirty];
return otherStats[which * NUM_CATEGORIES + OFFSET_PRIVATE_DIRTY];
}
/** @hide */
public int getOtherSharedDirty(int which) {
return otherStats[which*NUM_CATEGORIES + offsetSharedDirty];
return otherStats[which * NUM_CATEGORIES + OFFSET_SHARED_DIRTY];
}
/** @hide */
public int getOtherPrivateClean(int which) {
return otherStats[which*NUM_CATEGORIES + offsetPrivateClean];
return otherStats[which * NUM_CATEGORIES + OFFSET_PRIVATE_CLEAN];
}
/** @hide */
@@ -414,17 +432,17 @@ public final class Debug
/** @hide */
public int getOtherSharedClean(int which) {
return otherStats[which*NUM_CATEGORIES + offsetSharedClean];
return otherStats[which * NUM_CATEGORIES + OFFSET_SHARED_CLEAN];
}
/** @hide */
public int getOtherSwappedOut(int which) {
return otherStats[which*NUM_CATEGORIES + offsetSwappedOut];
return otherStats[which * NUM_CATEGORIES + OFFSET_SWAPPED_OUT];
}
/** @hide */
public int getOtherSwappedOutPss(int which) {
return otherStats[which*NUM_CATEGORIES + offsetSwappedOutPss];
return otherStats[which * NUM_CATEGORIES + OFFSET_SWAPPED_OUT_PSS];
}
/** @hide */
@@ -741,6 +759,7 @@ public final class Debug
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(dalvikPss);
dest.writeInt(dalvikSwappablePss);
dest.writeInt(dalvikRss);
dest.writeInt(dalvikPrivateDirty);
dest.writeInt(dalvikSharedDirty);
dest.writeInt(dalvikPrivateClean);
@@ -749,6 +768,7 @@ public final class Debug
dest.writeInt(dalvikSwappedOutPss);
dest.writeInt(nativePss);
dest.writeInt(nativeSwappablePss);
dest.writeInt(nativeRss);
dest.writeInt(nativePrivateDirty);
dest.writeInt(nativeSharedDirty);
dest.writeInt(nativePrivateClean);
@@ -757,6 +777,7 @@ public final class Debug
dest.writeInt(nativeSwappedOutPss);
dest.writeInt(otherPss);
dest.writeInt(otherSwappablePss);
dest.writeInt(otherRss);
dest.writeInt(otherPrivateDirty);
dest.writeInt(otherSharedDirty);
dest.writeInt(otherPrivateClean);
@@ -770,6 +791,7 @@ public final class Debug
public void readFromParcel(Parcel source) {
dalvikPss = source.readInt();
dalvikSwappablePss = source.readInt();
dalvikRss = source.readInt();
dalvikPrivateDirty = source.readInt();
dalvikSharedDirty = source.readInt();
dalvikPrivateClean = source.readInt();
@@ -778,6 +800,7 @@ public final class Debug
dalvikSwappedOutPss = source.readInt();
nativePss = source.readInt();
nativeSwappablePss = source.readInt();
nativeRss = source.readInt();
nativePrivateDirty = source.readInt();
nativeSharedDirty = source.readInt();
nativePrivateClean = source.readInt();
@@ -786,6 +809,7 @@ public final class Debug
nativeSwappedOutPss = source.readInt();
otherPss = source.readInt();
otherSwappablePss = source.readInt();
otherRss = source.readInt();
otherPrivateDirty = source.readInt();
otherSharedDirty = source.readInt();
otherPrivateClean = source.readInt();

View File

@@ -17,6 +17,7 @@
package android.util;
import android.os.FileUtils;
import android.os.SystemClock;
import libcore.io.IoUtils;
@@ -47,14 +48,25 @@ import java.util.function.Consumer;
public class AtomicFile {
private final File mBaseName;
private final File mBackupName;
private final String mCommitTag;
private long mStartTime;
/**
* Create a new AtomicFile for a file located at the given File path.
* The secondary backup file will be the same file path with ".bak" appended.
*/
public AtomicFile(File baseName) {
this(baseName, null);
}
/**
* @hide Internal constructor that also allows you to have the class
* automatically log commit events.
*/
public AtomicFile(File baseName, String commitTag) {
mBaseName = baseName;
mBackupName = new File(baseName.getPath() + ".bak");
mCommitTag = commitTag;
}
/**
@@ -88,6 +100,18 @@ public class AtomicFile {
* access to AtomicFile.
*/
public FileOutputStream startWrite() throws IOException {
return startWrite(mCommitTag != null ? SystemClock.uptimeMillis() : 0);
}
/**
* @hide Internal version of {@link #startWrite()} that allows you to specify an earlier
* start time of the operation to adjust how the commit is logged.
* @param startTime The effective start time of the operation, in the time
* base of {@link SystemClock#uptimeMillis()}.
*/
public FileOutputStream startWrite(long startTime) throws IOException {
mStartTime = startTime;
// Rename the current file so it may be used as a backup during the next read
if (mBaseName.exists()) {
if (!mBackupName.exists()) {
@@ -135,6 +159,10 @@ public class AtomicFile {
} catch (IOException e) {
Log.w("AtomicFile", "finishWrite: Got exception:", e);
}
if (mCommitTag != null) {
com.android.internal.logging.EventLogTags.writeCommitSysConfigFile(
mCommitTag, SystemClock.uptimeMillis() - mStartTime);
}
}
}