aboutsummaryrefslogtreecommitdiff
path: root/cmd/bolt
diff options
context:
space:
mode:
authorMartin Kobetic <mkobetic@gmail.com>2014-05-13 17:28:17 +0000
committerMartin Kobetic <mkobetic@gmail.com>2014-05-13 17:28:17 +0000
commit6eaeb31424c5cf7dae9dff104b33d166b9f4cdc3 (patch)
treeb1f9ead73ea6449335d1b6a4752a5240b2943da8 /cmd/bolt
parentundo page.go changes (diff)
downloaddedo-6eaeb31424c5cf7dae9dff104b33d166b9f4cdc3.tar.gz
dedo-6eaeb31424c5cf7dae9dff104b33d166b9f4cdc3.tar.xz
address review comments
Diffstat (limited to 'cmd/bolt')
-rw-r--r--cmd/bolt/stats.go17
-rw-r--r--cmd/bolt/stats_test.go43
2 files changed, 47 insertions, 13 deletions
diff --git a/cmd/bolt/stats.go b/cmd/bolt/stats.go
index 6968273..54a0f44 100644
--- a/cmd/bolt/stats.go
+++ b/cmd/bolt/stats.go
@@ -46,17 +46,26 @@ func Stats(path, prefix string) {
println("Page size utilization")
printf("\tBytes allocated for physical branch pages: %d\n", s.BranchAlloc)
- percentage := int(float32(s.BranchInuse) * 100.0 / float32(s.BranchAlloc))
+ var percentage int
+ if s.BranchAlloc != 0 {
+ percentage = int(float32(s.BranchInuse) * 100.0 / float32(s.BranchAlloc))
+ }
printf("\tBytes actually used for branch data: %d (%d%%)\n", s.BranchInuse, percentage)
printf("\tBytes allocated for physical leaf pages: %d\n", s.LeafAlloc)
- percentage = int(float32(s.LeafInuse) * 100.0 / float32(s.LeafAlloc))
+ percentage = 0
+ if s.LeafAlloc != 0 {
+ percentage = int(float32(s.LeafInuse) * 100.0 / float32(s.LeafAlloc))
+ }
printf("\tBytes actually used for leaf data: %d (%d%%)\n", s.LeafInuse, percentage)
- println("Bucket statistics ")
+ println("Bucket statistics")
printf("\tTotal number of buckets: %d\n", s.BucketN)
percentage = int(float32(s.InlineBucketN) * 100.0 / float32(s.BucketN))
printf("\tTotal number on inlined buckets: %d (%d%%)\n", s.InlineBucketN, percentage)
- percentage = int(float32(s.InlineBucketInuse) * 100.0 / float32(s.LeafInuse))
+ percentage = 0
+ if s.LeafInuse != 0 {
+ percentage = int(float32(s.InlineBucketInuse) * 100.0 / float32(s.LeafInuse))
+ }
printf("\tBytes used for inlined buckets: %d (%d%%)\n", s.InlineBucketInuse, percentage)
return nil
diff --git a/cmd/bolt/stats_test.go b/cmd/bolt/stats_test.go
index 9662f09..2ad5d51 100644
--- a/cmd/bolt/stats_test.go
+++ b/cmd/bolt/stats_test.go
@@ -1,6 +1,8 @@
package main_test
import (
+ "os"
+ "strconv"
"testing"
"github.com/boltdb/bolt"
@@ -9,12 +11,31 @@ import (
)
func TestStats(t *testing.T) {
+ if os.Getpagesize() != 4096 {
+ t.Skip()
+ }
SetTestMode(true)
open(func(db *bolt.DB, path string) {
db.Update(func(tx *bolt.Tx) error {
- tx.CreateBucket([]byte("foo"))
- tx.CreateBucket([]byte("bar"))
- tx.CreateBucket([]byte("baz"))
+ b, err := tx.CreateBucket([]byte("foo"))
+ if err != nil {
+ return err
+ }
+ for i := 0; i < 10; i++ {
+ b.Put([]byte(strconv.Itoa(i)), []byte(strconv.Itoa(i)))
+ }
+ b, err = tx.CreateBucket([]byte("bar"))
+ if err != nil {
+ return err
+ }
+ for i := 0; i < 100; i++ {
+ b.Put([]byte(strconv.Itoa(i)), []byte(strconv.Itoa(i)))
+ }
+ b, err = tx.CreateBucket([]byte("baz"))
+ if err != nil {
+ return err
+ }
+ b.Put([]byte("key"), []byte("value"))
return nil
})
db.Close()
@@ -23,15 +44,19 @@ func TestStats(t *testing.T) {
"Page count statistics\n"+
"\tNumber of logical branch pages: 0\n"+
"\tNumber of physical branch overflow pages: 0\n"+
- "\tNumber of logical leaf pages: 2\n"+
+ "\tNumber of logical leaf pages: 1\n"+
"\tNumber of physical leaf overflow pages: 0\n"+
"Tree statistics\n"+
- "\tNumber of keys/value pairs: 0\n"+
- "\tNumber of levels in B+tree: 0\n"+
+ "\tNumber of keys/value pairs: 101\n"+
+ "\tNumber of levels in B+tree: 1\n"+
"Page size utilization\n"+
"\tBytes allocated for physical branch pages: 0\n"+
- "\tBytes actually used for branch data: 0\n"+
- "\tBytes allocated for physical leaf pages: 8192\n"+
- "\tBytes actually used for leaf data: 0", output)
+ "\tBytes actually used for branch data: 0 (0%)\n"+
+ "\tBytes allocated for physical leaf pages: 4096\n"+
+ "\tBytes actually used for leaf data: 1996 (48%)\n"+
+ "Bucket statistics\n"+
+ "\tTotal number of buckets: 2\n"+
+ "\tTotal number on inlined buckets: 1 (50%)\n"+
+ "\tBytes used for inlined buckets: 40 (2%)", output)
})
}