Loading core/java/android/app/PropertyInvalidatedCache.java +44 −25 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import com.android.internal.util.FastPrintWriter; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.io.ByteArrayOutputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintWriter; Loading Loading @@ -1444,7 +1445,6 @@ public class PropertyInvalidatedCache<Query, Result> { mCache.size(), mMaxEntries, mHighWaterMark, mMissOverflow)); pw.println(TextUtils.formatSimple(" Enabled: %s", mDisabled ? "false" : "true")); pw.println(""); pw.flush(); // No specific cache was requested. This is the default, and no details // should be dumped. Loading @@ -1463,7 +1463,6 @@ public class PropertyInvalidatedCache<Query, Result> { pw.println(TextUtils.formatSimple(" Key: %s\n Value: %s\n", key, value)); } pw.flush(); } } Loading @@ -1488,13 +1487,8 @@ public class PropertyInvalidatedCache<Query, Result> { * provided ParcelFileDescriptor. Optional switches allow the caller to choose * specific caches (selection is by cache name or property name); if these switches * are used then the output includes both cache statistics and cache entries. * @hide */ public static void dumpCacheInfo(@NonNull ParcelFileDescriptor pfd, @NonNull String[] args) { try ( FileOutputStream fout = new FileOutputStream(pfd.getFileDescriptor()); PrintWriter pw = new FastPrintWriter(fout); ) { private static void dumpCacheInfo(@NonNull PrintWriter pw, @NonNull String[] args) { if (!sEnabled) { pw.println(" Caching is disabled in this process."); return; Loading @@ -1516,6 +1510,31 @@ public class PropertyInvalidatedCache<Query, Result> { PropertyInvalidatedCache currentCache = activeCaches.get(i); currentCache.dumpContents(pw, detail, args); } } /** * Without arguments, this dumps statistics from every cache in the process to the * provided ParcelFileDescriptor. Optional switches allow the caller to choose * specific caches (selection is by cache name or property name); if these switches * are used then the output includes both cache statistics and cache entries. * @hide */ public static void dumpCacheInfo(@NonNull ParcelFileDescriptor pfd, @NonNull String[] args) { // Create a PrintWriter that uses a byte array. The code can safely write to // this array without fear of blocking. The completed byte array will be sent // to the caller after all the data has been collected and all locks have been // released. ByteArrayOutputStream barray = new ByteArrayOutputStream(); PrintWriter bout = new PrintWriter(barray); dumpCacheInfo(bout, args); bout.close(); try { // Send the final byte array to the output. This happens outside of all locks. var out = new FileOutputStream(pfd.getFileDescriptor()); barray.writeTo(out); out.close(); barray.close(); } catch (IOException e) { Log.e(TAG, "Failed to dump PropertyInvalidatedCache instances"); } Loading Loading
core/java/android/app/PropertyInvalidatedCache.java +44 −25 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import com.android.internal.util.FastPrintWriter; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.io.ByteArrayOutputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintWriter; Loading Loading @@ -1444,7 +1445,6 @@ public class PropertyInvalidatedCache<Query, Result> { mCache.size(), mMaxEntries, mHighWaterMark, mMissOverflow)); pw.println(TextUtils.formatSimple(" Enabled: %s", mDisabled ? "false" : "true")); pw.println(""); pw.flush(); // No specific cache was requested. This is the default, and no details // should be dumped. Loading @@ -1463,7 +1463,6 @@ public class PropertyInvalidatedCache<Query, Result> { pw.println(TextUtils.formatSimple(" Key: %s\n Value: %s\n", key, value)); } pw.flush(); } } Loading @@ -1488,13 +1487,8 @@ public class PropertyInvalidatedCache<Query, Result> { * provided ParcelFileDescriptor. Optional switches allow the caller to choose * specific caches (selection is by cache name or property name); if these switches * are used then the output includes both cache statistics and cache entries. * @hide */ public static void dumpCacheInfo(@NonNull ParcelFileDescriptor pfd, @NonNull String[] args) { try ( FileOutputStream fout = new FileOutputStream(pfd.getFileDescriptor()); PrintWriter pw = new FastPrintWriter(fout); ) { private static void dumpCacheInfo(@NonNull PrintWriter pw, @NonNull String[] args) { if (!sEnabled) { pw.println(" Caching is disabled in this process."); return; Loading @@ -1516,6 +1510,31 @@ public class PropertyInvalidatedCache<Query, Result> { PropertyInvalidatedCache currentCache = activeCaches.get(i); currentCache.dumpContents(pw, detail, args); } } /** * Without arguments, this dumps statistics from every cache in the process to the * provided ParcelFileDescriptor. Optional switches allow the caller to choose * specific caches (selection is by cache name or property name); if these switches * are used then the output includes both cache statistics and cache entries. * @hide */ public static void dumpCacheInfo(@NonNull ParcelFileDescriptor pfd, @NonNull String[] args) { // Create a PrintWriter that uses a byte array. The code can safely write to // this array without fear of blocking. The completed byte array will be sent // to the caller after all the data has been collected and all locks have been // released. ByteArrayOutputStream barray = new ByteArrayOutputStream(); PrintWriter bout = new PrintWriter(barray); dumpCacheInfo(bout, args); bout.close(); try { // Send the final byte array to the output. This happens outside of all locks. var out = new FileOutputStream(pfd.getFileDescriptor()); barray.writeTo(out); out.close(); barray.close(); } catch (IOException e) { Log.e(TAG, "Failed to dump PropertyInvalidatedCache instances"); } Loading