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.

ReceivedPackStatistics.java 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /*
  2. * Copyright (C) 2016, Google Inc.
  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.transport;
  44. import org.eclipse.jgit.lib.Constants;
  45. /**
  46. * Statistics about {@link org.eclipse.jgit.transport.PackParser}.
  47. *
  48. * @since 4.6
  49. */
  50. public class ReceivedPackStatistics {
  51. private long numBytesRead;
  52. private long numWholeCommit;
  53. private long numWholeTree;
  54. private long numWholeBlob;
  55. private long numWholeTag;
  56. private long numOfsDelta;
  57. private long numRefDelta;
  58. private long numDeltaCommit;
  59. private long numDeltaTree;
  60. private long numDeltaBlob;
  61. private long numDeltaTag;
  62. /**
  63. * Get number of bytes read from the input stream
  64. *
  65. * @return number of bytes read from the input stream
  66. */
  67. public long getNumBytesRead() {
  68. return numBytesRead;
  69. }
  70. /**
  71. * Get number of whole commit objects in the pack
  72. *
  73. * @return number of whole commit objects in the pack
  74. */
  75. public long getNumWholeCommit() {
  76. return numWholeCommit;
  77. }
  78. /**
  79. * Get number of whole tree objects in the pack
  80. *
  81. * @return number of whole tree objects in the pack
  82. */
  83. public long getNumWholeTree() {
  84. return numWholeTree;
  85. }
  86. /**
  87. * Get number of whole blob objects in the pack
  88. *
  89. * @return number of whole blob objects in the pack
  90. */
  91. public long getNumWholeBlob() {
  92. return numWholeBlob;
  93. }
  94. /**
  95. * Get number of whole tag objects in the pack
  96. *
  97. * @return number of whole tag objects in the pack
  98. */
  99. public long getNumWholeTag() {
  100. return numWholeTag;
  101. }
  102. /**
  103. * Get number of offset delta objects in the pack
  104. *
  105. * @return number of offset delta objects in the pack
  106. */
  107. public long getNumOfsDelta() {
  108. return numOfsDelta;
  109. }
  110. /**
  111. * Get number of ref delta objects in the pack
  112. *
  113. * @return number of ref delta objects in the pack
  114. */
  115. public long getNumRefDelta() {
  116. return numRefDelta;
  117. }
  118. /**
  119. * Get number of delta commit objects in the pack
  120. *
  121. * @return number of delta commit objects in the pack
  122. */
  123. public long getNumDeltaCommit() {
  124. return numDeltaCommit;
  125. }
  126. /**
  127. * Get number of delta tree objects in the pack
  128. *
  129. * @return number of delta tree objects in the pack
  130. */
  131. public long getNumDeltaTree() {
  132. return numDeltaTree;
  133. }
  134. /**
  135. * Get number of delta blob objects in the pack
  136. *
  137. * @return number of delta blob objects in the pack
  138. */
  139. public long getNumDeltaBlob() {
  140. return numDeltaBlob;
  141. }
  142. /**
  143. * Get number of delta tag objects in the pack
  144. *
  145. * @return number of delta tag objects in the pack
  146. */
  147. public long getNumDeltaTag() {
  148. return numDeltaTag;
  149. }
  150. /** A builder for {@link ReceivedPackStatistics}. */
  151. public static class Builder {
  152. private long numBytesRead;
  153. private long numWholeCommit;
  154. private long numWholeTree;
  155. private long numWholeBlob;
  156. private long numWholeTag;
  157. private long numOfsDelta;
  158. private long numRefDelta;
  159. private long numDeltaCommit;
  160. private long numDeltaTree;
  161. private long numDeltaBlob;
  162. private long numDeltaTag;
  163. /**
  164. * @param numBytesRead number of bytes read from the input stream
  165. * @return this
  166. */
  167. public Builder setNumBytesRead(long numBytesRead) {
  168. this.numBytesRead = numBytesRead;
  169. return this;
  170. }
  171. /**
  172. * Increment a whole object count.
  173. *
  174. * @param type OBJ_COMMIT, OBJ_TREE, OBJ_BLOB, or OBJ_TAG
  175. * @return this
  176. */
  177. public Builder addWholeObject(int type) {
  178. switch (type) {
  179. case Constants.OBJ_COMMIT:
  180. numWholeCommit++;
  181. break;
  182. case Constants.OBJ_TREE:
  183. numWholeTree++;
  184. break;
  185. case Constants.OBJ_BLOB:
  186. numWholeBlob++;
  187. break;
  188. case Constants.OBJ_TAG:
  189. numWholeTag++;
  190. break;
  191. default:
  192. throw new IllegalArgumentException(
  193. type + " cannot be a whole object"); //$NON-NLS-1$
  194. }
  195. return this;
  196. }
  197. /** @return this */
  198. public Builder addOffsetDelta() {
  199. numOfsDelta++;
  200. return this;
  201. }
  202. /** @return this */
  203. public Builder addRefDelta() {
  204. numRefDelta++;
  205. return this;
  206. }
  207. /**
  208. * Increment a delta object count.
  209. *
  210. * @param type OBJ_COMMIT, OBJ_TREE, OBJ_BLOB, or OBJ_TAG
  211. * @return this
  212. */
  213. public Builder addDeltaObject(int type) {
  214. switch (type) {
  215. case Constants.OBJ_COMMIT:
  216. numDeltaCommit++;
  217. break;
  218. case Constants.OBJ_TREE:
  219. numDeltaTree++;
  220. break;
  221. case Constants.OBJ_BLOB:
  222. numDeltaBlob++;
  223. break;
  224. case Constants.OBJ_TAG:
  225. numDeltaTag++;
  226. break;
  227. default:
  228. throw new IllegalArgumentException(
  229. "delta should be a delta to a whole object. " + //$NON-NLS-1$
  230. type + " cannot be a whole object"); //$NON-NLS-1$
  231. }
  232. return this;
  233. }
  234. ReceivedPackStatistics build() {
  235. ReceivedPackStatistics s = new ReceivedPackStatistics();
  236. s.numBytesRead = numBytesRead;
  237. s.numWholeCommit = numWholeCommit;
  238. s.numWholeTree = numWholeTree;
  239. s.numWholeBlob = numWholeBlob;
  240. s.numWholeTag = numWholeTag;
  241. s.numOfsDelta = numOfsDelta;
  242. s.numRefDelta = numRefDelta;
  243. s.numDeltaCommit = numDeltaCommit;
  244. s.numDeltaTree = numDeltaTree;
  245. s.numDeltaBlob = numDeltaBlob;
  246. s.numDeltaTag = numDeltaTag;
  247. return s;
  248. }
  249. }
  250. }