mirror of
https://github.com/golang/go
synced 2024-09-30 05:24:29 -06:00
runtime/trace, internal/trace: script to collect canned traces
This adds support to the runtime/trace test for saving traces collected by its tests to disk and a script in internal/trace that uses this to collect canned traces for the trace test suite. This can be used to add to the test suite when we introduce a new trace format version. Change-Id: Id9ac1ff312235bf02f982fdfff8a827f54035758 Reviewed-on: https://go-review.googlesource.com/32290 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
This commit is contained in:
parent
9a8c69539c
commit
e14b021977
19
src/internal/trace/mkcanned.bash
Executable file
19
src/internal/trace/mkcanned.bash
Executable file
@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright 2016 The Go Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style
|
||||
# license that can be found in the LICENSE file.
|
||||
|
||||
# mkcanned.bash creates canned traces for the trace test suite using
|
||||
# the current Go version.
|
||||
|
||||
set -e
|
||||
|
||||
if [ $# != 1 ]; then
|
||||
echo "usage: $0 <label>" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
go test -run ClientServerParallel4 -trace "testdata/http_$1_good" net/http
|
||||
go test -run 'TraceStress$|TraceStressStartStop$' runtime/trace -savetraces
|
||||
mv ../../runtime/trace/TestTraceStress.trace "testdata/stress_$1_good"
|
||||
mv ../../runtime/trace/TestTraceStressStartStop.trace "testdata/stress_start_stop_$1_good"
|
@ -128,6 +128,8 @@ func readTrace(r io.Reader) (ver int, events []rawEvent, strings map[uint64]stri
|
||||
}
|
||||
switch ver {
|
||||
case 1005, 1007, 1008:
|
||||
// Note: When adding a new version, add canned traces
|
||||
// from the old version to the test suite using mkcanned.bash.
|
||||
break
|
||||
default:
|
||||
err = fmt.Errorf("unsupported trace file version %v.%v (update Go toolchain) %v", ver/1000, ver%1000, ver)
|
||||
|
@ -6,8 +6,10 @@ package trace_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"flag"
|
||||
"internal/trace"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"runtime"
|
||||
@ -17,6 +19,10 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
saveTraces = flag.Bool("savetraces", false, "save traces collected by tests")
|
||||
)
|
||||
|
||||
func TestTraceStartStop(t *testing.T) {
|
||||
buf := new(bytes.Buffer)
|
||||
if err := Start(buf); err != nil {
|
||||
@ -31,6 +37,7 @@ func TestTraceStartStop(t *testing.T) {
|
||||
if size != buf.Len() {
|
||||
t.Fatalf("trace writes after stop: %v -> %v", size, buf.Len())
|
||||
}
|
||||
saveTrace(t, buf, "TestTraceStartStop")
|
||||
}
|
||||
|
||||
func TestTraceDoubleStart(t *testing.T) {
|
||||
@ -52,6 +59,7 @@ func TestTrace(t *testing.T) {
|
||||
t.Fatalf("failed to start tracing: %v", err)
|
||||
}
|
||||
Stop()
|
||||
saveTrace(t, buf, "TestTrace")
|
||||
_, err := trace.Parse(buf, "")
|
||||
if err == trace.ErrTimeOrder {
|
||||
t.Skipf("skipping trace: %v", err)
|
||||
@ -233,6 +241,7 @@ func TestTraceStress(t *testing.T) {
|
||||
runtime.GOMAXPROCS(procs)
|
||||
|
||||
Stop()
|
||||
saveTrace(t, buf, "TestTraceStress")
|
||||
trace := buf.Bytes()
|
||||
parseTrace(t, buf)
|
||||
testBrokenTimestamps(t, trace)
|
||||
@ -376,6 +385,7 @@ func TestTraceStressStartStop(t *testing.T) {
|
||||
}
|
||||
time.Sleep(time.Millisecond)
|
||||
Stop()
|
||||
saveTrace(t, buf, "TestTraceStressStartStop")
|
||||
trace := buf.Bytes()
|
||||
parseTrace(t, buf)
|
||||
testBrokenTimestamps(t, trace)
|
||||
@ -436,6 +446,7 @@ func TestTraceFutileWakeup(t *testing.T) {
|
||||
done.Wait()
|
||||
|
||||
Stop()
|
||||
saveTrace(t, buf, "TestTraceFutileWakeup")
|
||||
events, _ := parseTrace(t, buf)
|
||||
// Check that (1) trace does not contain EvFutileWakeup events and
|
||||
// (2) there are no consecutive EvGoBlock/EvGCStart/EvGoBlock events
|
||||
@ -464,3 +475,12 @@ func TestTraceFutileWakeup(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func saveTrace(t *testing.T, buf *bytes.Buffer, name string) {
|
||||
if !*saveTraces {
|
||||
return
|
||||
}
|
||||
if err := ioutil.WriteFile(name+".trace", buf.Bytes(), 0600); err != nil {
|
||||
t.Errorf("failed to write trace file: %s", err)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user