github.com/cockroachdb/pebble@v1.1.1-0.20240513155919-3622ade60459/cmd/pebble/main.go (about) 1 // Copyright 2018 The LevelDB-Go and Pebble Authors. All rights reserved. Use 2 // of this source code is governed by a BSD-style license that can be found in 3 // the LICENSE file. 4 5 package main 6 7 import ( 8 "log" 9 "os" 10 "time" 11 12 "github.com/cockroachdb/pebble/internal/testkeys" 13 "github.com/cockroachdb/pebble/tool" 14 "github.com/spf13/cobra" 15 ) 16 17 var ( 18 cacheSize int64 19 concurrency int 20 disableWAL bool 21 duration time.Duration 22 maxSize uint64 23 maxOpsPerSec = newRateFlag("") 24 verbose bool 25 waitCompactions bool 26 wipe bool 27 pathToLocalSharedStorage string 28 // If zero, or if !sharedStorageEnabled, secondary cache is 29 // not used. 30 secondaryCacheSize int64 31 ) 32 33 func main() { 34 log.SetFlags(0) 35 36 cobra.EnableCommandSorting = false 37 38 benchCmd := &cobra.Command{ 39 Use: "bench", 40 Short: "benchmarks", 41 } 42 43 replayCmd := initReplayCmd() 44 benchCmd.AddCommand( 45 replayCmd, 46 scanCmd, 47 syncCmd, 48 tombstoneCmd, 49 ycsbCmd, 50 fsBenchCmd, 51 writeBenchCmd, 52 ) 53 54 rootCmd := &cobra.Command{ 55 Use: "pebble [command] (flags)", 56 Short: "pebble benchmarking/introspection tool", 57 } 58 rootCmd.AddCommand(benchCmd) 59 60 t := tool.New(tool.Comparers(mvccComparer, testkeys.Comparer), tool.Mergers(fauxMVCCMerger)) 61 rootCmd.AddCommand(t.Commands...) 62 63 for _, cmd := range []*cobra.Command{replayCmd, scanCmd, syncCmd, tombstoneCmd, writeBenchCmd, ycsbCmd} { 64 cmd.Flags().BoolVarP( 65 &verbose, "verbose", "v", false, "enable verbose event logging") 66 cmd.Flags().StringVar( 67 &pathToLocalSharedStorage, "shared-storage", "", "path to local shared storage (empty for no shared storage)") 68 cmd.Flags().Int64Var( 69 &secondaryCacheSize, "secondary-cache", 0, "secondary cache size in bytes") 70 } 71 for _, cmd := range []*cobra.Command{scanCmd, syncCmd, tombstoneCmd, ycsbCmd} { 72 cmd.Flags().Int64Var( 73 &cacheSize, "cache", 1<<30, "cache size") 74 } 75 for _, cmd := range []*cobra.Command{scanCmd, syncCmd, tombstoneCmd, ycsbCmd, fsBenchCmd, writeBenchCmd} { 76 cmd.Flags().DurationVarP( 77 &duration, "duration", "d", 10*time.Second, "the duration to run (0, run forever)") 78 } 79 for _, cmd := range []*cobra.Command{scanCmd, syncCmd, tombstoneCmd, ycsbCmd} { 80 cmd.Flags().IntVarP( 81 &concurrency, "concurrency", "c", 1, "number of concurrent workers") 82 cmd.Flags().BoolVar( 83 &disableWAL, "disable-wal", false, "disable the WAL (voiding persistence guarantees)") 84 cmd.Flags().VarP( 85 maxOpsPerSec, "rate", "m", "max ops per second [{zipf,uniform}:]min[-max][/period (sec)]") 86 cmd.Flags().BoolVar( 87 &waitCompactions, "wait-compactions", false, 88 "wait for background compactions to complete after load stops") 89 cmd.Flags().BoolVarP( 90 &wipe, "wipe", "w", false, "wipe the database before starting") 91 cmd.Flags().Uint64Var( 92 &maxSize, "max-size", 0, "maximum disk size, in MB (0, run forever)") 93 } 94 95 if err := rootCmd.Execute(); err != nil { 96 // Cobra has already printed the error message. 97 os.Exit(1) 98 } 99 }