#!/usr/bin/env bash
set -euo pipefail
export TZ=UTC
out=${1:-out}
mkdir -p "$out"
go version > "$out/environment.txt"
go test -v . > "$out/test.txt"
go test -race . >> "$out/test.txt"
go vet . >> "$out/test.txt"
go build -o "$out/lab" .
GOMAXPROCS=2 "$out/lab" "$out/trace.out" > "$out/run.txt"
go tool trace -d=parsed "$out/trace.out" > "$out/events.txt"
for kind in sched sync net syscall; do
 go tool trace -pprof="$kind" "$out/trace.out" > "$out/$kind.pb.gz"
 go tool pprof -top "$out/$kind.pb.gz" > "$out/$kind-top.txt"
done
