Skip to content

Commit c881937

Browse files
committed
pretty Usage
1 parent a9d0196 commit c881937

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

benchmark/benchmark.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ const (
99
DBDriverMySQL = "mysql"
1010
DBDriverPgSQL = "pgsql"
1111
DBDriverSpanner = "spanner"
12+
13+
NameOLTPReadOnly = "oltp_read_only"
14+
NameOLTPReadWrite = "oltp_read_write"
1215
)
1316

1417
type (
@@ -38,11 +41,15 @@ func BenchmarkFactory(testname string, opt *BenchmarkOpts) (Benchmark, error) {
3841
opt.TableSize = opt.TableSizeP
3942
}
4043

41-
if testname == "oltp_read_only" {
44+
if testname == NameOLTPReadOnly {
4245
return newOLTPBench(opt, rwModeReadOnly), nil
43-
} else if testname == "oltp_read_write" {
46+
} else if testname == NameOLTPReadWrite {
4447
return newOLTPBench(opt, rwModeReadWrite), nil
4548
}
4649
return nil, fmt.Errorf("Unknown benchmark: %s", testname)
4750

4851
}
52+
53+
func BenchmarkNames() []string {
54+
return []string{NameOLTPReadOnly, NameOLTPReadWrite}
55+
}

cmd/go-sysbench/main.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@ package main
77

88
// 20. PreparedStatement の実装
99

10-
// 40. --mysql-ignore-errors の場合 others にカウントする
10+
// 30. --mysql-ignore-errors の場合 others にカウントする
1111

12-
// 50. README に 日本語を書く
13-
// 51. README に 性能差分について書く
14-
15-
// 71. help に testname を表示
12+
// 40. README に 日本語を書く
13+
// 41. README に 性能差分について書く
1614

1715
import (
1816
"fmt"
19-
"log"
2017
"os"
18+
"strings"
2119

2220
"github.com/jessevdk/go-flags"
2321

@@ -39,10 +37,12 @@ func main() {
3937
opts := CmdOpts{}
4038

4139
parser := flags.NewParser(&opts, flags.HelpFlag|flags.PassDoubleDash)
40+
parser.Usage = fmt.Sprintf("[options]... [%s] [prepare|run]", strings.Join(benchmark.BenchmarkNames(), "|"))
4241

4342
args, err := parser.Parse()
4443
if err != nil {
45-
log.Fatal(err)
44+
fmt.Println(err)
45+
os.Exit(1)
4646
}
4747

4848
if opts.Version {
@@ -62,7 +62,8 @@ func main() {
6262
bench, err := benchmark.BenchmarkFactory(testname, &opts.BenchmarkOpts)
6363

6464
if err != nil {
65-
log.Fatal(err)
65+
fmt.Println(err)
66+
os.Exit(1)
6667
}
6768

6869
if command == "run" {
@@ -72,6 +73,7 @@ func main() {
7273
}
7374

7475
if err != nil {
75-
log.Fatal(err)
76+
fmt.Println(err)
77+
os.Exit(1)
7678
}
7779
}

runner/runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const (
1919
histogramMin = 0.001
2020
histogramMax = 100000
2121

22-
n2m = 1000000.0
22+
n2m = 1000000.0
2323
)
2424

2525
type (

0 commit comments

Comments
 (0)