...
1
2
3
4
5
6
7 package main
8
9 import (
10 "bytes"
11 "fmt"
12 "internal/trace/v2/raw"
13 "internal/trace/v2/version"
14 "io"
15 "log"
16 "os"
17 "os/exec"
18 )
19
20 func main() {
21
22 var trace, stderr bytes.Buffer
23 cmd := exec.Command("go", "run", "./testprog/main.go")
24
25 cmd.Env = append(os.Environ(), "GOEXPERIMENT=exectracer2")
26 cmd.Stdout = &trace
27 cmd.Stderr = &stderr
28
29
30 fmt.Fprintln(os.Stderr, "running trace program...")
31 if err := cmd.Run(); err != nil {
32 log.Fatalf("running trace program: %v:\n%s", err, stderr.String())
33 }
34
35
36 f, err := os.Create(fmt.Sprintf("./go1%d.test", version.Current))
37 if err != nil {
38 log.Fatalf("creating output file: %v", err)
39 }
40 defer f.Close()
41
42
43 r, err := raw.NewReader(&trace)
44 if err != nil {
45 log.Fatalf("reading trace: %v", err)
46 }
47 w, err := raw.NewTextWriter(f, version.Current)
48 for {
49 ev, err := r.ReadEvent()
50 if err == io.EOF {
51 break
52 }
53 if err != nil {
54 log.Fatalf("reading trace: %v", err)
55 }
56 if err := w.WriteEvent(ev); err != nil {
57 log.Fatalf("writing trace: %v", err)
58 }
59 }
60 }
61
View as plain text