summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Lee Shombert <shombert@google.com> 2020-01-24 16:04:00 -0800
committer Lee Shombert <shombert@google.com> 2020-01-30 10:53:16 -0800
commit2f529c13accbb595d7dd9b4722439993ecdb56ff (patch)
tree121b625e2ef42f1083689c23e066444aee18a18a
parentbe1592efdae30869e318b7df9643b9bab5ed758e (diff)
Enhance PropertyInvalidatedCache debug
Bug: 140788621 Add the cache name to most debug messages. The cache name defaults to the property name but can be overridden. Overriding the cache name makes the most sense when multiple caches share a single proprerty. This function is only called from inside debug log messages. Wrap the default invocation of Query.toString() with a cache instance method that can be overridden. A cache that uses a simple type (like Integer) for its Query to provide nicely formatted query strings in the debug logs. This function is only called from inside debug log messages. Test: Created a test build using the hasSystemFeature() binder cache, overriding cache name and the object query string. Change-Id: If379ac3e8494e9fef0ff9f5cc5ca0412d02e5502
-rw-r--r--core/java/android/app/PropertyInvalidatedCache.java34
1 files changed, 27 insertions, 7 deletions
diff --git a/core/java/android/app/PropertyInvalidatedCache.java b/core/java/android/app/PropertyInvalidatedCache.java
index 736efb6a5e69..cbd2f1a52c0c 100644
--- a/core/java/android/app/PropertyInvalidatedCache.java
+++ b/core/java/android/app/PropertyInvalidatedCache.java
@@ -297,9 +297,10 @@ public abstract class PropertyInvalidatedCache<Query, Result> {
if (currentNonce == NONCE_DISABLED || currentNonce == NONCE_UNSET) {
if (DEBUG) {
Log.d(TAG,
- String.format("cache %s for %s",
+ String.format("cache %s %s for %s",
+ cacheName(),
currentNonce == NONCE_DISABLED ? "disabled" : "unset",
- query));
+ queryToString(query)));
}
return recompute(query);
}
@@ -310,7 +311,8 @@ public abstract class PropertyInvalidatedCache<Query, Result> {
} else {
if (DEBUG) {
Log.d(TAG,
- String.format("clearing cache because nonce changed [%s] -> [%s]",
+ String.format("clearing cache %s because nonce changed [%s] -> [%s]",
+ cacheName(),
mLastSeenNonce, currentNonce));
}
mCache.clear();
@@ -328,13 +330,15 @@ public abstract class PropertyInvalidatedCache<Query, Result> {
final Result refreshedResult = refresh(cachedResult, query);
if (refreshedResult != cachedResult) {
if (DEBUG) {
- Log.d(TAG, "cache refresh for " + query);
+ Log.d(TAG, "cache refresh for " + cacheName() + " " + queryToString(query));
}
final long afterRefreshNonce = getCurrentNonce();
if (currentNonce != afterRefreshNonce) {
currentNonce = afterRefreshNonce;
if (DEBUG) {
- Log.d(TAG, "restarting query because nonce changed in refresh");
+ Log.d(TAG, String.format("restarting %s %s because nonce changed in refresh",
+ cacheName(),
+ queryToString(query)));
}
continue;
}
@@ -352,13 +356,13 @@ public abstract class PropertyInvalidatedCache<Query, Result> {
return maybeCheckConsistency(query, refreshedResult);
}
if (DEBUG) {
- Log.d(TAG, "cache hit for " + query);
+ Log.d(TAG, "cache hit for " + cacheName() + " " + queryToString(query));
}
return maybeCheckConsistency(query, cachedResult);
}
// Cache miss: make the value from scratch.
if (DEBUG) {
- Log.d(TAG, "cache miss for " + query);
+ Log.d(TAG, "cache miss for " + cacheName() + " " + queryToString(query));
}
final Result result = recompute(query);
synchronized (mLock) {
@@ -451,4 +455,20 @@ public abstract class PropertyInvalidatedCache<Query, Result> {
}
return proposedResult;
}
+
+ /**
+ * Return the name of the cache, to be used in debug messages. The
+ * method is public so clients can use it.
+ */
+ public String cacheName() {
+ return mPropertyName;
+ }
+
+ /**
+ * Return the query as a string, to be used in debug messages. The
+ * method is public so clients can use it in external debug messages.
+ */
+ public String queryToString(Query query) {
+ return Objects.toString(query);
+ }
}