Add timing info for each tool and total duration

This commit is contained in:
Jeffrey Paul 2025-12-18 01:11:17 -08:00
parent 0c31667230
commit 30b1cebd02

27
main.go
View File

@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"sync"
"time"
)
//go:embed tools.json
@ -57,6 +58,8 @@ func main() {
sem := make(chan struct{}, *parallel)
results := make(chan result, len(tf.Tools))
startTime := time.Now()
for _, t := range tf.Tools {
wg.Add(1)
go func(tool Tool) {
@ -68,11 +71,12 @@ func main() {
fmt.Printf("Installing %s@%s...\n", tool.Name, tool.Version)
}
toolStart := time.Now()
pkg := fmt.Sprintf("%s@%s", tool.Package, tool.Version)
cmd := exec.Command("go", "install", pkg)
cmd.Env = os.Environ()
output, err := cmd.CombinedOutput()
results <- result{tool: tool, err: err, output: string(output)}
results <- result{tool: tool, err: err, output: string(output), duration: time.Since(toolStart)}
}(t)
}
@ -84,25 +88,34 @@ func main() {
var succeeded, failed int
for r := range results {
if r.err != nil {
fmt.Printf("✗ %s@%s: %v\n", r.tool.Name, r.tool.Version, r.err)
fmt.Printf("✗ %s@%s: %v (%s)\n", r.tool.Name, r.tool.Version, r.err, formatDuration(r.duration))
if *verbose && r.output != "" {
fmt.Printf(" %s\n", r.output)
}
failed++
} else {
fmt.Printf("✓ %s@%s\n", r.tool.Name, r.tool.Version)
fmt.Printf("✓ %s@%s (%s)\n", r.tool.Name, r.tool.Version, formatDuration(r.duration))
succeeded++
}
}
fmt.Printf("\nDone: %d succeeded, %d failed\n", succeeded, failed)
totalDuration := time.Since(startTime)
fmt.Printf("\nDone: %d succeeded, %d failed in %s\n", succeeded, failed, formatDuration(totalDuration))
if failed > 0 {
os.Exit(1)
}
}
type result struct {
tool Tool
err error
output string
tool Tool
err error
output string
duration time.Duration
}
func formatDuration(d time.Duration) string {
if d < time.Second {
return fmt.Sprintf("%dms", d.Milliseconds())
}
return fmt.Sprintf("%.1fs", d.Seconds())
}