MCPcopy
hub / github.com/dgraph-io/dgraph / sizeHistogram

Function sizeHistogram

dgraph/cmd/debug/run.go:782–821  ·  view source on GitHub ↗
(db *badger.DB)

Source from the content-addressed store, hash-verified

780}
781
782func 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
823func printAlphaProposal(buf *bytes.Buffer, pr *pb.Proposal, pending map[uint64]bool) {
824 if pr == nil {

Callers 1

runFunction · 0.85

Calls 11

UpdateMethod · 0.95
PrintHistogramMethod · 0.95
PredicatePrefixFunction · 0.92
getHistogramBoundsFunction · 0.85
NewHistogramDataFunction · 0.85
NewIteratorMethod · 0.80
SeekMethod · 0.80
ItemMethod · 0.80
CloseMethod · 0.65
NextMethod · 0.45
KeyMethod · 0.45

Tested by

no test coverage detected