diff options
author | Martin Kobetic <mkobetic@gmail.com> | 2014-05-09 20:50:55 +0000 |
---|---|---|
committer | Martin Kobetic <mkobetic@gmail.com> | 2014-05-09 20:50:55 +0000 |
commit | b9899d09ab6c032b54fe4a09e9389dff28d8a7f8 (patch) | |
tree | 30a0bdbcd865fd26bbb268afab23f3f68d3f692a /cmd/bolt | |
parent | Merge pull request #160 from benbjohnson/fix-deletion (diff) | |
download | dedo-b9899d09ab6c032b54fe4a09e9389dff28d8a7f8.tar.gz dedo-b9899d09ab6c032b54fe4a09e9389dff28d8a7f8.tar.xz |
first part
Diffstat (limited to 'cmd/bolt')
-rw-r--r-- | cmd/bolt/main.go | 8 | ||||
-rw-r--r-- | cmd/bolt/stats.go | 54 |
2 files changed, 62 insertions, 0 deletions
diff --git a/cmd/bolt/main.go b/cmd/bolt/main.go index 3397042..659f1c3 100644 --- a/cmd/bolt/main.go +++ b/cmd/bolt/main.go @@ -92,6 +92,14 @@ func NewApp() *cli.App { }, }, { + Name: "stats", + Usage: "Retrieve statistics for a bucket (aggregated recursively)", + Action: func(c *cli.Context) { + path, name := c.Args().Get(0), c.Args().Get(1) + Stats(path, name) + }, + }, + { Name: "bench", Usage: "Performs a synthetic benchmark", Flags: []cli.Flag{ diff --git a/cmd/bolt/stats.go b/cmd/bolt/stats.go new file mode 100644 index 0000000..da344d0 --- /dev/null +++ b/cmd/bolt/stats.go @@ -0,0 +1,54 @@ +package main + +import ( + "os" + + "github.com/boltdb/bolt" +) + +// Keys retrieves a list of keys for a given bucket. +func Stats(path, name string) { + if _, err := os.Stat(path); os.IsNotExist(err) { + fatal(err) + return + } + + db, err := bolt.Open(path, 0600) + if err != nil { + fatal(err) + return + } + defer db.Close() + + err = db.View(func(tx *bolt.Tx) error { + // Find bucket. + b := tx.Bucket([]byte(name)) + if b == nil { + fatalf("bucket not found: %s", name) + return nil + } + + // Iterate over each key. + s := b.Stats() + println("Page count statistics") + printf("\tNumber of logical branch pages: %d\n", s.BranchPageN) + printf("\tNumber of physical branch overflow pages: %d\n", s.BranchOverflowN) + printf("\tNumber of logical leaf pages: %d\n", s.LeafPageN) + printf("\tNumber of physical leaf overflow pages: %d\n", s.LeafOverflowN) + + println("Tree statistics") + printf("\tNumber of keys/value pairs: %d\n", s.KeyN) + printf("\tNumber of levels in B+tree: %d\n", s.Depth) + + println("Page size utilization") + printf("\tBytes allocated for physical branch pages: %d\n", s.BranchAlloc) + printf("\tBytes actually used for branch data: %d\n", s.BranchInuse) + printf("\tBytes allocated for physical leaf pages: %d\n", s.LeafAlloc) + printf("\tBytes actually used for leaf data: %d\n", s.LeafInuse) + return nil + }) + if err != nil { + fatal(err) + return + } +} |