aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/storage
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2019-11-30 03:38:13 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2019-12-08 01:09:24 +0100
commit42f0c7c9cb1c516603da6f89ae7072989bf4b984 (patch)
tree9ea227a86c49c7602d2cbdbdfc2070e1cbb69bb5 /org.eclipse.jgit/src/org/eclipse/jgit/storage
parent7554bdfad5be0eff0b95dcfcec11a2cb19883b18 (diff)
downloadjgit-42f0c7c9cb1c516603da6f89ae7072989bf4b984.tar.gz
jgit-42f0c7c9cb1c516603da6f89ae7072989bf4b984.zip
Enhance WindowCache statistics
Add the following statistics - cache hit count and hit ratio - cache miss count and miss ratio - count of successful and failed loads - rate of failed loads - load, eviction and request count - average and total load time Use LongAdder instead of AtomicLong to implement counters in order to improve scalability. Optionally expose these metrics via JMX, they are registered with the platform MBean server if the config option jmx.WindowCacheStats = true in the user or system level git config. Bug: 553573 Change-Id: Ia2d5246ef69b9c2bd594a23934424bc5800774aa Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/storage')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCacheStats.java176
1 files changed, 170 insertions, 6 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCacheStats.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCacheStats.java
index 3570733e41..b7f6394df6 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCacheStats.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCacheStats.java
@@ -40,29 +40,193 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
package org.eclipse.jgit.storage.file;
+import javax.management.MXBean;
+
import org.eclipse.jgit.internal.storage.file.WindowCache;
/**
- * Accessor for stats about {@link WindowCache}.
+ * Cache statistics for {@link WindowCache}.
*
* @since 4.11
- *
*/
-public class WindowCacheStats {
+@MXBean
+public interface WindowCacheStats {
/**
* @return the number of open files.
+ * @deprecated use {@link #getOpenFileCount()} instead
*/
+ @Deprecated
public static int getOpenFiles() {
- return WindowCache.getInstance().getOpenFiles();
+ return (int) WindowCache.getInstance().getStats().getOpenFileCount();
}
/**
* @return the number of open bytes.
+ * @deprecated use {@link #getOpenByteCount()} instead
*/
+ @Deprecated
public static long getOpenBytes() {
- return WindowCache.getInstance().getOpenBytes();
+ return WindowCache.getInstance().getStats().getOpenByteCount();
+ }
+
+ /**
+ * @return cache statistics for the WindowCache
+ * @since 5.1.13
+ */
+ public static WindowCacheStats getStats() {
+ return WindowCache.getInstance().getStats();
+ }
+
+ /**
+ * Number of cache hits
+ *
+ * @return number of cache hits
+ */
+ long getHitCount();
+
+ /**
+ * Ratio of cache requests which were hits defined as
+ * {@code hitCount / requestCount}, or {@code 1.0} when
+ * {@code requestCount == 0}. Note that {@code hitRate + missRate =~ 1.0}.
+ *
+ * @return the ratio of cache requests which were hits
+ */
+ default double getHitRatio() {
+ long requestCount = getRequestCount();
+ return (requestCount == 0) ? 1.0
+ : (double) getHitCount() / requestCount;
+ }
+
+ /**
+ * Number of cache misses.
+ *
+ * @return number of cash misses
+ */
+ long getMissCount();
+
+ /**
+ * Ratio of cache requests which were misses defined as
+ * {@code missCount / requestCount}, or {@code 0.0} when
+ * {@code requestCount == 0}. Note that {@code hitRate + missRate =~ 1.0}.
+ * Cache misses include all requests which weren't cache hits, including
+ * requests which resulted in either successful or failed loading attempts.
+ *
+ * @return the ratio of cache requests which were misses
+ */
+ default double getMissRatio() {
+ long requestCount = getRequestCount();
+ return (requestCount == 0) ? 0.0
+ : (double) getMissCount() / requestCount;
+ }
+
+ /**
+ * Number of successful loads
+ *
+ * @return number of successful loads
+ */
+ long getLoadSuccessCount();
+
+ /**
+ * Number of failed loads
+ *
+ * @return number of failed loads
+ */
+ long getLoadFailureCount();
+
+ /**
+ * Ratio of cache load attempts which threw exceptions. This is defined as
+ * {@code loadFailureCount / (loadSuccessCount + loadFailureCount)}, or
+ * {@code 0.0} when {@code loadSuccessCount + loadFailureCount == 0}.
+ *
+ * @return the ratio of cache loading attempts which threw exceptions
+ */
+ default double getLoadFailureRatio() {
+ long loadFailureCount = getLoadFailureCount();
+ long totalLoadCount = getLoadSuccessCount() + loadFailureCount;
+ return (totalLoadCount == 0) ? 0.0
+ : (double) loadFailureCount / totalLoadCount;
}
+
+ /**
+ * Total number of times that the cache attempted to load new values. This
+ * includes both successful load operations, as well as failed loads. This
+ * is defined as {@code loadSuccessCount + loadFailureCount}.
+ *
+ * @return the {@code loadSuccessCount + loadFailureCount}
+ */
+ default long getLoadCount() {
+ return getLoadSuccessCount() + getLoadFailureCount();
+ }
+
+ /**
+ * Number of cache evictions
+ *
+ * @return number of evictions
+ */
+ long getEvictionCount();
+
+ /**
+ * Ratio of cache evictions. This is defined as
+ * {@code evictionCount / requestCount}, or {@code 0.0} when
+ * {@code requestCount == 0}.
+ *
+ * @return the ratio of cache loading attempts which threw exceptions
+ */
+ default double getEvictionRatio() {
+ long evictionCount = getEvictionCount();
+ long requestCount = getRequestCount();
+ return (requestCount == 0) ? 0.0
+ : (double) evictionCount / requestCount;
+ }
+
+ /**
+ * Number of times the cache returned either a cached or uncached value.
+ * This is defined as {@code hitCount + missCount}.
+ *
+ * @return the {@code hitCount + missCount}
+ */
+ default long getRequestCount() {
+ return getHitCount() + getMissCount();
+ }
+
+ /**
+ * Average time in nanoseconds for loading new values. This is
+ * {@code totalLoadTime / (loadSuccessCount + loadFailureCount)}.
+ *
+ * @return the average time spent loading new values
+ */
+ default double getAverageLoadTime() {
+ long totalLoadCount = getLoadSuccessCount() + getLoadFailureCount();
+ return (totalLoadCount == 0) ? 0.0
+ : (double) getTotalLoadTime() / totalLoadCount;
+ }
+
+ /**
+ * Total time in nanoseconds the cache spent loading new values.
+ *
+ * @return the total number of nanoseconds the cache has spent loading new
+ * values
+ */
+ long getTotalLoadTime();
+
+ /**
+ * Number of pack files kept open by the cache
+ *
+ * @return number of files kept open by cache
+ */
+ long getOpenFileCount();
+
+ /**
+ * Number of bytes cached
+ *
+ * @return number of bytes cached
+ */
+ long getOpenByteCount();
+
+ /**
+ * Reset counters. Does not reset open bytes and open files counters.
+ */
+ void resetCounters();
}