MCPcopy
hub / github.com/etcd-io/bbolt / Stats

Method Stats

bucket.go:614–697  ·  view source on GitHub ↗

Stats returns stats on a bucket.

()

Source from the content-addressed store, hash-verified

612
613// Stats returns stats on a bucket.
614func (b *Bucket) Stats() BucketStats {
615 var s, subStats BucketStats
616 pageSize := b.tx.db.pageSize
617 s.BucketN += 1
618 if b.RootPage() == 0 {
619 s.InlineBucketN += 1
620 }
621 b.forEachPage(func(p *common.Page, depth int, pgstack []common.Pgid) {
622 if p.IsLeafPage() {
623 s.KeyN += int(p.Count())
624
625 // used totals the used bytes for the page
626 used := common.PageHeaderSize
627
628 if p.Count() != 0 {
629 // If page has any elements, add all element headers.
630 used += common.LeafPageElementSize * uintptr(p.Count()-1)
631
632 // Add all element key, value sizes.
633 // The computation takes advantage of the fact that the position
634 // of the last element's key/value equals to the total of the sizes
635 // of all previous elements' keys and values.
636 // It also includes the last element's header.
637 lastElement := p.LeafPageElement(p.Count() - 1)
638 used += uintptr(lastElement.Pos() + lastElement.Ksize() + lastElement.Vsize())
639 }
640
641 if b.RootPage() == 0 {
642 // For inlined bucket just update the inline stats
643 s.InlineBucketInuse += int(used)
644 } else {
645 // For non-inlined bucket update all the leaf stats
646 s.LeafPageN++
647 s.LeafInuse += int(used)
648 s.LeafOverflowN += int(p.Overflow())
649
650 // Collect stats from sub-buckets.
651 // Do that by iterating over all element headers
652 // looking for the ones with the bucketLeafFlag.
653 for i := uint16(0); i < p.Count(); i++ {
654 e := p.LeafPageElement(i)
655 if (e.Flags() & common.BucketLeafFlag) != 0 {
656 // For any bucket element, open the element value
657 // and recursively call Stats on the contained bucket.
658 subStats.Add(b.openBucket(e.Value()).Stats())
659 }
660 }
661 }
662 } else if p.IsBranchPage() {
663 s.BranchPageN++
664
665 used := common.PageHeaderSize
666 if p.Count() != 0 {
667 lastElement := p.BranchPageElement(p.Count() - 1)
668
669 // Add all element headers.
670 used += common.BranchPageElementSize * uintptr(p.Count()-1)
671

Callers

nothing calls this directly

Calls 15

forEachPageMethod · 0.95
AddMethod · 0.95
openBucketMethod · 0.95
RootPageMethod · 0.80
IsLeafPageMethod · 0.80
LeafPageElementMethod · 0.80
VsizeMethod · 0.80
OverflowMethod · 0.80
IsBranchPageMethod · 0.80
BranchPageElementMethod · 0.80
CountMethod · 0.65
PosMethod · 0.45

Tested by

no test coverage detected