func home(cmd *cobra.Command, args []string) { token, err := getToken() if err != nil { fmt.Println("Authentication required") os.Exit(1) } addr := os.Getenv("CLAWIO_BENCH_META_ADDR") con, err := grpc.Dial(addr, grpc.WithInsecure()) if err != nil { fmt.Println("Cannot connect to server " + addr) os.Exit(1) } defer con.Close() c := pb.NewMetaClient(con) in := &pb.HomeReq{} in.AccessToken = token ctx := context.Background() _, err = c.Home(ctx, in) if err != nil { fmt.Println("Cannot create homedir: " + err.Error()) os.Exit(1) } fmt.Println("Home directory created") }
func stat(cmd *cobra.Command, args []string) error { if len(args) != 1 { cmd.Help() return nil } token, err := getToken() if err != nil { return err } con, err := grpc.Dial(metaAddr, grpc.WithInsecure()) if err != nil { return err } defer con.Close() c := pb.NewMetaClient(con) benchStart := time.Now() total := 0 errorProbes := 0 errChan := make(chan error) resChan := make(chan string) doneChan := make(chan bool) limitChan := make(chan int, concurrencyFlag) for i := 0; i < concurrencyFlag; i++ { limitChan <- 1 } var bar *br.ProgressBar if progressBar { bar = br.StartNew(probesFlag) } for i := 0; i < probesFlag; i++ { go func() { <-limitChan defer func() { limitChan <- 1 }() in := &pb.StatReq{} in.AccessToken = token in.Path = args[0] in.Children = childrenFlag ctx := context.Background() _, err := c.Stat(ctx, in) if err != nil { errChan <- err return } doneChan <- true resChan <- "" }() } for { select { case _ = <-doneChan: total++ if progressBar { bar.Increment() } case _ = <-resChan: case err := <-errChan: log.Error(err) errorProbes++ total++ if progressBar { bar.Increment() } } if total == probesFlag { break } } if progressBar { bar.Finish() } numberRequests := probesFlag concurrency := concurrencyFlag totalTime := time.Since(benchStart).Seconds() failedRequests := errorProbes frequency := float64(numberRequests-failedRequests) / totalTime period := float64(1 / frequency) data := [][]string{ {"#NUMBER", "CONCURRENCY", "TIME", "FAILED", "FREQ", "PERIOD"}, {fmt.Sprintf("%d", numberRequests), fmt.Sprintf("%d", concurrency), fmt.Sprintf("%f", totalTime), fmt.Sprintf("%d", failedRequests), fmt.Sprintf("%f", frequency), fmt.Sprintf("%f", period)}, } w := csv.NewWriter(output) w.Comma = ' ' for _, d := range data { if err := w.Write(d); err != nil { return err } } w.Flush() if err := w.Error(); err != nil { return err } return nil }