...
1
2
3
4
5
6
7
8
9
10
11 package main
12
13 import (
14 "log"
15 "os"
16 "runtime/trace"
17 "syscall"
18 "time"
19 )
20
21 func main() {
22
23 var p [2]int
24 if err := syscall.Pipe(p[:]); err != nil {
25 log.Fatalf("failed to create pipe: %v", err)
26 }
27 rfd, wfd := p[0], p[1]
28
29
30 done := make(chan struct{})
31 go func() {
32 var data [1]byte
33 _, err := syscall.Read(rfd, data[:])
34 if err != nil {
35 log.Fatalf("failed to read from pipe: %v", err)
36 }
37 done <- struct{}{}
38 }()
39
40
41 time.Sleep(10 * time.Millisecond)
42
43
44 if err := trace.Start(os.Stdout); err != nil {
45 log.Fatalf("failed to start tracing: %v", err)
46 }
47
48
49
50 time.Sleep(100 * time.Millisecond)
51
52
53 if _, err := syscall.Write(wfd, []byte{10}); err != nil {
54 log.Fatalf("failed to write to pipe: %v", err)
55 }
56
57
58
59
60
61
62 <-done
63
64
65 trace.Stop()
66 }
67
View as plain text