trace pprof Profiler labels

go tool trace
不合适



运行缓慢的函数,或者找到大部分CPU时间花费在哪里,术业有专攻,看CPU时间花费,是有专门的工具的 go tool pprof



合适



找出程序在一段时间内正在做什么



go tool trace 可以通过 view trace链接提供的其他可视化功能,对于诊断争用问题帮助极大



关键的goroutine被阻止运行时,可能会有延迟问题,大概的原因相信大家应该有些谱了吧



系统调用时被阻塞;



被共享内存阻塞(通道/互斥等)



调度程序没有按照我们所期望的频率运行协程



被runtime系统(例如GC)阻塞

https://www.bilibili.com/read/cv11534849/



Go 1.9 is introducing profiler labels, a way to add arbitrary key-values to the samples collected by the CPU profiler. CPU profilers collect and output hot spots where the CPU spent most time in when executing. A typical CPU profiler output is primarily reports the location of these spots as function name, source file/line, etc. By looking at the data, you can also examine which parts of the code invoked these spots. You can also filter by invokers to have more granular understanding of certain execution paths.



labels := pprof.Labels("worker", "purge")
pprof.Do(ctx, labels, func(ctx context.Context) {
// Do some work...

go update(ctx) // propagates labels in ctx.
})

https://rakyll.org/profiler-labels/



https://www.jetbrains.com/help/go/using-profiler-labels.html#viewing-labels-in-goland



Category golang