String returns a string representation of the Histogram.
()
| 168 | |
| 169 | // String returns a string representation of the Histogram. |
| 170 | func (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. |
| 201 | func (h *Histogram) ZeroBucket() Bucket[uint64] { |