Loading core/java/android/app/PropertyInvalidatedCache.java +25 −0 Original line number Original line Diff line number Diff line Loading @@ -188,6 +188,17 @@ public abstract class PropertyInvalidatedCache<Query, Result> { private static final boolean DEBUG = false; private static final boolean DEBUG = false; private static final boolean VERIFY = false; private static final boolean VERIFY = false; // Per-Cache performance counters. As some cache instances are declared static, @GuardedBy("mLock") private long mHits = 0; @GuardedBy("mLock") private long mMisses = 0; // Most invalidation is done in a static context, so the counters need to be accessible. @GuardedBy("sCorkLock") private static final HashMap<String, Long> sInvalidates = new HashMap<>(); /** /** * If sEnabled is false then all cache operations are stubbed out. Set * If sEnabled is false then all cache operations are stubbed out. Set * it to false inside test processes. * it to false inside test processes. Loading Loading @@ -265,6 +276,7 @@ public abstract class PropertyInvalidatedCache<Query, Result> { }; }; synchronized (sCorkLock) { synchronized (sCorkLock) { sCaches.put(this, null); sCaches.put(this, null); sInvalidates.put(propertyName, (long) 0); } } } } Loading Loading @@ -365,6 +377,8 @@ public abstract class PropertyInvalidatedCache<Query, Result> { synchronized (mLock) { synchronized (mLock) { if (currentNonce == mLastSeenNonce) { if (currentNonce == mLastSeenNonce) { cachedResult = mCache.get(query); cachedResult = mCache.get(query); if (cachedResult != null) mHits++; } else { } else { if (DEBUG) { if (DEBUG) { Log.d(TAG, Log.d(TAG, Loading Loading @@ -428,6 +442,7 @@ public abstract class PropertyInvalidatedCache<Query, Result> { if (mLastSeenNonce == currentNonce && result != null) { if (mLastSeenNonce == currentNonce && result != null) { mCache.put(query, result); mCache.put(query, result); } } mMisses++; } } return maybeCheckConsistency(query, result); return maybeCheckConsistency(query, result); } } Loading Loading @@ -531,6 +546,8 @@ public abstract class PropertyInvalidatedCache<Query, Result> { newValueString)); newValueString)); } } SystemProperties.set(name, newValueString); SystemProperties.set(name, newValueString); long invalidateCount = sInvalidates.getOrDefault(name, (long) 0); sInvalidates.put(name, ++invalidateCount); } } /** /** Loading Loading @@ -758,8 +775,16 @@ public abstract class PropertyInvalidatedCache<Query, Result> { } } private void dumpContents(PrintWriter pw, String[] args) { private void dumpContents(PrintWriter pw, String[] args) { long invalidateCount; synchronized (sCorkLock) { invalidateCount = sInvalidates.getOrDefault(mPropertyName, (long) 0); } synchronized (mLock) { synchronized (mLock) { pw.println(String.format(" Cache Property Name: %s", cacheName())); pw.println(String.format(" Cache Property Name: %s", cacheName())); pw.println(String.format(" Hits: %d, Misses: %d, Invalidates: %d", mHits, mMisses, invalidateCount)); pw.println(String.format(" Last Observed Nonce: %d", mLastSeenNonce)); pw.println(String.format(" Last Observed Nonce: %d", mLastSeenNonce)); pw.println(String.format(" Current Size: %d, Max Size: %d", pw.println(String.format(" Current Size: %d, Max Size: %d", mCache.entrySet().size(), mMaxEntries)); mCache.entrySet().size(), mMaxEntries)); Loading Loading
core/java/android/app/PropertyInvalidatedCache.java +25 −0 Original line number Original line Diff line number Diff line Loading @@ -188,6 +188,17 @@ public abstract class PropertyInvalidatedCache<Query, Result> { private static final boolean DEBUG = false; private static final boolean DEBUG = false; private static final boolean VERIFY = false; private static final boolean VERIFY = false; // Per-Cache performance counters. As some cache instances are declared static, @GuardedBy("mLock") private long mHits = 0; @GuardedBy("mLock") private long mMisses = 0; // Most invalidation is done in a static context, so the counters need to be accessible. @GuardedBy("sCorkLock") private static final HashMap<String, Long> sInvalidates = new HashMap<>(); /** /** * If sEnabled is false then all cache operations are stubbed out. Set * If sEnabled is false then all cache operations are stubbed out. Set * it to false inside test processes. * it to false inside test processes. Loading Loading @@ -265,6 +276,7 @@ public abstract class PropertyInvalidatedCache<Query, Result> { }; }; synchronized (sCorkLock) { synchronized (sCorkLock) { sCaches.put(this, null); sCaches.put(this, null); sInvalidates.put(propertyName, (long) 0); } } } } Loading Loading @@ -365,6 +377,8 @@ public abstract class PropertyInvalidatedCache<Query, Result> { synchronized (mLock) { synchronized (mLock) { if (currentNonce == mLastSeenNonce) { if (currentNonce == mLastSeenNonce) { cachedResult = mCache.get(query); cachedResult = mCache.get(query); if (cachedResult != null) mHits++; } else { } else { if (DEBUG) { if (DEBUG) { Log.d(TAG, Log.d(TAG, Loading Loading @@ -428,6 +442,7 @@ public abstract class PropertyInvalidatedCache<Query, Result> { if (mLastSeenNonce == currentNonce && result != null) { if (mLastSeenNonce == currentNonce && result != null) { mCache.put(query, result); mCache.put(query, result); } } mMisses++; } } return maybeCheckConsistency(query, result); return maybeCheckConsistency(query, result); } } Loading Loading @@ -531,6 +546,8 @@ public abstract class PropertyInvalidatedCache<Query, Result> { newValueString)); newValueString)); } } SystemProperties.set(name, newValueString); SystemProperties.set(name, newValueString); long invalidateCount = sInvalidates.getOrDefault(name, (long) 0); sInvalidates.put(name, ++invalidateCount); } } /** /** Loading Loading @@ -758,8 +775,16 @@ public abstract class PropertyInvalidatedCache<Query, Result> { } } private void dumpContents(PrintWriter pw, String[] args) { private void dumpContents(PrintWriter pw, String[] args) { long invalidateCount; synchronized (sCorkLock) { invalidateCount = sInvalidates.getOrDefault(mPropertyName, (long) 0); } synchronized (mLock) { synchronized (mLock) { pw.println(String.format(" Cache Property Name: %s", cacheName())); pw.println(String.format(" Cache Property Name: %s", cacheName())); pw.println(String.format(" Hits: %d, Misses: %d, Invalidates: %d", mHits, mMisses, invalidateCount)); pw.println(String.format(" Last Observed Nonce: %d", mLastSeenNonce)); pw.println(String.format(" Last Observed Nonce: %d", mLastSeenNonce)); pw.println(String.format(" Current Size: %d, Max Size: %d", pw.println(String.format(" Current Size: %d, Max Size: %d", mCache.entrySet().size(), mMaxEntries)); mCache.entrySet().size(), mMaxEntries)); Loading