Skip to content

Commit

Permalink
Add option to show badger logs in write benchmark tool (#967)
Browse files Browse the repository at this point in the history
The current implementation of write benchmark tool doesn't show any logs
from badger. This commits adds a `--logs` flag which allows the user to
enable badger logs.
  • Loading branch information
Ibrahim Jarif authored Aug 7, 2019
1 parent 8783134 commit e843141
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions badger/cmd/write_bench.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ performance analysis.
}

var (
keySz int
valSz int
numKeys float64
force bool
sorted bool
keySz int
valSz int
numKeys float64
force bool
sorted bool
showLogs bool

sizeWritten uint64
entriesWritten uint64
Expand All @@ -67,6 +68,7 @@ func init() {
writeBenchCmd.Flags().BoolVarP(&force, "force-compact", "f", true,
"Force compact level 0 on close.")
writeBenchCmd.Flags().BoolVarP(&sorted, "sorted", "s", false, "Write keys in sorted order.")
writeBenchCmd.Flags().BoolVarP(&showLogs, "logs", "l", false, "Show Badger logs.")
}

func writeRandom(db *badger.DB, num uint64) error {
Expand Down Expand Up @@ -155,12 +157,17 @@ func writeSorted(db *badger.DB, num uint64) error {
}

func writeBench(cmd *cobra.Command, args []string) error {
db, err := badger.Open(badger.DefaultOptions(sstDir).
opt := badger.DefaultOptions(sstDir).
WithValueDir(vlogDir).
WithTruncate(truncate).
WithSyncWrites(false).
WithCompactL0OnClose(force).
WithLogger(nil))
WithCompactL0OnClose(force)

if !showLogs {
opt = opt.WithLogger(nil)
}

db, err := badger.Open(opt)
if err != nil {
return err
}
Expand Down

0 comments on commit e843141

Please sign in to comment.