mirror of https://github.com/etcd-io/bbolt.git
allign naming with MemStats
parent
62592ec840
commit
4245fd9c4e
34
bucket.go
34
bucket.go
|
@ -334,28 +334,28 @@ func (b *Bucket) Stat() *BucketStat {
|
||||||
pageSize := b.tx.db.pageSize
|
pageSize := b.tx.db.pageSize
|
||||||
b.tx.forEachPage(b.root, 0, func(p *page, depth int) {
|
b.tx.forEachPage(b.root, 0, func(p *page, depth int) {
|
||||||
if (p.flags & leafPageFlag) != 0 {
|
if (p.flags & leafPageFlag) != 0 {
|
||||||
s.LeafPageCount++
|
s.LeafPageN++
|
||||||
s.KeyCount += int(p.count)
|
s.KeyN += int(p.count)
|
||||||
lastElement := p.leafPageElement(p.count - 1)
|
lastElement := p.leafPageElement(p.count - 1)
|
||||||
used := pageHeaderSize + (leafPageElementSize * int(p.count-1))
|
used := pageHeaderSize + (leafPageElementSize * int(p.count-1))
|
||||||
used += int(lastElement.pos + lastElement.ksize + lastElement.vsize)
|
used += int(lastElement.pos + lastElement.ksize + lastElement.vsize)
|
||||||
s.LeafInuse += used
|
s.LeafInuse += used
|
||||||
s.LeafOverflowPageCount += int(p.overflow)
|
s.LeafOverflowN += int(p.overflow)
|
||||||
} else if (p.flags & branchPageFlag) != 0 {
|
} else if (p.flags & branchPageFlag) != 0 {
|
||||||
s.BranchPageCount++
|
s.BranchPageN++
|
||||||
lastElement := p.branchPageElement(p.count - 1)
|
lastElement := p.branchPageElement(p.count - 1)
|
||||||
used := pageHeaderSize + (branchPageElementSize * int(p.count-1))
|
used := pageHeaderSize + (branchPageElementSize * int(p.count-1))
|
||||||
used += int(lastElement.pos + lastElement.ksize)
|
used += int(lastElement.pos + lastElement.ksize)
|
||||||
s.BranchInuse += used
|
s.BranchInuse += used
|
||||||
s.BranchOverflowPageCount += int(p.overflow)
|
s.BranchOverflowN += int(p.overflow)
|
||||||
}
|
}
|
||||||
|
|
||||||
if depth+1 > s.MaxDepth {
|
if depth+1 > s.MaxDepth {
|
||||||
s.MaxDepth = (depth + 1)
|
s.MaxDepth = (depth + 1)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
s.BranchAlloc = (s.BranchPageCount + s.BranchOverflowPageCount) * pageSize
|
s.BranchAlloc = (s.BranchPageN + s.BranchOverflowN) * pageSize
|
||||||
s.LeafAlloc = (s.LeafPageCount + s.LeafOverflowPageCount) * pageSize
|
s.LeafAlloc = (s.LeafPageN + s.LeafOverflowN) * pageSize
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -517,14 +517,14 @@ func (b *Bucket) pageNode(id pgid) (*page, *node) {
|
||||||
|
|
||||||
// BucketStat represents stats on a bucket such as branch pages and leaf pages.
|
// BucketStat represents stats on a bucket such as branch pages and leaf pages.
|
||||||
type BucketStat struct {
|
type BucketStat struct {
|
||||||
BranchPageCount int
|
BranchPageN int
|
||||||
BranchOverflowPageCount int
|
BranchOverflowN int
|
||||||
LeafPageCount int
|
LeafPageN int
|
||||||
LeafOverflowPageCount int
|
LeafOverflowN int
|
||||||
KeyCount int
|
KeyN int
|
||||||
MaxDepth int
|
MaxDepth int
|
||||||
BranchAlloc int
|
BranchAlloc int
|
||||||
BranchInuse int
|
BranchInuse int
|
||||||
LeafAlloc int
|
LeafAlloc int
|
||||||
LeafInuse int
|
LeafInuse int
|
||||||
}
|
}
|
||||||
|
|
|
@ -491,11 +491,11 @@ func TestBucket_Stat(t *testing.T) {
|
||||||
db.View(func(tx *Tx) error {
|
db.View(func(tx *Tx) error {
|
||||||
b := tx.Bucket([]byte("woojits"))
|
b := tx.Bucket([]byte("woojits"))
|
||||||
stat := b.Stat()
|
stat := b.Stat()
|
||||||
assert.Equal(t, stat.BranchPageCount, 1)
|
assert.Equal(t, stat.BranchPageN, 1)
|
||||||
assert.Equal(t, stat.BranchOverflowPageCount, 0)
|
assert.Equal(t, stat.BranchOverflowN, 0)
|
||||||
assert.Equal(t, stat.LeafPageCount, 6)
|
assert.Equal(t, stat.LeafPageN, 6)
|
||||||
assert.Equal(t, stat.LeafOverflowPageCount, 2)
|
assert.Equal(t, stat.LeafOverflowN, 2)
|
||||||
assert.Equal(t, stat.KeyCount, 501)
|
assert.Equal(t, stat.KeyN, 501)
|
||||||
assert.Equal(t, stat.MaxDepth, 2)
|
assert.Equal(t, stat.MaxDepth, 2)
|
||||||
assert.Equal(t, stat.BranchInuse, 125)
|
assert.Equal(t, stat.BranchInuse, 125)
|
||||||
assert.Equal(t, stat.BranchAlloc, 4096)
|
assert.Equal(t, stat.BranchAlloc, 4096)
|
||||||
|
@ -522,11 +522,11 @@ func TestBucket_Stat_Small(t *testing.T) {
|
||||||
db.View(func(tx *Tx) error {
|
db.View(func(tx *Tx) error {
|
||||||
b := tx.Bucket([]byte("whozawhats"))
|
b := tx.Bucket([]byte("whozawhats"))
|
||||||
stat := b.Stat()
|
stat := b.Stat()
|
||||||
assert.Equal(t, stat.BranchPageCount, 0)
|
assert.Equal(t, stat.BranchPageN, 0)
|
||||||
assert.Equal(t, stat.BranchOverflowPageCount, 0)
|
assert.Equal(t, stat.BranchOverflowN, 0)
|
||||||
assert.Equal(t, stat.LeafPageCount, 1)
|
assert.Equal(t, stat.LeafPageN, 1)
|
||||||
assert.Equal(t, stat.LeafOverflowPageCount, 0)
|
assert.Equal(t, stat.LeafOverflowN, 0)
|
||||||
assert.Equal(t, stat.KeyCount, 1)
|
assert.Equal(t, stat.KeyN, 1)
|
||||||
assert.Equal(t, stat.MaxDepth, 1)
|
assert.Equal(t, stat.MaxDepth, 1)
|
||||||
assert.Equal(t, stat.BranchInuse, 0)
|
assert.Equal(t, stat.BranchInuse, 0)
|
||||||
assert.Equal(t, stat.BranchAlloc, 0)
|
assert.Equal(t, stat.BranchAlloc, 0)
|
||||||
|
@ -558,11 +558,11 @@ func TestBucket_Stat_Large(t *testing.T) {
|
||||||
db.View(func(tx *Tx) error {
|
db.View(func(tx *Tx) error {
|
||||||
b := tx.Bucket([]byte("widgets"))
|
b := tx.Bucket([]byte("widgets"))
|
||||||
stat := b.Stat()
|
stat := b.Stat()
|
||||||
assert.Equal(t, stat.BranchPageCount, 15)
|
assert.Equal(t, stat.BranchPageN, 15)
|
||||||
assert.Equal(t, stat.BranchOverflowPageCount, 0)
|
assert.Equal(t, stat.BranchOverflowN, 0)
|
||||||
assert.Equal(t, stat.LeafPageCount, 1281)
|
assert.Equal(t, stat.LeafPageN, 1281)
|
||||||
assert.Equal(t, stat.LeafOverflowPageCount, 0)
|
assert.Equal(t, stat.LeafOverflowN, 0)
|
||||||
assert.Equal(t, stat.KeyCount, 100000)
|
assert.Equal(t, stat.KeyN, 100000)
|
||||||
assert.Equal(t, stat.MaxDepth, 3)
|
assert.Equal(t, stat.MaxDepth, 3)
|
||||||
assert.Equal(t, stat.BranchInuse, 27289)
|
assert.Equal(t, stat.BranchInuse, 27289)
|
||||||
assert.Equal(t, stat.BranchAlloc, 61440)
|
assert.Equal(t, stat.BranchAlloc, 61440)
|
||||||
|
|
Loading…
Reference in New Issue