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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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 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. /** @return number of bytes read from the input stream */
  63. public long getNumBytesRead() {
  64. return numBytesRead;
  65. }
  66. /** @return number of whole commit objects in the pack */
  67. public long getNumWholeCommit() {
  68. return numWholeCommit;
  69. }
  70. /** @return number of whole tree objects in the pack */
  71. public long getNumWholeTree() {
  72. return numWholeTree;
  73. }
  74. /** @return number of whole blob objects in the pack */
  75. public long getNumWholeBlob() {
  76. return numWholeBlob;
  77. }
  78. /** @return number of whole tag objects in the pack */
  79. public long getNumWholeTag() {
  80. return numWholeTag;
  81. }
  82. /** @return number of offset delta objects in the pack */
  83. public long getNumOfsDelta() {
  84. return numOfsDelta;
  85. }
  86. /** @return number of ref delta objects in the pack */
  87. public long getNumRefDelta() {
  88. return numRefDelta;
  89. }
  90. /** @return number of delta commit objects in the pack */
  91. public long getNumDeltaCommit() {
  92. return numDeltaCommit;
  93. }
  94. /** @return number of delta tree objects in the pack */
  95. public long getNumDeltaTree() {
  96. return numDeltaTree;
  97. }
  98. /** @return number of delta blob objects in the pack */
  99. public long getNumDeltaBlob() {
  100. return numDeltaBlob;
  101. }
  102. /** @return number of delta tag objects in the pack */
  103. public long getNumDeltaTag() {
  104. return numDeltaTag;
  105. }
  106. /** A builder for {@link ReceivedPackStatistics}. */
  107. public static class Builder {
  108. private long numBytesRead;
  109. private long numWholeCommit;
  110. private long numWholeTree;
  111. private long numWholeBlob;
  112. private long numWholeTag;
  113. private long numOfsDelta;
  114. private long numRefDelta;
  115. private long numDeltaCommit;
  116. private long numDeltaTree;
  117. private long numDeltaBlob;
  118. private long numDeltaTag;
  119. /**
  120. * @param numBytesRead number of bytes read from the input stream
  121. * @return this
  122. */
  123. public Builder setNumBytesRead(long numBytesRead) {
  124. this.numBytesRead = numBytesRead;
  125. return this;
  126. }
  127. /**
  128. * Increment a whole object count.
  129. *
  130. * @param type OBJ_COMMIT, OBJ_TREE, OBJ_BLOB, or OBJ_TAG
  131. * @return this
  132. */
  133. public Builder addWholeObject(int type) {
  134. switch (type) {
  135. case Constants.OBJ_COMMIT:
  136. numWholeCommit++;
  137. break;
  138. case Constants.OBJ_TREE:
  139. numWholeTree++;
  140. break;
  141. case Constants.OBJ_BLOB:
  142. numWholeBlob++;
  143. break;
  144. case Constants.OBJ_TAG:
  145. numWholeTag++;
  146. break;
  147. default:
  148. throw new IllegalArgumentException(
  149. type + " cannot be a whole object"); //$NON-NLS-1$
  150. }
  151. return this;
  152. }
  153. /** @return this */
  154. public Builder addOffsetDelta() {
  155. numOfsDelta++;
  156. return this;
  157. }
  158. /** @return this */
  159. public Builder addRefDelta() {
  160. numRefDelta++;
  161. return this;
  162. }
  163. /**
  164. * Increment a delta object count.
  165. *
  166. * @param type OBJ_COMMIT, OBJ_TREE, OBJ_BLOB, or OBJ_TAG
  167. * @return this
  168. */
  169. public Builder addDeltaObject(int type) {
  170. switch (type) {
  171. case Constants.OBJ_COMMIT:
  172. numDeltaCommit++;
  173. break;
  174. case Constants.OBJ_TREE:
  175. numDeltaTree++;
  176. break;
  177. case Constants.OBJ_BLOB:
  178. numDeltaBlob++;
  179. break;
  180. case Constants.OBJ_TAG:
  181. numDeltaTag++;
  182. break;
  183. default:
  184. throw new IllegalArgumentException(
  185. "delta should be a delta to a whole object. " + //$NON-NLS-1$
  186. type + " cannot be a whole object"); //$NON-NLS-1$
  187. }
  188. return this;
  189. }
  190. ReceivedPackStatistics build() {
  191. ReceivedPackStatistics s = new ReceivedPackStatistics();
  192. s.numBytesRead = numBytesRead;
  193. s.numWholeCommit = numWholeCommit;
  194. s.numWholeTree = numWholeTree;
  195. s.numWholeBlob = numWholeBlob;
  196. s.numWholeTag = numWholeTag;
  197. s.numOfsDelta = numOfsDelta;
  198. s.numRefDelta = numRefDelta;
  199. s.numDeltaCommit = numDeltaCommit;
  200. s.numDeltaTree = numDeltaTree;
  201. s.numDeltaBlob = numDeltaBlob;
  202. s.numDeltaTag = numDeltaTag;
  203. return s;
  204. }
  205. }
  206. }