MCPcopy
hub / github.com/grpc/grpc-go / PrintWithUnit

Method PrintWithUnit

benchmark/stats/histogram.go:112–140  ·  view source on GitHub ↗

PrintWithUnit writes textual output of the histogram values . Data in histogram is divided by a Unit before print.

(w io.Writer, unit float64)

Source from the content-addressed store, hash-verified

110// PrintWithUnit writes textual output of the histogram values .
111// Data in histogram is divided by a Unit before print.
112func (h *Histogram) PrintWithUnit(w io.Writer, unit float64) {
113 avg := float64(h.Sum) / float64(h.Count)
114 fmt.Fprintf(w, "Count: %d Min: %5.1f Max: %5.1f Avg: %.2f\n", h.Count, float64(h.Min)/unit, float64(h.Max)/unit, avg/unit)
115 fmt.Fprintf(w, "%s\n", strings.Repeat("-", 60))
116 if h.Count <= 0 {
117 return
118 }
119
120 maxBucketDigitLen := len(strconv.FormatFloat(h.Buckets[len(h.Buckets)-1].LowBound, 'f', 6, 64))
121 maxCountDigitLen := len(strconv.FormatInt(h.Count, 10))
122 percentMulti := 100 / float64(h.Count)
123
124 accCount := int64(0)
125 for i, b := range h.Buckets {
126 fmt.Fprintf(w, "[%*f, ", maxBucketDigitLen, b.LowBound/unit)
127 if i+1 < len(h.Buckets) {
128 fmt.Fprintf(w, "%*f)", maxBucketDigitLen, h.Buckets[i+1].LowBound/unit)
129 } else {
130 upperBound := float64(h.opts.MinValue) + (b.LowBound-float64(h.opts.MinValue))*(1.0+h.opts.GrowthFactor)
131 fmt.Fprintf(w, "%*f)", maxBucketDigitLen, upperBound/unit)
132 }
133 accCount += b.Count
134 fmt.Fprintf(w, " %*d %5.1f%% %5.1f%%", maxCountDigitLen, b.Count, float64(b.Count)*percentMulti, float64(accCount)*percentMulti)
135
136 const barScale = 0.1
137 barLength := int(float64(b.Count)*percentMulti*barScale + 0.5)
138 fmt.Fprintf(w, " %s\n", strings.Repeat("#", barLength))
139 }
140}
141
142// String returns the textual output of the histogram values as string.
143func (h *Histogram) String() string {

Callers 2

PrintMethod · 0.95
dumpMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected