aboutsummaryrefslogtreecommitdiff
path: root/bucket.go
diff options
context:
space:
mode:
authorMartin Kobetic <mkobetic@gmail.com>2014-05-09 18:16:38 +0000
committerMartin Kobetic <mkobetic@gmail.com>2014-05-09 20:50:58 +0000
commitc4ad027df774d84c29c9cc53436071c87138c60d (patch)
treef2a26eeea973f9fe25a7f4957361052563175a80 /bucket.go
parentfirst part (diff)
downloaddedo-c4ad027df774d84c29c9cc53436071c87138c60d.tar.gz
dedo-c4ad027df774d84c29c9cc53436071c87138c60d.tar.xz
aggregate bucket stats recursively and add stats to cmd
Diffstat (limited to 'bucket.go')
-rw-r--r--bucket.go12
1 files changed, 8 insertions, 4 deletions
diff --git a/bucket.go b/bucket.go
index 41156d7..6f7bbd2 100644
--- a/bucket.go
+++ b/bucket.go
@@ -366,6 +366,9 @@ func (b *Bucket) Stats() BucketStats {
b.forEachPage(func(p *page, depth int) {
if (p.flags & leafPageFlag) != 0 {
s.LeafPageN++
+ if p.count == 0 {
+ return
+ }
s.KeyN += int(p.count)
lastElement := p.leafPageElement(p.count - 1)
used := pageHeaderSize + (leafPageElementSize * int(p.count-1))
@@ -373,9 +376,10 @@ func (b *Bucket) Stats() BucketStats {
s.LeafInuse += used
s.LeafOverflowN += int(p.overflow)
- // Recurse into sub-buckets
- for _, e := range p.leafPageElements() {
- if e.flags&bucketLeafFlag != 0 {
+ // Collect stats from sub-buckets
+ for i := uint16(0); i < p.count; i++ {
+ e := p.leafPageElement(i)
+ if (e.flags & bucketLeafFlag) != 0 {
subStats.Add(b.openBucket(e.value()).Stats())
}
}
@@ -666,7 +670,7 @@ func (s *BucketStats) Add(other BucketStats) {
s.BranchOverflowN += other.BranchOverflowN
s.LeafPageN += other.LeafPageN
s.LeafOverflowN += other.LeafOverflowN
- s.KeyN += s.KeyN
+ s.KeyN += other.KeyN
if s.Depth < other.Depth {
s.Depth = other.Depth
}