in gitaly-bench.go [75:163]
func main() {
commands := map[string]*struct {
flagSet *flag.FlagSet
builder func(repository *gitalypb.Repository, conn *grpc.ClientConn) operations.BenchmarkOperation
}{
"gc": {flagSet: operations.GCFlagSet, builder: operations.NewGC},
"repack-full": {flagSet: operations.GCFlagSet, builder: operations.NewRepackFull},
"find-all-branch-names": {flagSet: nil, builder: operations.NewFindAllBranchNames},
"find-all-branches": {flagSet: nil, builder: operations.NewFindAllBranches},
"commit-diff": {flagSet: operations.CommitDiffFlagSet, builder: operations.NewCommitDiff},
"ref-exists": {flagSet: operations.RefExistsFlagSet, builder: operations.NewRefExists},
"info-refs": {flagSet: nil, builder: operations.NewInfoRefs},
"has-local-branches": {flagSet: nil, builder: operations.NewHasLocalBranches},
"find-commit": {flagSet: operations.FindCommitFlagSet, builder: operations.NewFindCommit},
}
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage of gitaly-bench [options] command:\n\n")
fmt.Fprintf(os.Stderr, "Options:\n")
flag.PrintDefaults()
fmt.Fprintf(os.Stderr, "\n`command` being one of:\n")
for k := range commands {
fmt.Fprintf(os.Stderr, "\t%v\n", k)
}
fmt.Fprintf(os.Stderr, "Use gitaly-bench command --help for command options\n")
}
flag.Parse()
if *gitRepoPath == "" {
flag.Usage()
os.Exit(1)
}
// Verify that a subcommand has been provided
if len(flag.Args()) < 1 {
flag.Usage()
os.Exit(1)
}
if *profileFlag != "" {
profileOpt := getProfileOpt(*profileFlag)
if profileOpt == nil {
flag.Usage()
os.Exit(1)
}
defer profile.Start(profileOpt, profile.ProfilePath(".")).Stop()
}
benchmarkName := flag.Arg(0)
command := commands[benchmarkName]
if command == nil {
flag.Usage()
os.Exit(1)
}
if command.flagSet != nil {
err := command.flagSet.Parse(flag.Args()[1:])
if err != nil || len(command.flagSet.Args()) > 0 {
if len(command.flagSet.Args()) > 0 {
fmt.Println("Unknown argument", strings.Join(command.flagSet.Args(), " "))
}
command.flagSet.Usage()
os.Exit(1)
}
} else {
if len(flag.Args()) > 1 {
fmt.Println("Unknown argument", strings.Join(flag.Args()[1:], " "))
flag.Usage()
os.Exit(1)
}
}
conn, err := newConnection()
if err != nil {
panic(err)
}
defer conn.Close()
repository := &gitalypb.Repository{
StorageName: *storage,
RelativePath: *gitRepoPath,
}
operation := command.builder(repository, conn)
benchmarks.RunBenchmark(benchmarkName, *parallel, *iterations, operation)
}