(db *badger.DB)
| 780 | } |
| 781 | |
| 782 | func sizeHistogram(db *badger.DB) { |
| 783 | txn := db.NewTransactionAt(opt.readTs, false) |
| 784 | defer txn.Discard() |
| 785 | |
| 786 | iopts := badger.DefaultIteratorOptions |
| 787 | iopts.PrefetchValues = false |
| 788 | itr := txn.NewIterator(iopts) |
| 789 | defer itr.Close() |
| 790 | |
| 791 | // Generate distribution bounds. Key sizes are not greater than 2^16 while |
| 792 | // value sizes are not greater than 1GB (2^30). |
| 793 | keyBounds := getHistogramBounds(5, 16) |
| 794 | valueBounds := getHistogramBounds(5, 30) |
| 795 | |
| 796 | // Initialize exporter. |
| 797 | keySizeHistogram := NewHistogramData(keyBounds) |
| 798 | valueSizeHistogram := NewHistogramData(valueBounds) |
| 799 | |
| 800 | // Collect key and value sizes. |
| 801 | var prefix []byte |
| 802 | if len(opt.predicate) > 0 { |
| 803 | prefix = x.PredicatePrefix(opt.predicate) |
| 804 | } |
| 805 | var loop int |
| 806 | for itr.Seek(prefix); itr.ValidForPrefix(prefix); itr.Next() { |
| 807 | item := itr.Item() |
| 808 | |
| 809 | keySizeHistogram.Update(int64(len(item.Key()))) |
| 810 | valueSizeHistogram.Update(item.ValueSize()) |
| 811 | |
| 812 | loop++ |
| 813 | } |
| 814 | |
| 815 | fmt.Printf("prefix = %s\n", hex.Dump(prefix)) |
| 816 | fmt.Printf("Found %d keys\n", loop) |
| 817 | fmt.Printf("\nHistogram of key sizes (in bytes)\n") |
| 818 | keySizeHistogram.PrintHistogram() |
| 819 | fmt.Printf("\nHistogram of value sizes (in bytes)\n") |
| 820 | valueSizeHistogram.PrintHistogram() |
| 821 | } |
| 822 | |
| 823 | func printAlphaProposal(buf *bytes.Buffer, pr *pb.Proposal, pending map[uint64]bool) { |
| 824 | if pr == nil { |
no test coverage detected