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 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. import javax.management.MXBean;
  12. import org.eclipse.jgit.internal.storage.file.WindowCache;
  13. /**
  14. * Cache statistics for {@link WindowCache}.
  15. *
  16. * @since 4.11
  17. */
  18. @MXBean
  19. public interface WindowCacheStats {
  20. /**
  21. * @return the number of open files.
  22. * @deprecated use {@link #getOpenFileCount()} instead
  23. */
  24. @Deprecated
  25. public static int getOpenFiles() {
  26. return (int) WindowCache.getInstance().getStats().getOpenFileCount();
  27. }
  28. /**
  29. * @return the number of open bytes.
  30. * @deprecated use {@link #getOpenByteCount()} instead
  31. */
  32. @Deprecated
  33. public static long getOpenBytes() {
  34. return WindowCache.getInstance().getStats().getOpenByteCount();
  35. }
  36. /**
  37. * @return cache statistics for the WindowCache
  38. * @since 5.1.13
  39. */
  40. public static WindowCacheStats getStats() {
  41. return WindowCache.getInstance().getStats();
  42. }
  43. /**
  44. * Number of cache hits
  45. *
  46. * @return number of cache hits
  47. */
  48. long getHitCount();
  49. /**
  50. * Ratio of cache requests which were hits defined as
  51. * {@code hitCount / requestCount}, or {@code 1.0} when
  52. * {@code requestCount == 0}. Note that {@code hitRate + missRate =~ 1.0}.
  53. *
  54. * @return the ratio of cache requests which were hits
  55. */
  56. default double getHitRatio() {
  57. long requestCount = getRequestCount();
  58. return (requestCount == 0) ? 1.0
  59. : (double) getHitCount() / requestCount;
  60. }
  61. /**
  62. * Number of cache misses.
  63. *
  64. * @return number of cash misses
  65. */
  66. long getMissCount();
  67. /**
  68. * Ratio of cache requests which were misses defined as
  69. * {@code missCount / requestCount}, or {@code 0.0} when
  70. * {@code requestCount == 0}. Note that {@code hitRate + missRate =~ 1.0}.
  71. * Cache misses include all requests which weren't cache hits, including
  72. * requests which resulted in either successful or failed loading attempts.
  73. *
  74. * @return the ratio of cache requests which were misses
  75. */
  76. default double getMissRatio() {
  77. long requestCount = getRequestCount();
  78. return (requestCount == 0) ? 0.0
  79. : (double) getMissCount() / requestCount;
  80. }
  81. /**
  82. * Number of successful loads
  83. *
  84. * @return number of successful loads
  85. */
  86. long getLoadSuccessCount();
  87. /**
  88. * Number of failed loads
  89. *
  90. * @return number of failed loads
  91. */
  92. long getLoadFailureCount();
  93. /**
  94. * Ratio of cache load attempts which threw exceptions. This is defined as
  95. * {@code loadFailureCount / (loadSuccessCount + loadFailureCount)}, or
  96. * {@code 0.0} when {@code loadSuccessCount + loadFailureCount == 0}.
  97. *
  98. * @return the ratio of cache loading attempts which threw exceptions
  99. */
  100. default double getLoadFailureRatio() {
  101. long loadFailureCount = getLoadFailureCount();
  102. long totalLoadCount = getLoadSuccessCount() + loadFailureCount;
  103. return (totalLoadCount == 0) ? 0.0
  104. : (double) loadFailureCount / totalLoadCount;
  105. }
  106. /**
  107. * Total number of times that the cache attempted to load new values. This
  108. * includes both successful load operations, as well as failed loads. This
  109. * is defined as {@code loadSuccessCount + loadFailureCount}.
  110. *
  111. * @return the {@code loadSuccessCount + loadFailureCount}
  112. */
  113. default long getLoadCount() {
  114. return getLoadSuccessCount() + getLoadFailureCount();
  115. }
  116. /**
  117. * Number of cache evictions
  118. *
  119. * @return number of evictions
  120. */
  121. long getEvictionCount();
  122. /**
  123. * Ratio of cache evictions. This is defined as
  124. * {@code evictionCount / requestCount}, or {@code 0.0} when
  125. * {@code requestCount == 0}.
  126. *
  127. * @return the ratio of cache loading attempts which threw exceptions
  128. */
  129. default double getEvictionRatio() {
  130. long evictionCount = getEvictionCount();
  131. long requestCount = getRequestCount();
  132. return (requestCount == 0) ? 0.0
  133. : (double) evictionCount / requestCount;
  134. }
  135. /**
  136. * Number of times the cache returned either a cached or uncached value.
  137. * This is defined as {@code hitCount + missCount}.
  138. *
  139. * @return the {@code hitCount + missCount}
  140. */
  141. default long getRequestCount() {
  142. return getHitCount() + getMissCount();
  143. }
  144. /**
  145. * Average time in nanoseconds for loading new values. This is
  146. * {@code totalLoadTime / (loadSuccessCount + loadFailureCount)}.
  147. *
  148. * @return the average time spent loading new values
  149. */
  150. default double getAverageLoadTime() {
  151. long totalLoadCount = getLoadSuccessCount() + getLoadFailureCount();
  152. return (totalLoadCount == 0) ? 0.0
  153. : (double) getTotalLoadTime() / totalLoadCount;
  154. }
  155. /**
  156. * Total time in nanoseconds the cache spent loading new values.
  157. *
  158. * @return the total number of nanoseconds the cache has spent loading new
  159. * values
  160. */
  161. long getTotalLoadTime();
  162. /**
  163. * Number of pack files kept open by the cache
  164. *
  165. * @return number of files kept open by cache
  166. */
  167. long getOpenFileCount();
  168. /**
  169. * Number of bytes cached
  170. *
  171. * @return number of bytes cached
  172. */
  173. long getOpenByteCount();
  174. /**
  175. * Reset counters. Does not reset open bytes and open files counters.
  176. */
  177. void resetCounters();
  178. }