diff options
Diffstat (limited to 'bucket.go')
-rw-r--r-- | bucket.go | 40 |
1 files changed, 28 insertions, 12 deletions
@@ -331,20 +331,31 @@ func (b *Bucket) ForEach(fn func(k, v []byte) error) error { // Stat returns stats on a bucket. func (b *Bucket) Stat() *BucketStat { s := &BucketStat{} + pageSize := b.tx.db.pageSize b.tx.forEachPage(b.root, 0, func(p *page, depth int) { if (p.flags & leafPageFlag) != 0 { - s.LeafPageCount++ - s.KeyCount += int(p.count) + s.LeafPageN++ + s.KeyN += int(p.count) + lastElement := p.leafPageElement(p.count - 1) + used := pageHeaderSize + (leafPageElementSize * int(p.count-1)) + used += int(lastElement.pos + lastElement.ksize + lastElement.vsize) + s.LeafInuse += used + s.LeafOverflowN += int(p.overflow) } else if (p.flags & branchPageFlag) != 0 { - s.BranchPageCount++ + s.BranchPageN++ + lastElement := p.branchPageElement(p.count - 1) + used := pageHeaderSize + (branchPageElementSize * int(p.count-1)) + used += int(lastElement.pos + lastElement.ksize) + s.BranchInuse += used + s.BranchOverflowN += int(p.overflow) } - s.OverflowPageCount += int(p.overflow) - - if depth+1 > s.MaxDepth { - s.MaxDepth = (depth + 1) + if depth+1 > s.Depth { + s.Depth = (depth + 1) } }) + s.BranchAlloc = (s.BranchPageN + s.BranchOverflowN) * pageSize + s.LeafAlloc = (s.LeafPageN + s.LeafOverflowN) * pageSize return s } @@ -506,9 +517,14 @@ func (b *Bucket) pageNode(id pgid) (*page, *node) { // BucketStat represents stats on a bucket such as branch pages and leaf pages. type BucketStat struct { - BranchPageCount int - LeafPageCount int - OverflowPageCount int - KeyCount int - MaxDepth int + BranchPageN int + BranchOverflowN int + LeafPageN int + LeafOverflowN int + KeyN int + Depth int + BranchAlloc int + BranchInuse int + LeafAlloc int + LeafInuse int } |