Stats returns stats on a bucket.
()
| 612 | |
| 613 | // Stats returns stats on a bucket. |
| 614 | func (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 |
nothing calls this directly
no test coverage detected