View Javadoc
1   /*
2    * Copyright (C) 2018, David Pursehouse <david.pursehouse@gmail.com> and others
3    *
4    * This program and the accompanying materials are made available under the
5    * terms of the Eclipse Distribution License v. 1.0 which is available at
6    * https://www.eclipse.org/org/documents/edl-v10.php.
7    *
8    * SPDX-License-Identifier: BSD-3-Clause
9    */
10  package org.eclipse.jgit.storage.file;
11  
12  import java.util.Map;
13  
14  import javax.management.MXBean;
15  
16  import org.eclipse.jgit.internal.storage.file.WindowCache;
17  
18  /**
19   * Cache statistics for {@link WindowCache}.
20   *
21   * @since 4.11
22   */
23  @MXBean
24  public interface WindowCacheStats {
25  	/**
26  	 * @return the number of open files.
27  	 * @deprecated use {@link #getOpenFileCount()} instead
28  	 */
29  	@Deprecated
30  	public static int getOpenFiles() {
31  		return (int) WindowCache.getInstance().getStats().getOpenFileCount();
32  	}
33  
34  	/**
35  	 * @return the number of open bytes.
36  	 * @deprecated use {@link #getOpenByteCount()} instead
37  	 */
38  	@Deprecated
39  	public static long getOpenBytes() {
40  		return WindowCache.getInstance().getStats().getOpenByteCount();
41  	}
42  
43  	/**
44  	 * @return cache statistics for the WindowCache
45  	 * @since 5.1.13
46  	 */
47  	public static WindowCacheStats getStats() {
48  		return WindowCache.getInstance().getStats();
49  	}
50  
51  	/**
52  	 * Number of cache hits
53  	 *
54  	 * @return number of cache hits
55  	 */
56  	long getHitCount();
57  
58  	/**
59  	 * Ratio of cache requests which were hits defined as
60  	 * {@code hitCount / requestCount}, or {@code 1.0} when
61  	 * {@code requestCount == 0}. Note that {@code hitRate + missRate =~ 1.0}.
62  	 *
63  	 * @return the ratio of cache requests which were hits
64  	 */
65  	default double getHitRatio() {
66  		long requestCount = getRequestCount();
67  		return (requestCount == 0) ? 1.0
68  				: (double) getHitCount() / requestCount;
69  	}
70  
71  	/**
72  	 * Number of cache misses.
73  	 *
74  	 * @return number of cash misses
75  	 */
76  	long getMissCount();
77  
78  	/**
79  	 * Ratio of cache requests which were misses defined as
80  	 * {@code missCount / requestCount}, or {@code 0.0} when
81  	 * {@code requestCount == 0}. Note that {@code hitRate + missRate =~ 1.0}.
82  	 * Cache misses include all requests which weren't cache hits, including
83  	 * requests which resulted in either successful or failed loading attempts.
84  	 *
85  	 * @return the ratio of cache requests which were misses
86  	 */
87  	default double getMissRatio() {
88  		long requestCount = getRequestCount();
89  		return (requestCount == 0) ? 0.0
90  				: (double) getMissCount() / requestCount;
91  	}
92  
93  	/**
94  	 * Number of successful loads
95  	 *
96  	 * @return number of successful loads
97  	 */
98  	long getLoadSuccessCount();
99  
100 	/**
101 	 * Number of failed loads
102 	 *
103 	 * @return number of failed loads
104 	 */
105 	long getLoadFailureCount();
106 
107 	/**
108 	 * Ratio of cache load attempts which threw exceptions. This is defined as
109 	 * {@code loadFailureCount / (loadSuccessCount + loadFailureCount)}, or
110 	 * {@code 0.0} when {@code loadSuccessCount + loadFailureCount == 0}.
111 	 *
112 	 * @return the ratio of cache loading attempts which threw exceptions
113 	 */
114 	default double getLoadFailureRatio() {
115 		long loadFailureCount = getLoadFailureCount();
116 		long totalLoadCount = getLoadSuccessCount() + loadFailureCount;
117 		return (totalLoadCount == 0) ? 0.0
118 				: (double) loadFailureCount / totalLoadCount;
119 	}
120 
121 	/**
122 	 * Total number of times that the cache attempted to load new values. This
123 	 * includes both successful load operations, as well as failed loads. This
124 	 * is defined as {@code loadSuccessCount + loadFailureCount}.
125 	 *
126 	 * @return the {@code loadSuccessCount + loadFailureCount}
127 	 */
128 	default long getLoadCount() {
129 		return getLoadSuccessCount() + getLoadFailureCount();
130 	}
131 
132 	/**
133 	 * Number of cache evictions
134 	 *
135 	 * @return number of evictions
136 	 */
137 	long getEvictionCount();
138 
139 	/**
140 	 * Ratio of cache evictions. This is defined as
141 	 * {@code evictionCount / requestCount}, or {@code 0.0} when
142 	 * {@code requestCount == 0}.
143 	 *
144 	 * @return the ratio of cache loading attempts which threw exceptions
145 	 */
146 	default double getEvictionRatio() {
147 		long evictionCount = getEvictionCount();
148 		long requestCount = getRequestCount();
149 		return (requestCount == 0) ? 0.0
150 				: (double) evictionCount / requestCount;
151 	}
152 
153 	/**
154 	 * Number of times the cache returned either a cached or uncached value.
155 	 * This is defined as {@code hitCount + missCount}.
156 	 *
157 	 * @return the {@code hitCount + missCount}
158 	 */
159 	default long getRequestCount() {
160 		return getHitCount() + getMissCount();
161 	}
162 
163 	/**
164 	 * Average time in nanoseconds for loading new values. This is
165 	 * {@code totalLoadTime / (loadSuccessCount + loadFailureCount)}.
166 	 *
167 	 * @return the average time spent loading new values
168 	 */
169 	default double getAverageLoadTime() {
170 		long totalLoadCount = getLoadSuccessCount() + getLoadFailureCount();
171 		return (totalLoadCount == 0) ? 0.0
172 				: (double) getTotalLoadTime() / totalLoadCount;
173 	}
174 
175 	/**
176 	 * Total time in nanoseconds the cache spent loading new values.
177 	 *
178 	 * @return the total number of nanoseconds the cache has spent loading new
179 	 *         values
180 	 */
181 	long getTotalLoadTime();
182 
183 	/**
184 	 * Number of pack files kept open by the cache
185 	 *
186 	 * @return number of files kept open by cache
187 	 */
188 	long getOpenFileCount();
189 
190 	/**
191 	 * Number of bytes cached
192 	 *
193 	 * @return number of bytes cached
194 	 */
195 	long getOpenByteCount();
196 
197 	/**
198 	 * Number of bytes cached per repository
199 	 *
200 	 * @return number of bytes cached per repository
201 	 */
202 	Map<String, Long> getOpenByteCountPerRepository();
203 
204 	/**
205 	 * Reset counters. Does not reset open bytes and open files counters.
206 	 */
207 	void resetCounters();
208 }