我正在优化Go程序的性能。在查看互斥锁分析时,我遇到了以下内容:
> go tool pprof -seconds 30 -ignore .*Shopify.* http://HOST/debug/pprof/mutex
(pprof) top 20
Active filters:
ignore=.*Shopify.*
Showing nodes accounting for 3.08mins, 91.03% of 3.39mins total
Dropped 82 nodes (cum <= 0.02mins)
flat flat% sum% cum cum%
3.08mins 91.03% 91.03% 3.08mins 91.03% sync.(*Mutex).Unlock
0 0% 91.03% 0.06mins 1.75% ....func2
0 0% 91.03% 0.06mins 1.75% ....func3
代码片段是:
. . 502: w.mu.Lock()
. . ... some calculation
. 5.02mins 510: w.mu.Unlock()
. . 511:
. . 512: return nil
. . 513:}
我不明白的是:
- 为什么互斥锁分析只显示顶部 1 的
flat
时间,其余全部为0
? - 如果它显示等待
Lock
,那么很可能意味着计算时间过长,但如果它显示等待Unlock
是什么意思?