github.com/zeebo/mon@v0.0.0-20211012163247-13d39bdb54fa/inthist/histogram_debug.go (about) 1 // +build debug 2 3 package inthist 4 5 import ( 6 "fmt" 7 "strings" 8 "sync/atomic" 9 ) 10 11 func (h *Histogram) Bitmap() string { 12 var lines []string 13 for bucket := range h.buckets[:] { 14 b := loadBucket(&h.buckets[bucket]) 15 if b == nil { 16 lines = append(lines, strings.Repeat("0", histEntries)) 17 continue 18 } 19 20 var line []byte 21 for entry := range b.entries[:] { 22 count := atomic.LoadUint32(&b.entries[entry]) 23 if count == 0 { 24 line = append(line, '0') 25 } else { 26 line = append(line, '1') 27 } 28 } 29 lines = append(lines, string(line)) 30 } 31 return strings.Join(lines, "\n") + "\n" 32 } 33 34 func (h *Histogram) Dump() { 35 for bucket := range h.buckets[:] { 36 b := loadBucket(&h.buckets[bucket]) 37 if b == nil { 38 continue 39 } 40 41 for entry := range b.entries[:] { 42 count := atomic.LoadUint32(&b.entries[entry]) 43 if count == 0 { 44 continue 45 } 46 47 fmt.Printf("%d:%d\n", lowerValue(uint64(bucket), uint64(entry)), count) 48 } 49 } 50 }