-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
52 lines (44 loc) · 1.35 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"flag"
"fmt"
"os"
"github.com/pkg/profile"
)
var (
engine = flag.String("e", "bitcask", "database engine name. pogreb, goleveldb, bbolt, badger, or bitcask")
numKeys = flag.Int("n", 100000, "number of keys")
minKeySize = flag.Int("mink", 16, "minimum key size")
maxKeySize = flag.Int("maxk", 64, "maximum key size")
minValueSize = flag.Int("minv", 128, "minimum value size")
maxValueSize = flag.Int("maxv", 512, "maximum value size")
concurrency = flag.Int("c", 1, "number of concurrent goroutines")
dir = flag.String("d", "", "database directory")
progress = flag.Bool("p", false, "show progress")
profileMode = flag.String("profile", "", "enable profile. cpu, mem, block or mutex")
)
func main() {
flag.Parse()
if *dir == "" {
flag.Usage()
return
}
err := os.MkdirAll(*dir, 0755)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
switch *profileMode {
case "cpu":
defer profile.Start(profile.CPUProfile).Stop()
case "mem":
defer profile.Start(profile.MemProfile).Stop()
case "block":
defer profile.Start(profile.BlockProfile).Stop()
case "mutex":
defer profile.Start(profile.MutexProfile).Stop()
}
if err := benchmark(*engine, *dir, *numKeys, *minKeySize, *maxKeySize, *minValueSize, *maxValueSize, *concurrency, *progress); err != nil {
fmt.Fprintln(os.Stderr, err)
}
}