@cryptotaxi247 / kubo / commits / 58d222fbd

Remove codahale/hdrhistogram as it is not longer used

License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>

Jakub Sztandera committed Jun 11, 2016 at 16:25 UTC 58d222fbd56dd34d5007795add8639b4981f8428
7 files changed -1000
Godeps/_workspace/src/github.com/codahale/hdrhistogram/.travis.yml deleted
-9
@@ -1,9 +0,0 @@
1 -language: go
2 -go:
3 - - 1.3.3
4 -notifications:
5 - # See http://about.travis-ci.org/docs/user/build-configuration/ to learn more
6 - # about configuring notification recipients and more.
7 - email:
8 - recipients:
9 - - coda.hale@gmail.com
Godeps/_workspace/src/github.com/codahale/hdrhistogram/LICENSE deleted
-21
@@ -1,21 +0,0 @@
1 -The MIT License (MIT)
2 -
3 -Copyright (c) 2014 Coda Hale
4 -
5 -Permission is hereby granted, free of charge, to any person obtaining a copy
6 -of this software and associated documentation files (the "Software"), to deal
7 -in the Software without restriction, including without limitation the rights
8 -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 -copies of the Software, and to permit persons to whom the Software is
10 -furnished to do so, subject to the following conditions:
11 -
12 -The above copyright notice and this permission notice shall be included in
13 -all copies or substantial portions of the Software.
14 -
15 -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 -THE SOFTWARE.
Godeps/_workspace/src/github.com/codahale/hdrhistogram/README.md deleted
-15
@@ -1,15 +0,0 @@
1 -hdrhistogram
2 -============
3 -
4 -[![Build Status](https://travis-ci.org/codahale/hdrhistogram.png?branch=master)](https://travis-ci.org/codahale/hdrhistogram)
5 -
6 -A pure Go implementation of the [HDR Histogram](https://github.com/HdrHistogram/HdrHistogram).
7 -
8 -> A Histogram that supports recording and analyzing sampled data value counts
9 -> across a configurable integer value range with configurable value precision
10 -> within the range. Value precision is expressed as the number of significant
11 -> digits in the value recording, and provides control over value quantization
12 -> behavior across the value range and the subsequent value resolution at any
13 -> given level.
14 -
15 -For documentation, check [godoc](http://godoc.org/github.com/codahale/hdrhistogram).
Godeps/_workspace/src/github.com/codahale/hdrhistogram/hdr.go deleted
-513
@@ -1,513 +0,0 @@
1 -// Package hdrhistogram provides an implementation of Gil Tene's HDR Histogram
2 -// data structure. The HDR Histogram allows for fast and accurate analysis of
3 -// the extreme ranges of data with non-normal distributions, like latency.
4 -package hdrhistogram
5 -
6 -import (
7 - "fmt"
8 - "math"
9 -)
10 -
11 -// A Bracket is a part of a cumulative distribution.
12 -type Bracket struct {
13 - Quantile float64
14 - Count, ValueAt int64
15 -}
16 -
17 -// A Snapshot is an exported view of a Histogram, useful for serializing them.
18 -// A Histogram can be constructed from it by passing it to Import.
19 -type Snapshot struct {
20 - LowestTrackableValue int64
21 - HighestTrackableValue int64
22 - SignificantFigures int64
23 - Counts []int64
24 -}
25 -
26 -// A Histogram is a lossy data structure used to record the distribution of
27 -// non-normally distributed data (like latency) with a high degree of accuracy
28 -// and a bounded degree of precision.
29 -type Histogram struct {
30 - lowestTrackableValue int64
31 - highestTrackableValue int64
32 - unitMagnitude int64
33 - significantFigures int64
34 - subBucketHalfCountMagnitude int32
35 - subBucketHalfCount int32
36 - subBucketMask int64
37 - subBucketCount int32
38 - bucketCount int32
39 - countsLen int32
40 - totalCount int64
41 - counts []int64
42 -}
43 -
44 -// New returns a new Histogram instance capable of tracking values in the given
45 -// range and with the given amount of precision.
46 -func New(minValue, maxValue int64, sigfigs int) *Histogram {
47 - if sigfigs < 1 || 5 < sigfigs {
48 - panic(fmt.Errorf("sigfigs must be [1,5] (was %d)", sigfigs))
49 - }
50 -
51 - largestValueWithSingleUnitResolution := 2 * math.Pow10(sigfigs)
52 - subBucketCountMagnitude := int32(math.Ceil(math.Log2(float64(largestValueWithSingleUnitResolution))))
53 -
54 - subBucketHalfCountMagnitude := subBucketCountMagnitude
55 - if subBucketHalfCountMagnitude < 1 {
56 - subBucketHalfCountMagnitude = 1
57 - }
58 - subBucketHalfCountMagnitude--
59 -
60 - unitMagnitude := int32(math.Floor(math.Log2(float64(minValue))))
61 - if unitMagnitude < 0 {
62 - unitMagnitude = 0
63 - }
64 -
65 - subBucketCount := int32(math.Pow(2, float64(subBucketHalfCountMagnitude)+1))
66 -
67 - subBucketHalfCount := subBucketCount / 2
68 - subBucketMask := int64(subBucketCount-1) << uint(unitMagnitude)
69 -
70 - // determine exponent range needed to support the trackable value with no
71 - // overflow:
72 - smallestUntrackableValue := int64(subBucketCount) << uint(unitMagnitude)
73 - bucketsNeeded := int32(1)
74 - for smallestUntrackableValue < maxValue {
75 - smallestUntrackableValue <<= 1
76 - bucketsNeeded++
77 - }
78 -
79 - bucketCount := bucketsNeeded
80 - countsLen := (bucketCount + 1) * (subBucketCount / 2)
81 -
82 - return &Histogram{
83 - lowestTrackableValue: minValue,
84 - highestTrackableValue: maxValue,
85 - unitMagnitude: int64(unitMagnitude),
86 - significantFigures: int64(sigfigs),
87 - subBucketHalfCountMagnitude: subBucketHalfCountMagnitude,
88 - subBucketHalfCount: subBucketHalfCount,
89 - subBucketMask: subBucketMask,
90 - subBucketCount: subBucketCount,
91 - bucketCount: bucketCount,
92 - countsLen: countsLen,
93 - totalCount: 0,
94 - counts: make([]int64, countsLen),
95 - }
96 -}
97 -
98 -// ByteSize returns an estimate of the amount of memory allocated to the
99 -// histogram in bytes.
100 -//
101 -// N.B.: This does not take into account the overhead for slices, which are
102 -// small, constant, and specific to the compiler version.
103 -func (h *Histogram) ByteSize() int {
104 - return 6*8 + 5*4 + len(h.counts)*8
105 -}
106 -
107 -// Merge merges the data stored in the given histogram with the receiver,
108 -// returning the number of recorded values which had to be dropped.
109 -func (h *Histogram) Merge(from *Histogram) (dropped int64) {
110 - i := from.rIterator()
111 - for i.next() {
112 - v := i.valueFromIdx
113 - c := i.countAtIdx
114 -
115 - if h.RecordValues(v, c) != nil {
116 - dropped += c
117 - }
118 - }
119 -
120 - return
121 -}
122 -
123 -// TotalCount returns total number of values recorded.
124 -func (h *Histogram) TotalCount() int64 {
125 - return h.totalCount
126 -}
127 -
128 -// Max returns the approximate maximum recorded value.
129 -func (h *Histogram) Max() int64 {
130 - var max int64
131 - i := h.iterator()
132 - for i.next() {
133 - if i.countAtIdx != 0 {
134 - max = i.highestEquivalentValue
135 - }
136 - }
137 - return h.lowestEquivalentValue(max)
138 -}
139 -
140 -// Min returns the approximate minimum recorded value.
141 -func (h *Histogram) Min() int64 {
142 - var min int64
143 - i := h.iterator()
144 - for i.next() {
145 - if i.countAtIdx != 0 && min == 0 {
146 - min = i.highestEquivalentValue
147 - break
148 - }
149 - }
150 - return h.lowestEquivalentValue(min)
151 -}
152 -
153 -// Mean returns the approximate arithmetic mean of the recorded values.
154 -func (h *Histogram) Mean() float64 {
155 - var total int64
156 - i := h.iterator()
157 - for i.next() {
158 - if i.countAtIdx != 0 {
159 - total += i.countAtIdx * h.medianEquivalentValue(i.valueFromIdx)
160 - }
161 - }
162 - return float64(total) / float64(h.totalCount)
163 -}
164 -
165 -// StdDev returns the approximate standard deviation of the recorded values.
166 -func (h *Histogram) StdDev() float64 {
167 - mean := h.Mean()
168 - geometricDevTotal := 0.0
169 -
170 - i := h.iterator()
171 - for i.next() {
172 - if i.countAtIdx != 0 {
173 - dev := float64(h.medianEquivalentValue(i.valueFromIdx)) - mean
174 - geometricDevTotal += (dev * dev) * float64(i.countAtIdx)
175 - }
176 - }
177 -
178 - return math.Sqrt(geometricDevTotal / float64(h.totalCount))
179 -}
180 -
181 -// Reset deletes all recorded values and restores the histogram to its original
182 -// state.
183 -func (h *Histogram) Reset() {
184 - h.totalCount = 0
185 - for i := range h.counts {
186 - h.counts[i] = 0
187 - }
188 -}
189 -
190 -// RecordValue records the given value, returning an error if the value is out
191 -// of range.
192 -func (h *Histogram) RecordValue(v int64) error {
193 - return h.RecordValues(v, 1)
194 -}
195 -
196 -// RecordCorrectedValue records the given value, correcting for stalls in the
197 -// recording process. This only works for processes which are recording values
198 -// at an expected interval (e.g., doing jitter analysis). Processes which are
199 -// recording ad-hoc values (e.g., latency for incoming requests) can't take
200 -// advantage of this.
201 -func (h *Histogram) RecordCorrectedValue(v, expectedInterval int64) error {
202 - if err := h.RecordValue(v); err != nil {
203 - return err
204 - }
205 -
206 - if expectedInterval <= 0 || v <= expectedInterval {
207 - return nil
208 - }
209 -
210 - missingValue := v - expectedInterval
211 - for missingValue >= expectedInterval {
212 - if err := h.RecordValue(missingValue); err != nil {
213 - return err
214 - }
215 - missingValue -= expectedInterval
216 - }
217 -
218 - return nil
219 -}
220 -
221 -// RecordValues records n occurrences of the given value, returning an error if
222 -// the value is out of range.
223 -func (h *Histogram) RecordValues(v, n int64) error {
224 - idx := h.countsIndexFor(v)
225 - if idx < 0 || int(h.countsLen) <= idx {
226 - return fmt.Errorf("value %d is too large to be recorded", v)
227 - }
228 - h.counts[idx] += n
229 - h.totalCount += n
230 -
231 - return nil
232 -}
233 -
234 -// ValueAtQuantile returns the recorded value at the given quantile (0..100).
235 -func (h *Histogram) ValueAtQuantile(q float64) int64 {
236 - if q > 100 {
237 - q = 100
238 - }
239 -
240 - total := int64(0)
241 - countAtPercentile := int64(((q / 100) * float64(h.totalCount)) + 0.5)
242 -
243 - i := h.iterator()
244 - for i.next() {
245 - total += i.countAtIdx
246 - if total >= countAtPercentile {
247 - return h.highestEquivalentValue(i.valueFromIdx)
248 - }
249 - }
250 -
251 - return 0
252 -}
253 -
254 -// CumulativeDistribution returns an ordered list of brackets of the
255 -// distribution of recorded values.
256 -func (h *Histogram) CumulativeDistribution() []Bracket {
257 - var result []Bracket
258 -
259 - i := h.pIterator(1)
260 - for i.next() {
261 - result = append(result, Bracket{
262 - Quantile: i.percentile,
263 - Count: i.countToIdx,
264 - ValueAt: i.highestEquivalentValue,
265 - })
266 - }
267 -
268 - return result
269 -}
270 -
271 -// Equals returns true if the two Histograms are equivalent, false if not.
272 -func (h *Histogram) Equals(other *Histogram) bool {
273 - switch {
274 - case
275 - h.lowestTrackableValue != other.lowestTrackableValue,
276 - h.highestTrackableValue != other.highestTrackableValue,
277 - h.unitMagnitude != other.unitMagnitude,
278 - h.significantFigures != other.significantFigures,
279 - h.subBucketHalfCountMagnitude != other.subBucketHalfCountMagnitude,
280 - h.subBucketHalfCount != other.subBucketHalfCount,
281 - h.subBucketMask != other.subBucketMask,
282 - h.subBucketCount != other.subBucketCount,
283 - h.bucketCount != other.bucketCount,
284 - h.countsLen != other.countsLen,
285 - h.totalCount != other.totalCount:
286 - return false
287 - default:
288 - for i, c := range h.counts {
289 - if c != other.counts[i] {
290 - return false
291 - }
292 - }
293 - }
294 - return true
295 -}
296 -
297 -// Export returns a snapshot view of the Histogram. This can be later passed to
298 -// Import to construct a new Histogram with the same state.
299 -func (h *Histogram) Export() *Snapshot {
300 - return &Snapshot{
301 - LowestTrackableValue: h.lowestTrackableValue,
302 - HighestTrackableValue: h.highestTrackableValue,
303 - SignificantFigures: h.significantFigures,
304 - Counts: h.counts,
305 - }
306 -}
307 -
308 -// Import returns a new Histogram populated from the Snapshot data.
309 -func Import(s *Snapshot) *Histogram {
310 - h := New(s.LowestTrackableValue, s.HighestTrackableValue, int(s.SignificantFigures))
311 - h.counts = s.Counts
312 - totalCount := int64(0)
313 - for i := int32(0); i < h.countsLen; i++ {
314 - countAtIndex := h.counts[i]
315 - if countAtIndex > 0 {
316 - totalCount += countAtIndex
317 - }
318 - }
319 - h.totalCount = totalCount
320 - return h
321 -}
322 -
323 -func (h *Histogram) iterator() *iterator {
324 - return &iterator{
325 - h: h,
326 - subBucketIdx: -1,
327 - }
328 -}
329 -
330 -func (h *Histogram) rIterator() *rIterator {
331 - return &rIterator{
332 - iterator: iterator{
333 - h: h,
334 - subBucketIdx: -1,
335 - },
336 - }
337 -}
338 -
339 -func (h *Histogram) pIterator(ticksPerHalfDistance int32) *pIterator {
340 - return &pIterator{
341 - iterator: iterator{
342 - h: h,
343 - subBucketIdx: -1,
344 - },
345 - ticksPerHalfDistance: ticksPerHalfDistance,
346 - }
347 -}
348 -
349 -func (h *Histogram) sizeOfEquivalentValueRange(v int64) int64 {
350 - bucketIdx := h.getBucketIndex(v)
351 - subBucketIdx := h.getSubBucketIdx(v, bucketIdx)
352 - adjustedBucket := bucketIdx
353 - if subBucketIdx >= h.subBucketCount {
354 - adjustedBucket++
355 - }
356 - return int64(1) << uint(h.unitMagnitude+int64(adjustedBucket))
357 -}
358 -
359 -func (h *Histogram) valueFromIndex(bucketIdx, subBucketIdx int32) int64 {
360 - return int64(subBucketIdx) << uint(int64(bucketIdx)+h.unitMagnitude)
361 -}
362 -
363 -func (h *Histogram) lowestEquivalentValue(v int64) int64 {
364 - bucketIdx := h.getBucketIndex(v)
365 - subBucketIdx := h.getSubBucketIdx(v, bucketIdx)
366 - return h.valueFromIndex(bucketIdx, subBucketIdx)
367 -}
368 -
369 -func (h *Histogram) nextNonEquivalentValue(v int64) int64 {
370 - return h.lowestEquivalentValue(v) + h.sizeOfEquivalentValueRange(v)
371 -}
372 -
373 -func (h *Histogram) highestEquivalentValue(v int64) int64 {
374 - return h.nextNonEquivalentValue(v) - 1
375 -}
376 -
377 -func (h *Histogram) medianEquivalentValue(v int64) int64 {
378 - return h.lowestEquivalentValue(v) + (h.sizeOfEquivalentValueRange(v) >> 1)
379 -}
380 -
381 -func (h *Histogram) getCountAtIndex(bucketIdx, subBucketIdx int32) int64 {
382 - return h.counts[h.countsIndex(bucketIdx, subBucketIdx)]
383 -}
384 -
385 -func (h *Histogram) countsIndex(bucketIdx, subBucketIdx int32) int32 {
386 - bucketBaseIdx := (bucketIdx + 1) << uint(h.subBucketHalfCountMagnitude)
387 - offsetInBucket := subBucketIdx - h.subBucketHalfCount
388 - return bucketBaseIdx + offsetInBucket
389 -}
390 -
391 -func (h *Histogram) getBucketIndex(v int64) int32 {
392 - pow2Ceiling := bitLen(v | h.subBucketMask)
393 - return int32(pow2Ceiling - int64(h.unitMagnitude) -
394 - int64(h.subBucketHalfCountMagnitude+1))
395 -}
396 -
397 -func (h *Histogram) getSubBucketIdx(v int64, idx int32) int32 {
398 - return int32(v >> uint(int64(idx)+int64(h.unitMagnitude)))
399 -}
400 -
401 -func (h *Histogram) countsIndexFor(v int64) int {
402 - bucketIdx := h.getBucketIndex(v)
403 - subBucketIdx := h.getSubBucketIdx(v, bucketIdx)
404 - return int(h.countsIndex(bucketIdx, subBucketIdx))
405 -}
406 -
407 -type iterator struct {
408 - h *Histogram
409 - bucketIdx, subBucketIdx int32
410 - countAtIdx, countToIdx, valueFromIdx int64
411 - highestEquivalentValue int64
412 -}
413 -
414 -func (i *iterator) next() bool {
415 - if i.countToIdx >= i.h.totalCount {
416 - return false
417 - }
418 -
419 - // increment bucket
420 - i.subBucketIdx++
421 - if i.subBucketIdx >= i.h.subBucketCount {
422 - i.subBucketIdx = i.h.subBucketHalfCount
423 - i.bucketIdx++
424 - }
425 -
426 - if i.bucketIdx >= i.h.bucketCount {
427 - return false
428 - }
429 -
430 - i.countAtIdx = i.h.getCountAtIndex(i.bucketIdx, i.subBucketIdx)
431 - i.countToIdx += i.countAtIdx
432 - i.valueFromIdx = i.h.valueFromIndex(i.bucketIdx, i.subBucketIdx)
433 - i.highestEquivalentValue = i.h.highestEquivalentValue(i.valueFromIdx)
434 -
435 - return true
436 -}
437 -
438 -type rIterator struct {
439 - iterator
440 - countAddedThisStep int64
441 -}
442 -
443 -func (r *rIterator) next() bool {
444 - for r.iterator.next() {
445 - if r.countAtIdx != 0 {
446 - r.countAddedThisStep = r.countAtIdx
447 - return true
448 - }
449 - }
450 - return false
451 -}
452 -
453 -type pIterator struct {
454 - iterator
455 - seenLastValue bool
456 - ticksPerHalfDistance int32
457 - percentileToIteratorTo float64
458 - percentile float64
459 -}
460 -
461 -func (p *pIterator) next() bool {
462 - if !(p.countToIdx < p.h.totalCount) {
463 - if p.seenLastValue {
464 - return false
465 - }
466 -
467 - p.seenLastValue = true
468 - p.percentile = 100
469 -
470 - return true
471 - }
472 -
473 - if p.subBucketIdx == -1 && !p.iterator.next() {
474 - return false
475 - }
476 -
477 - var done = false
478 - for !done {
479 - currentPercentile := (100.0 * float64(p.countToIdx)) / float64(p.h.totalCount)
480 - if p.countAtIdx != 0 && p.percentileToIteratorTo <= currentPercentile {
481 - p.percentile = p.percentileToIteratorTo
482 - halfDistance := math.Trunc(math.Pow(2, math.Trunc(math.Log2(100.0/(100.0-p.percentileToIteratorTo)))+1))
483 - percentileReportingTicks := float64(p.ticksPerHalfDistance) * halfDistance
484 - p.percentileToIteratorTo += 100.0 / percentileReportingTicks
485 - return true
486 - }
487 - done = !p.iterator.next()
488 - }
489 -
490 - return true
491 -}
492 -
493 -func bitLen(x int64) (n int64) {
494 - for ; x >= 0x8000; x >>= 16 {
495 - n += 16
496 - }
497 - if x >= 0x80 {
498 - x >>= 8
499 - n += 8
500 - }
501 - if x >= 0x8 {
502 - x >>= 4
503 - n += 4
504 - }
505 - if x >= 0x2 {
506 - x >>= 2
507 - n += 2
508 - }
509 - if x >= 0x1 {
510 - n++
511 - }
512 - return
513 -}
Godeps/_workspace/src/github.com/codahale/hdrhistogram/hdr_test.go deleted
-333
@@ -1,333 +0,0 @@
1 -package hdrhistogram_test
2 -
3 -import (
4 - "reflect"
5 - "testing"
6 -
7 - "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/codahale/hdrhistogram"
8 -)
9 -
10 -func TestHighSigFig(t *testing.T) {
11 - input := []int64{
12 - 459876, 669187, 711612, 816326, 931423, 1033197, 1131895, 2477317,
13 - 3964974, 12718782,
14 - }
15 -
16 - hist := hdrhistogram.New(459876, 12718782, 5)
17 - for _, sample := range input {
18 - hist.RecordValue(sample)
19 - }
20 -
21 - if v, want := hist.ValueAtQuantile(50), int64(1048575); v != want {
22 - t.Errorf("Median was %v, but expected %v", v, want)
23 - }
24 -}
25 -
26 -func TestValueAtQuantile(t *testing.T) {
27 - h := hdrhistogram.New(1, 10000000, 3)
28 -
29 - for i := 0; i < 1000000; i++ {
30 - if err := h.RecordValue(int64(i)); err != nil {
31 - t.Fatal(err)
32 - }
33 - }
34 -
35 - data := []struct {
36 - q float64
37 - v int64
38 - }{
39 - {q: 50, v: 500223},
40 - {q: 75, v: 750079},
41 - {q: 90, v: 900095},
42 - {q: 95, v: 950271},
43 - {q: 99, v: 990207},
44 - {q: 99.9, v: 999423},
45 - {q: 99.99, v: 999935},
46 - }
47 -
48 - for _, d := range data {
49 - if v := h.ValueAtQuantile(d.q); v != d.v {
50 - t.Errorf("P%v was %v, but expected %v", d.q, v, d.v)
51 - }
52 - }
53 -}
54 -
55 -func TestMean(t *testing.T) {
56 - h := hdrhistogram.New(1, 10000000, 3)
57 -
58 - for i := 0; i < 1000000; i++ {
59 - if err := h.RecordValue(int64(i)); err != nil {
60 - t.Fatal(err)
61 - }
62 - }
63 -
64 - if v, want := h.Mean(), 500000.013312; v != want {
65 - t.Errorf("Mean was %v, but expected %v", v, want)
66 - }
67 -}
68 -
69 -func TestStdDev(t *testing.T) {
70 - h := hdrhistogram.New(1, 10000000, 3)
71 -
72 - for i := 0; i < 1000000; i++ {
73 - if err := h.RecordValue(int64(i)); err != nil {
74 - t.Fatal(err)
75 - }
76 - }
77 -
78 - if v, want := h.StdDev(), 288675.1403682715; v != want {
79 - t.Errorf("StdDev was %v, but expected %v", v, want)
80 - }
81 -}
82 -
83 -func TestTotalCount(t *testing.T) {
84 - h := hdrhistogram.New(1, 10000000, 3)
85 -
86 - for i := 0; i < 1000000; i++ {
87 - if err := h.RecordValue(int64(i)); err != nil {
88 - t.Fatal(err)
89 - }
90 - if v, want := h.TotalCount(), int64(i+1); v != want {
91 - t.Errorf("TotalCount was %v, but expected %v", v, want)
92 - }
93 - }
94 -}
95 -
96 -func TestMax(t *testing.T) {
97 - h := hdrhistogram.New(1, 10000000, 3)
98 -
99 - for i := 0; i < 1000000; i++ {
100 - if err := h.RecordValue(int64(i)); err != nil {
101 - t.Fatal(err)
102 - }
103 - }
104 -
105 - if v, want := h.Max(), int64(999936); v != want {
106 - t.Errorf("Max was %v, but expected %v", v, want)
107 - }
108 -}
109 -
110 -func TestReset(t *testing.T) {
111 - h := hdrhistogram.New(1, 10000000, 3)
112 -
113 - for i := 0; i < 1000000; i++ {
114 - if err := h.RecordValue(int64(i)); err != nil {
115 - t.Fatal(err)
116 - }
117 - }
118 -
119 - h.Reset()
120 -
121 - if v, want := h.Max(), int64(0); v != want {
122 - t.Errorf("Max was %v, but expected %v", v, want)
123 - }
124 -}
125 -
126 -func TestMerge(t *testing.T) {
127 - h1 := hdrhistogram.New(1, 1000, 3)
128 - h2 := hdrhistogram.New(1, 1000, 3)
129 -
130 - for i := 0; i < 100; i++ {
131 - if err := h1.RecordValue(int64(i)); err != nil {
132 - t.Fatal(err)
133 - }
134 - }
135 -
136 - for i := 100; i < 200; i++ {
137 - if err := h2.RecordValue(int64(i)); err != nil {
138 - t.Fatal(err)
139 - }
140 - }
141 -
142 - h1.Merge(h2)
143 -
144 - if v, want := h1.ValueAtQuantile(50), int64(99); v != want {
145 - t.Errorf("Median was %v, but expected %v", v, want)
146 - }
147 -}
148 -
149 -func TestMin(t *testing.T) {
150 - h := hdrhistogram.New(1, 10000000, 3)
151 -
152 - for i := 0; i < 1000000; i++ {
153 - if err := h.RecordValue(int64(i)); err != nil {
154 - t.Fatal(err)
155 - }
156 - }
157 -
158 - if v, want := h.Min(), int64(0); v != want {
159 - t.Errorf("Min was %v, but expected %v", v, want)
160 - }
161 -}
162 -
163 -func TestByteSize(t *testing.T) {
164 - h := hdrhistogram.New(1, 100000, 3)
165 -
166 - if v, want := h.ByteSize(), 65604; v != want {
167 - t.Errorf("ByteSize was %v, but expected %d", v, want)
168 - }
169 -}
170 -
171 -func TestRecordCorrectedValue(t *testing.T) {
172 - h := hdrhistogram.New(1, 100000, 3)
173 -
174 - if err := h.RecordCorrectedValue(10, 100); err != nil {
175 - t.Fatal(err)
176 - }
177 -
178 - if v, want := h.ValueAtQuantile(75), int64(10); v != want {
179 - t.Errorf("Corrected value was %v, but expected %v", v, want)
180 - }
181 -}
182 -
183 -func TestRecordCorrectedValueStall(t *testing.T) {
184 - h := hdrhistogram.New(1, 100000, 3)
185 -
186 - if err := h.RecordCorrectedValue(1000, 100); err != nil {
187 - t.Fatal(err)
188 - }
189 -
190 - if v, want := h.ValueAtQuantile(75), int64(800); v != want {
191 - t.Errorf("Corrected value was %v, but expected %v", v, want)
192 - }
193 -}
194 -
195 -func TestCumulativeDistribution(t *testing.T) {
196 - h := hdrhistogram.New(1, 100000000, 3)
197 -
198 - for i := 0; i < 1000000; i++ {
199 - if err := h.RecordValue(int64(i)); err != nil {
200 - t.Fatal(err)
201 - }
202 - }
203 -
204 - actual := h.CumulativeDistribution()
205 - expected := []hdrhistogram.Bracket{
206 - hdrhistogram.Bracket{Quantile: 0, Count: 1, ValueAt: 0},
207 - hdrhistogram.Bracket{Quantile: 50, Count: 500224, ValueAt: 500223},
208 - hdrhistogram.Bracket{Quantile: 75, Count: 750080, ValueAt: 750079},
209 - hdrhistogram.Bracket{Quantile: 87.5, Count: 875008, ValueAt: 875007},
210 - hdrhistogram.Bracket{Quantile: 93.75, Count: 937984, ValueAt: 937983},
211 - hdrhistogram.Bracket{Quantile: 96.875, Count: 969216, ValueAt: 969215},
212 - hdrhistogram.Bracket{Quantile: 98.4375, Count: 984576, ValueAt: 984575},
213 - hdrhistogram.Bracket{Quantile: 99.21875, Count: 992256, ValueAt: 992255},
214 - hdrhistogram.Bracket{Quantile: 99.609375, Count: 996352, ValueAt: 996351},
215 - hdrhistogram.Bracket{Quantile: 99.8046875, Count: 998400, ValueAt: 998399},
216 - hdrhistogram.Bracket{Quantile: 99.90234375, Count: 999424, ValueAt: 999423},
217 - hdrhistogram.Bracket{Quantile: 99.951171875, Count: 999936, ValueAt: 999935},
218 - hdrhistogram.Bracket{Quantile: 99.9755859375, Count: 999936, ValueAt: 999935},
219 - hdrhistogram.Bracket{Quantile: 99.98779296875, Count: 999936, ValueAt: 999935},
220 - hdrhistogram.Bracket{Quantile: 99.993896484375, Count: 1000000, ValueAt: 1000447},
221 - hdrhistogram.Bracket{Quantile: 100, Count: 1000000, ValueAt: 1000447},
222 - }
223 -
224 - if !reflect.DeepEqual(actual, expected) {
225 - t.Errorf("CF was %#v, but expected %#v", actual, expected)
226 - }
227 -}
228 -
229 -func BenchmarkHistogramRecordValue(b *testing.B) {
230 - h := hdrhistogram.New(1, 10000000, 3)
231 - for i := 0; i < 1000000; i++ {
232 - if err := h.RecordValue(int64(i)); err != nil {
233 - b.Fatal(err)
234 - }
235 - }
236 - b.ResetTimer()
237 - b.ReportAllocs()
238 -
239 - for i := 0; i < b.N; i++ {
240 - h.RecordValue(100)
241 - }
242 -}
243 -
244 -func BenchmarkNew(b *testing.B) {
245 - b.ReportAllocs()
246 -
247 - for i := 0; i < b.N; i++ {
248 - hdrhistogram.New(1, 120000, 3) // this could track 1ms-2min
249 - }
250 -}
251 -
252 -func TestUnitMagnitudeOverflow(t *testing.T) {
253 - h := hdrhistogram.New(0, 200, 4)
254 - if err := h.RecordValue(11); err != nil {
255 - t.Fatal(err)
256 - }
257 -}
258 -
259 -func TestSubBucketMaskOverflow(t *testing.T) {
260 - hist := hdrhistogram.New(2e7, 1e8, 5)
261 - for _, sample := range [...]int64{1e8, 2e7, 3e7} {
262 - hist.RecordValue(sample)
263 - }
264 -
265 - for q, want := range map[float64]int64{
266 - 50: 33554431,
267 - 83.33: 33554431,
268 - 83.34: 100663295,
269 - 99: 100663295,
270 - } {
271 - if got := hist.ValueAtQuantile(q); got != want {
272 - t.Errorf("got %d for %fth percentile. want: %d", got, q, want)
273 - }
274 - }
275 -}
276 -
277 -func TestExportImport(t *testing.T) {
278 - min := int64(1)
279 - max := int64(10000000)
280 - sigfigs := 3
281 - h := hdrhistogram.New(min, max, sigfigs)
282 - for i := 0; i < 1000000; i++ {
283 - if err := h.RecordValue(int64(i)); err != nil {
284 - t.Fatal(err)
285 - }
286 - }
287 -
288 - s := h.Export()
289 -
290 - if v := s.LowestTrackableValue; v != min {
291 - t.Errorf("LowestTrackableValue was %v, but expected %v", v, min)
292 - }
293 -
294 - if v := s.HighestTrackableValue; v != max {
295 - t.Errorf("HighestTrackableValue was %v, but expected %v", v, max)
296 - }
297 -
298 - if v := int(s.SignificantFigures); v != sigfigs {
299 - t.Errorf("SignificantFigures was %v, but expected %v", v, sigfigs)
300 - }
301 -
302 - if imported := hdrhistogram.Import(s); !imported.Equals(h) {
303 - t.Error("Expected Histograms to be equivalent")
304 - }
305 -
306 -}
307 -
308 -func TestEquals(t *testing.T) {
309 - h1 := hdrhistogram.New(1, 10000000, 3)
310 - for i := 0; i < 1000000; i++ {
311 - if err := h1.RecordValue(int64(i)); err != nil {
312 - t.Fatal(err)
313 - }
314 - }
315 -
316 - h2 := hdrhistogram.New(1, 10000000, 3)
317 - for i := 0; i < 10000; i++ {
318 - if err := h1.RecordValue(int64(i)); err != nil {
319 - t.Fatal(err)
320 - }
321 - }
322 -
323 - if h1.Equals(h2) {
324 - t.Error("Expected Histograms to not be equivalent")
325 - }
326 -
327 - h1.Reset()
328 - h2.Reset()
329 -
330 - if !h1.Equals(h2) {
331 - t.Error("Expected Histograms to be equivalent")
332 - }
333 -}
Godeps/_workspace/src/github.com/codahale/hdrhistogram/window.go deleted
-45
@@ -1,45 +0,0 @@
1 -package hdrhistogram
2 -
3 -// A WindowedHistogram combines histograms to provide windowed statistics.
4 -type WindowedHistogram struct {
5 - idx int
6 - h []Histogram
7 - m *Histogram
8 -
9 - Current *Histogram
10 -}
11 -
12 -// NewWindowed creates a new WindowedHistogram with N underlying histograms with
13 -// the given parameters.
14 -func NewWindowed(n int, minValue, maxValue int64, sigfigs int) *WindowedHistogram {
15 - w := WindowedHistogram{
16 - idx: -1,
17 - h: make([]Histogram, n),
18 - m: New(minValue, maxValue, sigfigs),
19 - }
20 -
21 - for i := range w.h {
22 - w.h[i] = *New(minValue, maxValue, sigfigs)
23 - }
24 - w.Rotate()
25 -
26 - return &w
27 -}
28 -
29 -// Merge returns a histogram which includes the recorded values from all the
30 -// sections of the window.
31 -func (w *WindowedHistogram) Merge() *Histogram {
32 - w.m.Reset()
33 - for _, h := range w.h {
34 - w.m.Merge(&h)
35 - }
36 - return w.m
37 -}
38 -
39 -// Rotate resets the oldest histogram and rotates it to be used as the current
40 -// histogram.
41 -func (w *WindowedHistogram) Rotate() {
42 - w.idx++
43 - w.Current = &w.h[w.idx%len(w.h)]
44 - w.Current.Reset()
45 -}
Godeps/_workspace/src/github.com/codahale/hdrhistogram/window_test.go deleted
-64
@@ -1,64 +0,0 @@
1 -package hdrhistogram_test
2 -
3 -import (
4 - "testing"
5 -
6 - "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/codahale/hdrhistogram"
7 -)
8 -
9 -func TestWindowedHistogram(t *testing.T) {
10 - w := hdrhistogram.NewWindowed(2, 1, 1000, 3)
11 -
12 - for i := 0; i < 100; i++ {
13 - w.Current.RecordValue(int64(i))
14 - }
15 - w.Rotate()
16 -
17 - for i := 100; i < 200; i++ {
18 - w.Current.RecordValue(int64(i))
19 - }
20 - w.Rotate()
21 -
22 - for i := 200; i < 300; i++ {
23 - w.Current.RecordValue(int64(i))
24 - }
25 -
26 - if v, want := w.Merge().ValueAtQuantile(50), int64(199); v != want {
27 - t.Errorf("Median was %v, but expected %v", v, want)
28 - }
29 -}
30 -
31 -func BenchmarkWindowedHistogramRecordAndRotate(b *testing.B) {
32 - w := hdrhistogram.NewWindowed(3, 1, 10000000, 3)
33 - b.ReportAllocs()
34 - b.ResetTimer()
35 -
36 - for i := 0; i < b.N; i++ {
37 - if err := w.Current.RecordValue(100); err != nil {
38 - b.Fatal(err)
39 - }
40 -
41 - if i%100000 == 1 {
42 - w.Rotate()
43 - }
44 - }
45 -}
46 -
47 -func BenchmarkWindowedHistogramMerge(b *testing.B) {
48 - w := hdrhistogram.NewWindowed(3, 1, 10000000, 3)
49 - for i := 0; i < 10000000; i++ {
50 - if err := w.Current.RecordValue(100); err != nil {
51 - b.Fatal(err)
52 - }
53 -
54 - if i%100000 == 1 {
55 - w.Rotate()
56 - }
57 - }
58 - b.ReportAllocs()
59 - b.ResetTimer()
60 -
61 - for i := 0; i < b.N; i++ {
62 - w.Merge()
63 - }
64 -}