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