Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2160532a authored by Collin Fijalkovich's avatar Collin Fijalkovich Committed by Automerger Merge Worker
Browse files

Merge "Add performance counters to cacheinfo dumps." into rvc-dev am: 4edffac7 am: 23e5f201

Change-Id: Ic3c062e346d615a7523589938f1c98764edd0169
parents c5cfb4f4 23e5f201
Loading
Loading
Loading
Loading
+25 −0
Original line number Original line Diff line number Diff line
@@ -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.
@@ -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);
        }
        }
    }
    }


@@ -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,
@@ -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);
        }
        }
@@ -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);
    }
    }


    /**
    /**
@@ -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));