From 2130d1dd50e5c51fa36c4a242fa12a141a7c44f6 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 29 Oct 2024 00:09:53 -0700 Subject: [PATCH] add waitgroup and write the csv.zst in parallel --- cli/benchmark.go | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/cli/benchmark.go b/cli/benchmark.go index 46ef82f..34cec74 100644 --- a/cli/benchmark.go +++ b/cli/benchmark.go @@ -252,26 +252,32 @@ func runBench(ctx *cli.Context, b bench.Benchmark) error { ops.SetClientID(cID) prof.stop(ctx2, ctx, fileName+".profiles.zip") + var wg sync.WaitGroup if len(ops) > 0 { - f, err := os.Create(fileName + ".csv.zst") - if err != nil { - monitor.Errorln("Unable to write benchmark data:", err) - } else { - func() { + wg.Add(1) + go func() { + defer wg.Done() + f, err := os.Create(fileName + ".csv.zst") + if err != nil { + monitor.Errorln("Unable to write benchmark data:", err) + } else { defer f.Close() + enc, err := zstd.NewWriter(f, zstd.WithEncoderLevel(zstd.SpeedBetterCompression)) fatalIf(probe.NewError(err), "Unable to compress benchmark output") - defer enc.Close() - err = ops.CSV(enc, commandLine(ctx)) - fatalIf(probe.NewError(err), "Unable to write benchmark output") - monitor.InfoLn(fmt.Sprintf("Benchmark data written to %q\n", fileName+".csv.zst")) - }() - } + fatalIf(probe.NewError(ops.CSV(enc, commandLine(ctx))), "Unable to write benchmark output") + } + }() } + monitor.OperationsReady(ops, fileName, commandLine(ctx)) printAnalysis(ctx, ops) + + wg.Wait() + monitor.InfoLn(fmt.Sprintf("Benchmark data written to %q\n", fileName+".csv.zst")) + if !ctx.Bool("keep-data") && !ctx.Bool("noclear") { monitor.InfoLn("Starting cleanup...") b.Cleanup(context.Background())