trace
最后更新于:2022-04-02 02:45:55
[TOC]
## 实例
```
func Example() {
f, err := os.Create("trace.out")
if err != nil {
log.Fatalf("failed to create trace output file: %v", err)
}
defer func() {
if err := f.Close(); err != nil {
log.Fatalf("failed to close trace file: %v", err)
}
}()
if err := trace.Start(f); err != nil {
log.Fatalf("failed to start trace: %v", err)
}
defer trace.Stop()
// your program here
RunMyProgram()
}
func RunMyProgram() {
fmt.Printf("this function will be traced")
}
```
执行
```
go test -trace=trace.out
```
';