...
1
2
3
4
5 package trace_test
6
7 import (
8 "fmt"
9 "log"
10 "os"
11 "runtime/trace"
12 )
13
14
15
16
17 func Example() {
18 f, err := os.Create("trace.out")
19 if err != nil {
20 log.Fatalf("failed to create trace output file: %v", err)
21 }
22 defer func() {
23 if err := f.Close(); err != nil {
24 log.Fatalf("failed to close trace file: %v", err)
25 }
26 }()
27
28 if err := trace.Start(f); err != nil {
29 log.Fatalf("failed to start trace: %v", err)
30 }
31 defer trace.Stop()
32
33
34 RunMyProgram()
35 }
36
37 func RunMyProgram() {
38 fmt.Printf("this function will be traced")
39 }
40
View as plain text