🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[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 ```