我正在优化 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
?