github.com/dolthub/dolt/go@v0.40.5-0.20240520175717-68db7794bea6/performance/sysbench/cmd/main.go (about)

     1  // Copyright 2022 Dolthub, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package main
    16  
    17  import (
    18  	"flag"
    19  	"fmt"
    20  	"log"
    21  	"os"
    22  
    23  	"github.com/dolthub/dolt/go/performance/sysbench"
    24  
    25  	driver "github.com/dolthub/dolt/go/libraries/doltcore/dtestutils/sql_server_driver"
    26  )
    27  
    28  var run = flag.String("run", "", "the path to a test file")
    29  var scriptDir = flag.String("script-dir", "", "the path to the script directory")
    30  var config = flag.String("config", "", "the path to a config file")
    31  var out = flag.String("out", "", "result output path")
    32  var verbose = flag.Bool("verbose", true, "verbose output")
    33  
    34  func main() {
    35  	flag.Parse()
    36  	defs, err := sysbench.ParseTestsFile(*run)
    37  	if err != nil {
    38  		log.Fatalln(err)
    39  	}
    40  
    41  	conf, err := sysbench.ParseConfig(*config)
    42  	if err != nil {
    43  		log.Fatalln(err)
    44  	}
    45  
    46  	conf = conf.WithScriptDir(*scriptDir).WithVerbose(*verbose)
    47  	if err := os.Chdir(*scriptDir); err != nil {
    48  		log.Fatalf("failed to 'cd %s'", *scriptDir)
    49  	}
    50  
    51  	tmpdir, err := os.MkdirTemp("", "repo-store-")
    52  	if err != nil {
    53  		log.Fatalln(err)
    54  	}
    55  
    56  	results := new(sysbench.Results)
    57  	u, err := driver.NewDoltUser()
    58  	for _, test := range defs.Tests {
    59  		test.InitWithTmpDir(tmpdir)
    60  
    61  		for _, r := range test.Repos {
    62  			var err error
    63  			switch {
    64  			case r.ExternalServer != nil:
    65  				err = test.RunExternalServerTests(r.Name, r.ExternalServer, conf)
    66  			case r.Server != nil:
    67  				err = test.RunSqlServerTests(r, u, conf)
    68  			default:
    69  				panic("unsupported")
    70  			}
    71  			if err != nil {
    72  				log.Fatalln(err)
    73  			}
    74  		}
    75  		results.Append(test.Results.Res...)
    76  	}
    77  	if *out != "" {
    78  		of, err := os.Create(*out)
    79  		if err != nil {
    80  			log.Fatalln(err)
    81  		}
    82  		fmt.Fprintf(of, results.SqlDump())
    83  	} else {
    84  		fmt.Println(results.SqlDump())
    85  	}
    86  	os.Exit(0)
    87  }