From 4fa010fba127f2273cfeb6d8e273a7f444fdbb73 Mon Sep 17 00:00:00 2001 From: Tobias Grieger Date: Thu, 19 Dec 2024 06:44:04 +0100 Subject: [PATCH 1/5] fix spinner updating Inconsequential since benchdiff is likely rarely used with multiple packages, but still, now it's correct. --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 9e19c65..7031f7c 100644 --- a/main.go +++ b/main.go @@ -589,8 +589,8 @@ func (bs *benchSuite) build(pkgFilter []string, postChck string, t time.Time) (e } else if ok { bs.testFiles[testBin] = struct{}{} } + spinner.Update(ui.Fraction(i+1, len(pkgs))) } - spinner.Update(ui.Fraction(len(pkgs), len(pkgs))) return nil } From c7eca1e1fc639173876c2056de46b179ed7cc887 Mon Sep 17 00:00:00 2001 From: Tobias Grieger Date: Thu, 19 Dec 2024 06:43:23 +0100 Subject: [PATCH 2/5] ui: clear spinner line when done spinning --- ui/spinner.go | 3 ++- ui/writer.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ui/spinner.go b/ui/spinner.go index 33f2d07..2d43efd 100644 --- a/ui/spinner.go +++ b/ui/spinner.go @@ -2,8 +2,8 @@ package ui import ( "fmt" - "strconv" "io" + "strconv" "sync" "time" ) @@ -31,6 +31,7 @@ func (s *Spinner) Start(out io.Writer, prefix string) { go func() { defer s.wg.Done() defer s.t.Stop() + defer s.w.Flush(out) var progress string var ok bool diff --git a/ui/writer.go b/ui/writer.go index a702e62..e27493a 100644 --- a/ui/writer.go +++ b/ui/writer.go @@ -25,10 +25,10 @@ type Writer struct { // Flush TODO(peter): document func (w *Writer) Flush(out io.Writer) error { + w.clearLines(out) if len(w.buf.Bytes()) == 0 { return nil } - w.clearLines(out) for _, b := range w.buf.Bytes() { if b == '\n' { From 703c730ee14b3db8b9c229630c064b21546c9807 Mon Sep 17 00:00:00 2001 From: Tobias Grieger Date: Thu, 19 Dec 2024 06:44:49 +0100 Subject: [PATCH 3/5] remove a log line We'll log this in a better location in a follow-up commit. --- main.go | 1 - 1 file changed, 1 deletion(-) diff --git a/main.go b/main.go index 7031f7c..86dcf1c 100644 --- a/main.go +++ b/main.go @@ -567,7 +567,6 @@ func (bs *benchSuite) build(pkgFilter []string, postChck string, t time.Time) (e } }() - fmt.Fprintf(os.Stderr, "checking out '%s'\n", bs.ref) if err := checkoutRef(bs.ref, postChck); err != nil { return err } From 4a7be62f2bbd0c12f1e714b80992ca32f717c008 Mon Sep 17 00:00:00 2001 From: Tobias Grieger Date: Thu, 19 Dec 2024 06:53:37 +0100 Subject: [PATCH 4/5] further tighten logging --- main.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/main.go b/main.go index 86dcf1c..59bc0c4 100644 --- a/main.go +++ b/main.go @@ -334,9 +334,8 @@ func runCmpBenches( cpuProfile, memProfile, mutexProfile bool, itersPerTest int, ) error { - fmt.Fprintf(os.Stderr, "\nrunning benchmarks:") var spinner ui.Spinner - spinner.Start(os.Stderr, "") + spinner.Start(os.Stderr, "running benchmarks:") defer spinner.Stop() for i, t := range tests { pkg := testBinToPkg(t) @@ -356,7 +355,6 @@ func runCmpBenches( return err } } - fmt.Fprintln(os.Stderr) } return nil } @@ -541,7 +539,6 @@ func (bs *benchSuite) build(pkgFilter []string, postChck string, t time.Time) (e // Create the binary directory: ./benchdiff//bin/ bs.binDir = testBinDir(bs.ref, pkgFilter) if _, err = os.Stat(bs.binDir); err == nil { - fmt.Fprintf(os.Stderr, "test binaries already exist for %s: %.50s\n", bs.ref, bs.subject) files, err := ioutil.ReadDir(bs.binDir) if err != nil { return err From c7148a287e8f5700d1e5474004411dfec7297e67 Mon Sep 17 00:00:00 2001 From: Tobias Grieger Date: Thu, 19 Dec 2024 08:48:22 +0100 Subject: [PATCH 5/5] print a header --- main.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/main.go b/main.go index 59bc0c4..676e0d3 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,7 @@ import ( "os/exec" "path/filepath" "sort" + "strconv" "strings" "time" @@ -214,6 +215,8 @@ func run(ctx context.Context) error { defer oldSuite.close() defer newSuite.close() + printHeader(os.Stdout, oldSuite, newSuite) + if previousRun == "" { if err := buildBenches(ctx, pkgFilter, postChck, &oldSuite, &newSuite); err != nil { return err @@ -628,3 +631,16 @@ func (fs fileSet) sorted() []string { sort.Strings(s) return s } + +func printHeader(w io.Writer, oldSuite, newSuite benchSuite) { + fmt.Fprintf(w, "old: %s %.50s\n", oldSuite.ref, oldSuite.subject) + fmt.Fprintf(w, "new: %s %.50s\n", newSuite.ref, newSuite.subject) + fmt.Fprintf(w, "args: %s\n\n", strings.Join(func() []string { + quoted := make([]string, 1+len(os.Args[1:])) + quoted[0] = "benchdiff" + for i, arg := range os.Args[1:] { + quoted[1+i] = strconv.Quote(arg) + } + return quoted + }(), " ")) +}