MCPcopy
hub / github.com/prometheus/prometheus / String

Method String

model/histogram/histogram.go:170–198  ·  view source on GitHub ↗

String returns a string representation of the Histogram.

()

Source from the content-addressed store, hash-verified

168
169// String returns a string representation of the Histogram.
170func (h *Histogram) String() string {
171 var sb strings.Builder
172 fmt.Fprintf(&sb, "{count:%d, sum:%g", h.Count, h.Sum)
173
174 var nBuckets []Bucket[uint64]
175 for it := h.NegativeBucketIterator(); it.Next(); {
176 bucket := it.At()
177 if bucket.Count != 0 {
178 nBuckets = append(nBuckets, it.At())
179 }
180 }
181 for i := len(nBuckets) - 1; i >= 0; i-- {
182 fmt.Fprintf(&sb, ", %s", nBuckets[i].String())
183 }
184
185 if h.ZeroCount != 0 {
186 fmt.Fprintf(&sb, ", %s", h.ZeroBucket().String())
187 }
188
189 for it := h.PositiveBucketIterator(); it.Next(); {
190 bucket := it.At()
191 if bucket.Count != 0 {
192 fmt.Fprintf(&sb, ", %s", bucket.String())
193 }
194 }
195
196 sb.WriteRune('}')
197 return sb.String()
198}
199
200// ZeroBucket returns the zero bucket. This method panics if the schema is for custom buckets.
201func (h *Histogram) ZeroBucket() Bucket[uint64] {

Callers 2

TestHistogramToFloatFunction · 0.95

Calls 6

ZeroBucketMethod · 0.95
NextMethod · 0.65
AtMethod · 0.65
StringMethod · 0.65

Tested by 2

TestHistogramToFloatFunction · 0.76