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

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