NewHistogram returns a pointer to a new Histogram object that was created with the provided options.
(opts HistogramOptions)
| 77 | // NewHistogram returns a pointer to a new Histogram object that was created |
| 78 | // with the provided options. |
| 79 | func NewHistogram(opts HistogramOptions) *Histogram { |
| 80 | if opts.NumBuckets == 0 { |
| 81 | opts.NumBuckets = 32 |
| 82 | } |
| 83 | if opts.BaseBucketSize == 0.0 { |
| 84 | opts.BaseBucketSize = 1.0 |
| 85 | } |
| 86 | h := Histogram{ |
| 87 | Buckets: make([]HistogramBucket, opts.NumBuckets), |
| 88 | Min: math.MaxInt64, |
| 89 | Max: math.MinInt64, |
| 90 | |
| 91 | opts: opts, |
| 92 | logBaseBucketSize: math.Log(opts.BaseBucketSize), |
| 93 | oneOverLogOnePlusGrowthFactor: 1 / math.Log(1+opts.GrowthFactor), |
| 94 | } |
| 95 | m := 1.0 + opts.GrowthFactor |
| 96 | delta := opts.BaseBucketSize |
| 97 | h.Buckets[0].LowBound = float64(opts.MinValue) |
| 98 | for i := 1; i < opts.NumBuckets; i++ { |
| 99 | h.Buckets[i].LowBound = float64(opts.MinValue) + delta |
| 100 | delta = delta * m |
| 101 | } |
| 102 | return &h |
| 103 | } |
| 104 | |
| 105 | // Print writes textual output of the histogram values. |
| 106 | func (h *Histogram) Print(w io.Writer) { |
no test coverage detected