diff options
Diffstat (limited to 'bucket.go')
-rw-r--r-- | bucket.go | 26 |
1 files changed, 23 insertions, 3 deletions
@@ -371,23 +371,36 @@ func (b *Bucket) Stats() BucketStats { b.forEachPage(func(p *page, depth int) { if (p.flags & leafPageFlag) != 0 { s.KeyN += int(p.count) + // used totals the used bytes for the page used := pageHeaderSize if p.count != 0 { + // If page has any elements, add all element headers. used += leafPageElementSize * int(p.count-1) + // Add all element key, value sizes. + // The computation takes advantage of the fact that the position + // of the last element's key/value equals to the total of the sizes + // of all previous elements' keys and values. + // It also includes the last element's header. lastElement := p.leafPageElement(p.count - 1) used += int(lastElement.pos + lastElement.ksize + lastElement.vsize) } if b.root == 0 { + // For inlined bucket just update the inline stats s.InlineBucketInuse += used } else { + // For non-inlined bucket update all the leaf stats s.LeafPageN++ s.LeafInuse += used s.LeafOverflowN += int(p.overflow) - // Collect stats from sub-buckets + // Collect stats from sub-buckets. + // Do that by iterating over all element headers + // looking for the ones with the bucketLeafFlag. for i := uint16(0); i < p.count; i++ { e := p.leafPageElement(i) if (e.flags & bucketLeafFlag) != 0 { + // For any bucket element, open the element value + // and recursively call Stats on the contained bucket. subStats.Add(b.openBucket(e.value()).Stats()) } } @@ -395,21 +408,28 @@ func (b *Bucket) Stats() BucketStats { } else if (p.flags & branchPageFlag) != 0 { s.BranchPageN++ lastElement := p.branchPageElement(p.count - 1) + // used totals the used bytes for the page + // Add header and all element headers. used := pageHeaderSize + (branchPageElementSize * int(p.count-1)) + // Add size of all keys and values. + // Again, use the fact that last element's position equals to + // the total of key, value sizes of all previous elements. used += int(lastElement.pos + lastElement.ksize) s.BranchInuse += used s.BranchOverflowN += int(p.overflow) } - + // Keep track of maximum page depth. if depth+1 > s.Depth { s.Depth = (depth + 1) } }) + // Alloc stats can be computed from page counts and pageSize. s.BranchAlloc = (s.BranchPageN + s.BranchOverflowN) * pageSize s.LeafAlloc = (s.LeafPageN + s.LeafOverflowN) * pageSize - // add the max depth of sub-buckets to get total nested depth + // Add the max depth of sub-buckets to get total nested depth. s.Depth += subStats.Depth + // Add the stats for all sub-buckets s.Add(subStats) return s } |