PrintHistogram prints the histogram data in a human-readable format.
()
| 745 | |
| 746 | // PrintHistogram prints the histogram data in a human-readable format. |
| 747 | func (histogram *HistogramData) PrintHistogram() { |
| 748 | if histogram == nil { |
| 749 | return |
| 750 | } |
| 751 | |
| 752 | fmt.Printf("Min value: %d\n", histogram.Min) |
| 753 | fmt.Printf("Max value: %d\n", histogram.Max) |
| 754 | fmt.Printf("Mean: %.2f\n", float64(histogram.Sum)/float64(histogram.Count)) |
| 755 | fmt.Printf("%24s %9s\n", "Range", "Count") |
| 756 | |
| 757 | numBounds := len(histogram.Bounds) |
| 758 | for index, count := range histogram.CountPerBucket { |
| 759 | if count == 0 { |
| 760 | continue |
| 761 | } |
| 762 | |
| 763 | // The last bucket represents the bucket that contains the range from |
| 764 | // the last bound up to infinity so it's processed differently than the |
| 765 | // other buckets. |
| 766 | if index == len(histogram.CountPerBucket)-1 { |
| 767 | lowerBound := int(histogram.Bounds[numBounds-1]) |
| 768 | fmt.Printf("[%10d, %10s) %9d\n", lowerBound, "infinity", count) |
| 769 | continue |
| 770 | } |
| 771 | |
| 772 | upperBound := int(histogram.Bounds[index]) |
| 773 | lowerBound := 0 |
| 774 | if index > 0 { |
| 775 | lowerBound = int(histogram.Bounds[index-1]) |
| 776 | } |
| 777 | |
| 778 | fmt.Printf("[%10d, %10d) %9d\n", lowerBound, upperBound, count) |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | func sizeHistogram(db *badger.DB) { |
| 783 | txn := db.NewTransactionAt(opt.readTs, false) |