Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tighten logging and print an informational header #5

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os/exec"
"path/filepath"
"sort"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -334,9 +337,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)
Expand All @@ -356,7 +358,6 @@ func runCmpBenches(
return err
}
}
fmt.Fprintln(os.Stderr)
}
return nil
}
Expand Down Expand Up @@ -541,7 +542,6 @@ func (bs *benchSuite) build(pkgFilter []string, postChck string, t time.Time) (e
// Create the binary directory: ./benchdiff/<ref>/bin/<hash(pkgFilter)>
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
Expand All @@ -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
}
Expand All @@ -589,8 +588,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
}

Expand Down Expand Up @@ -632,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
}(), " "))
}
3 changes: 2 additions & 1 deletion ui/spinner.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package ui

import (
"fmt"
"strconv"
"io"
"strconv"
"sync"
"time"
)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ui/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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' {
Expand Down