You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WindowCacheStats.java 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * Copyright (C) 2018, David Pursehouse <david.pursehouse@gmail.com>
  3. * and other copyright owners as documented in the project's IP log.
  4. *
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Distribution License v1.0 which
  7. * accompanies this distribution, is reproduced below, and is
  8. * available at http://www.eclipse.org/org/documents/edl-v10.php
  9. *
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials provided
  22. * with the distribution.
  23. *
  24. * - Neither the name of the Eclipse Foundation, Inc. nor the
  25. * names of its contributors may be used to endorse or promote
  26. * products derived from this software without specific prior
  27. * written permission.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  30. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  31. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  35. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  36. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  37. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  38. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  41. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42. */
  43. package org.eclipse.jgit.storage.file;
  44. import javax.management.MXBean;
  45. import org.eclipse.jgit.internal.storage.file.WindowCache;
  46. /**
  47. * Cache statistics for {@link WindowCache}.
  48. *
  49. * @since 4.11
  50. */
  51. @MXBean
  52. public interface WindowCacheStats {
  53. /**
  54. * @return the number of open files.
  55. * @deprecated use {@link #getOpenFileCount()} instead
  56. */
  57. @Deprecated
  58. public static int getOpenFiles() {
  59. return (int) WindowCache.getInstance().getStats().getOpenFileCount();
  60. }
  61. /**
  62. * @return the number of open bytes.
  63. * @deprecated use {@link #getOpenByteCount()} instead
  64. */
  65. @Deprecated
  66. public static long getOpenBytes() {
  67. return WindowCache.getInstance().getStats().getOpenByteCount();
  68. }
  69. /**
  70. * @return cache statistics for the WindowCache
  71. * @since 5.1.13
  72. */
  73. public static WindowCacheStats getStats() {
  74. return WindowCache.getInstance().getStats();
  75. }
  76. /**
  77. * Number of cache hits
  78. *
  79. * @return number of cache hits
  80. */
  81. long getHitCount();
  82. /**
  83. * Ratio of cache requests which were hits defined as
  84. * {@code hitCount / requestCount}, or {@code 1.0} when
  85. * {@code requestCount == 0}. Note that {@code hitRate + missRate =~ 1.0}.
  86. *
  87. * @return the ratio of cache requests which were hits
  88. */
  89. default double getHitRatio() {
  90. long requestCount = getRequestCount();
  91. return (requestCount == 0) ? 1.0
  92. : (double) getHitCount() / requestCount;
  93. }
  94. /**
  95. * Number of cache misses.
  96. *
  97. * @return number of cash misses
  98. */
  99. long getMissCount();
  100. /**
  101. * Ratio of cache requests which were misses defined as
  102. * {@code missCount / requestCount}, or {@code 0.0} when
  103. * {@code requestCount == 0}. Note that {@code hitRate + missRate =~ 1.0}.
  104. * Cache misses include all requests which weren't cache hits, including
  105. * requests which resulted in either successful or failed loading attempts.
  106. *
  107. * @return the ratio of cache requests which were misses
  108. */
  109. default double getMissRatio() {
  110. long requestCount = getRequestCount();
  111. return (requestCount == 0) ? 0.0
  112. : (double) getMissCount() / requestCount;
  113. }
  114. /**
  115. * Number of successful loads
  116. *
  117. * @return number of successful loads
  118. */
  119. long getLoadSuccessCount();
  120. /**
  121. * Number of failed loads
  122. *
  123. * @return number of failed loads
  124. */
  125. long getLoadFailureCount();
  126. /**
  127. * Ratio of cache load attempts which threw exceptions. This is defined as
  128. * {@code loadFailureCount / (loadSuccessCount + loadFailureCount)}, or
  129. * {@code 0.0} when {@code loadSuccessCount + loadFailureCount == 0}.
  130. *
  131. * @return the ratio of cache loading attempts which threw exceptions
  132. */
  133. default double getLoadFailureRatio() {
  134. long loadFailureCount = getLoadFailureCount();
  135. long totalLoadCount = getLoadSuccessCount() + loadFailureCount;
  136. return (totalLoadCount == 0) ? 0.0
  137. : (double) loadFailureCount / totalLoadCount;
  138. }
  139. /**
  140. * Total number of times that the cache attempted to load new values. This
  141. * includes both successful load operations, as well as failed loads. This
  142. * is defined as {@code loadSuccessCount + loadFailureCount}.
  143. *
  144. * @return the {@code loadSuccessCount + loadFailureCount}
  145. */
  146. default long getLoadCount() {
  147. return getLoadSuccessCount() + getLoadFailureCount();
  148. }
  149. /**
  150. * Number of cache evictions
  151. *
  152. * @return number of evictions
  153. */
  154. long getEvictionCount();
  155. /**
  156. * Ratio of cache evictions. This is defined as
  157. * {@code evictionCount / requestCount}, or {@code 0.0} when
  158. * {@code requestCount == 0}.
  159. *
  160. * @return the ratio of cache loading attempts which threw exceptions
  161. */
  162. default double getEvictionRatio() {
  163. long evictionCount = getEvictionCount();
  164. long requestCount = getRequestCount();
  165. return (requestCount == 0) ? 0.0
  166. : (double) evictionCount / requestCount;
  167. }
  168. /**
  169. * Number of times the cache returned either a cached or uncached value.
  170. * This is defined as {@code hitCount + missCount}.
  171. *
  172. * @return the {@code hitCount + missCount}
  173. */
  174. default long getRequestCount() {
  175. return getHitCount() + getMissCount();
  176. }
  177. /**
  178. * Average time in nanoseconds for loading new values. This is
  179. * {@code totalLoadTime / (loadSuccessCount + loadFailureCount)}.
  180. *
  181. * @return the average time spent loading new values
  182. */
  183. default double getAverageLoadTime() {
  184. long totalLoadCount = getLoadSuccessCount() + getLoadFailureCount();
  185. return (totalLoadCount == 0) ? 0.0
  186. : (double) getTotalLoadTime() / totalLoadCount;
  187. }
  188. /**
  189. * Total time in nanoseconds the cache spent loading new values.
  190. *
  191. * @return the total number of nanoseconds the cache has spent loading new
  192. * values
  193. */
  194. long getTotalLoadTime();
  195. /**
  196. * Number of pack files kept open by the cache
  197. *
  198. * @return number of files kept open by cache
  199. */
  200. long getOpenFileCount();
  201. /**
  202. * Number of bytes cached
  203. *
  204. * @return number of bytes cached
  205. */
  206. long getOpenByteCount();
  207. /**
  208. * Reset counters. Does not reset open bytes and open files counters.
  209. */
  210. void resetCounters();
  211. }