github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/workload/debug/tpcc_results.go (about) 1 // Copyright 2019 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package debug 12 13 import ( 14 "fmt" 15 "sort" 16 "time" 17 18 "github.com/cockroachdb/cockroach/pkg/workload/histogram" 19 "github.com/cockroachdb/cockroach/pkg/workload/tpcc" 20 "github.com/cockroachdb/errors" 21 "github.com/spf13/cobra" 22 ) 23 24 var tpccMergeResultsCmd = &cobra.Command{ 25 Use: "tpcc-merge-results [<hist-file> [<hist-file>...]]", 26 Short: "tpcc-merge-results merges the histograms from parallel runs of " + 27 "TPC-C to compute a combined result.", 28 RunE: tpccMergeResults, 29 Args: cobra.MinimumNArgs(1), 30 } 31 32 func init() { 33 flags := tpccMergeResultsCmd.Flags() 34 flags.Int("warehouses", 0, "number of aggregate warehouses in all of the histograms") 35 } 36 37 func tpccMergeResults(cmd *cobra.Command, args []string) error { 38 // We want to take histograms and merge them 39 warehouses, err := cmd.Flags().GetInt("warehouses") 40 if err != nil { 41 return errors.Wrap(err, "no warehouses flag found") 42 } 43 var results []*tpcc.Result 44 45 for _, fname := range args { 46 snapshots, err := histogram.DecodeSnapshots(fname) 47 if err != nil { 48 return errors.Wrapf(err, "failed to decode histograms at %q", fname) 49 } 50 results = append(results, tpcc.NewResultWithSnapshots(warehouses, 0, snapshots)) 51 } 52 53 res := tpcc.MergeResults(results...) 54 out := cmd.OutOrStdout() 55 _, _ = fmt.Fprintf(out, "Duration: %.5v, Warehouses: %v, Efficiency: %.4v, tpmC: %.2f\n", 56 res.Elapsed, res.ActiveWarehouses, res.Efficiency(), res.TpmC()) 57 _, _ = fmt.Fprintf(out, "_elapsed___ops/sec(cum)__p50(ms)__p90(ms)__p95(ms)__p99(ms)_pMax(ms)\n") 58 59 var queries []string 60 for query := range res.Cumulative { 61 queries = append(queries, query) 62 } 63 sort.Strings(queries) 64 for _, query := range queries { 65 hist := res.Cumulative[query] 66 _, _ = fmt.Fprintf(out, "%7.1fs %14.1f %8.1f %8.1f %8.1f %8.1f %8.1f %s\n", 67 res.Elapsed.Seconds(), 68 float64(hist.TotalCount())/res.Elapsed.Seconds(), 69 time.Duration(hist.ValueAtQuantile(50)).Seconds()*1000, 70 time.Duration(hist.ValueAtQuantile(90)).Seconds()*1000, 71 time.Duration(hist.ValueAtQuantile(95)).Seconds()*1000, 72 time.Duration(hist.ValueAtQuantile(99)).Seconds()*1000, 73 time.Duration(hist.ValueAtQuantile(100)).Seconds()*1000, 74 query, 75 ) 76 } 77 return nil 78 }