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