Commit 3441bda9 authored by Russ Cox's avatar Russ Cox

gotest: add timing, respect $GOARCH

R=r, r2
CC=golang-dev
https://golang.org/cl/4370049
parent bd43a2d9
...@@ -16,6 +16,7 @@ import ( ...@@ -16,6 +16,7 @@ import (
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings" "strings"
"time"
"unicode" "unicode"
"utf8" "utf8"
) )
...@@ -51,6 +52,13 @@ var ( ...@@ -51,6 +52,13 @@ var (
xFlag bool xFlag bool
) )
// elapsed returns time elapsed since gotest started.
func elapsed() float64 {
return float64(time.Nanoseconds()-start) / 1e9
}
var start = time.Nanoseconds()
// File represents a file that contains tests. // File represents a file that contains tests.
type File struct { type File struct {
name string name string
...@@ -80,6 +88,9 @@ func main() { ...@@ -80,6 +88,9 @@ func main() {
if !cFlag { if !cFlag {
runTestWithArgs("./" + O + ".out") runTestWithArgs("./" + O + ".out")
} }
if xFlag {
fmt.Printf("gotest %.2fs: done\n", elapsed())
}
} }
// needMakefile tests that we have a Makefile in this directory. // needMakefile tests that we have a Makefile in this directory.
...@@ -119,7 +130,10 @@ func setEnvironment() { ...@@ -119,7 +130,10 @@ func setEnvironment() {
// Basic environment. // Basic environment.
GOROOT = runtime.GOROOT() GOROOT = runtime.GOROOT()
addEnv("GOROOT", GOROOT) addEnv("GOROOT", GOROOT)
GOARCH = os.Getenv("GOARCH")
if GOARCH == "" {
GOARCH = runtime.GOARCH GOARCH = runtime.GOARCH
}
addEnv("GOARCH", GOARCH) addEnv("GOARCH", GOARCH)
O = theChar[GOARCH] O = theChar[GOARCH]
if O == "" { if O == "" {
...@@ -254,7 +268,12 @@ func runTestWithArgs(binary string) { ...@@ -254,7 +268,12 @@ func runTestWithArgs(binary string) {
// retrieve standard output. // retrieve standard output.
func doRun(argv []string, returnStdout bool) string { func doRun(argv []string, returnStdout bool) string {
if xFlag { if xFlag {
fmt.Printf("gotest: %s\n", strings.Join(argv, " ")) fmt.Printf("gotest %.2fs: %s\n", elapsed(), strings.Join(argv, " "))
t := -time.Nanoseconds()
defer func() {
t += time.Nanoseconds()
fmt.Printf(" [+%.2fs]\n", float64(t)/1e9)
}()
} }
command := argv[0] command := argv[0]
if runtime.GOOS == "windows" && command == "gomake" { if runtime.GOOS == "windows" && command == "gomake" {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment