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.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 java.util.Map;
  45. import javax.management.MXBean;
  46. import org.eclipse.jgit.internal.storage.file.WindowCache;
  47. /**
  48. * Cache statistics for {@link WindowCache}.
  49. *
  50. * @since 4.11
  51. */
  52. @MXBean
  53. public interface WindowCacheStats {
  54. /**
  55. * @return the number of open files.
  56. * @deprecated use {@link #getOpenFileCount()} instead
  57. */
  58. @Deprecated
  59. public static int getOpenFiles() {
  60. return (int) WindowCache.getInstance().getStats().getOpenFileCount();
  61. }
  62. /**
  63. * @return the number of open bytes.
  64. * @deprecated use {@link #getOpenByteCount()} instead
  65. */
  66. @Deprecated
  67. public static long getOpenBytes() {
  68. return WindowCache.getInstance().getStats().getOpenByteCount();
  69. }
  70. /**
  71. * @return cache statistics for the WindowCache
  72. * @since 5.1.13
  73. */
  74. public static WindowCacheStats getStats() {
  75. return WindowCache.getInstance().getStats();
  76. }
  77. /**
  78. * Number of cache hits
  79. *
  80. * @return number of cache hits
  81. */
  82. long getHitCount();
  83. /**
  84. * Ratio of cache requests which were hits defined as
  85. * {@code hitCount / requestCount}, or {@code 1.0} when
  86. * {@code requestCount == 0}. Note that {@code hitRate + missRate =~ 1.0}.
  87. *
  88. * @return the ratio of cache requests which were hits
  89. */
  90. default double getHitRatio() {
  91. long requestCount = getRequestCount();
  92. return (requestCount == 0) ? 1.0
  93. : (double) getHitCount() / requestCount;
  94. }
  95. /**
  96. * Number of cache misses.
  97. *
  98. * @return number of cash misses
  99. */
  100. long getMissCount();
  101. /**
  102. * Ratio of cache requests which were misses defined as
  103. * {@code missCount / requestCount}, or {@code 0.0} when
  104. * {@code requestCount == 0}. Note that {@code hitRate + missRate =~ 1.0}.
  105. * Cache misses include all requests which weren't cache hits, including
  106. * requests which resulted in either successful or failed loading attempts.
  107. *
  108. * @return the ratio of cache requests which were misses
  109. */
  110. default double getMissRatio() {
  111. long requestCount = getRequestCount();
  112. return (requestCount == 0) ? 0.0
  113. : (double) getMissCount() / requestCount;
  114. }
  115. /**
  116. * Number of successful loads
  117. *
  118. * @return number of successful loads
  119. */
  120. long getLoadSuccessCount();
  121. /**
  122. * Number of failed loads
  123. *
  124. * @return number of failed loads
  125. */
  126. long getLoadFailureCount();
  127. /**
  128. * Ratio of cache load attempts which threw exceptions. This is defined as
  129. * {@code loadFailureCount / (loadSuccessCount + loadFailureCount)}, or
  130. * {@code 0.0} when {@code loadSuccessCount + loadFailureCount == 0}.
  131. *
  132. * @return the ratio of cache loading attempts which threw exceptions
  133. */
  134. default double getLoadFailureRatio() {
  135. long loadFailureCount = getLoadFailureCount();
  136. long totalLoadCount = getLoadSuccessCount() + loadFailureCount;
  137. return (totalLoadCount == 0) ? 0.0
  138. : (double) loadFailureCount / totalLoadCount;
  139. }
  140. /**
  141. * Total number of times that the cache attempted to load new values. This
  142. * includes both successful load operations, as well as failed loads. This
  143. * is defined as {@code loadSuccessCount + loadFailureCount}.
  144. *
  145. * @return the {@code loadSuccessCount + loadFailureCount}
  146. */
  147. default long getLoadCount() {
  148. return getLoadSuccessCount() + getLoadFailureCount();
  149. }
  150. /**
  151. * Number of cache evictions
  152. *
  153. * @return number of evictions
  154. */
  155. long getEvictionCount();
  156. /**
  157. * Ratio of cache evictions. This is defined as
  158. * {@code evictionCount / requestCount}, or {@code 0.0} when
  159. * {@code requestCount == 0}.
  160. *
  161. * @return the ratio of cache loading attempts which threw exceptions
  162. */
  163. default double getEvictionRatio() {
  164. long evictionCount = getEvictionCount();
  165. long requestCount = getRequestCount();
  166. return (requestCount == 0) ? 0.0
  167. : (double) evictionCount / requestCount;
  168. }
  169. /**
  170. * Number of times the cache returned either a cached or uncached value.
  171. * This is defined as {@code hitCount + missCount}.
  172. *
  173. * @return the {@code hitCount + missCount}
  174. */
  175. default long getRequestCount() {
  176. return getHitCount() + getMissCount();
  177. }
  178. /**
  179. * Average time in nanoseconds for loading new values. This is
  180. * {@code totalLoadTime / (loadSuccessCount + loadFailureCount)}.
  181. *
  182. * @return the average time spent loading new values
  183. */
  184. default double getAverageLoadTime() {
  185. long totalLoadCount = getLoadSuccessCount() + getLoadFailureCount();
  186. return (totalLoadCount == 0) ? 0.0
  187. : (double) getTotalLoadTime() / totalLoadCount;
  188. }
  189. /**
  190. * Total time in nanoseconds the cache spent loading new values.
  191. *
  192. * @return the total number of nanoseconds the cache has spent loading new
  193. * values
  194. */
  195. long getTotalLoadTime();
  196. /**
  197. * Number of pack files kept open by the cache
  198. *
  199. * @return number of files kept open by cache
  200. */
  201. long getOpenFileCount();
  202. /**
  203. * Number of bytes cached
  204. *
  205. * @return number of bytes cached
  206. */
  207. long getOpenByteCount();
  208. /**
  209. * Number of bytes cached per repository
  210. *
  211. * @return number of bytes cached per repository
  212. */
  213. Map<String, Long> getOpenByteCountPerRepository();
  214. /**
  215. * Reset counters. Does not reset open bytes and open files counters.
  216. */
  217. void resetCounters();
  218. }