在本文中:https://www.datadoghq.com/blog/engineering/profiling-improvements-in-go-1-18/.下面这个词让我困惑:reporting 20 CPU cores being used by top, the expected signal rate should have been 2,000 signals per second. However, the resulting profile only contained an average of 240 stack traces per second.
。
我感到困惑的是在func运行时。SetCPUProfileRate,仅将当前线程profileHz设置为100。我知道在linux中,信号是随机选择一个线程来执行。所以profileHz不为零的线程将只接收大约2000/20=100个信号percond。因此,平均堆栈轨迹约为每秒100条。
为什么这篇文章说堆栈跟踪每秒会产生240个甚至更多的堆栈跟踪?
似乎要为init:中的所有线程添加sigmask
// minitSignalStack is called when initializing a new m to set the
// alternate signal stack. If the alternate signal stack is not set
// for the thread (the normal case) then set the alternate signal
// stack to the gsignal stack. If the alternate signal stack is set
// for the thread (the case when a non-Go thread sets the alternate
// signal stack and then calls a Go function) then set the gsignal
// stack to the alternate signal stack. We also set the alternate
// signal stack to the gsignal stack if cgo is not used (regardless
// of whether it is already set). Record which choice was made in
// newSigstack, so that it can be undone in unminit.
func minitSignalStack() {
因此只有启动pprof的线程才能接收sigprof信号。