Golang 大杀器之trace

需要下载graphviz

package main

import (
	"log"
	"os"
	"runtime/trace"
)

func main() {
	file, err := os.Create("trace.out")
	if err != nil {
		log.Fatal(err)
	}
	defer file.Close()
	err = trace.Start(file)
	if err != nil {
		log.Fatal(err)
	}
	defer trace.Stop()
	ch := make(chan string)
	go func() {
		ch <- "Go"
	}()

	<-ch
}

go run main.go
go tool trace  trace.out

输出

2023/11/13 15:10:36 Parsing trace...
2023/11/13 15:10:36 Splitting trace...
2023/11/13 15:10:36 Opening browser. Trace viewer is listening on http://127.0.0.1:54898

View trace:查看跟踪
Goroutine analysis:Goroutine 分析
Network blocking profile:网络阻塞概况
Synchronization blocking profile:同步阻塞概况
Syscall blocking profile:系统调用阻塞概况
Scheduler latency profile:调度延迟概况
User defined tasks:用户自定义任务
User defined regions:用户自定义区域
Minimum mutator utilization:最低 Mutator 利用率
posted @ 2023-11-13 15:26  朝阳1  阅读(73)  评论(0编辑  收藏  举报