登录
首页 >  Golang >  Go问答

是go pprof随机挑选一个线程接收信号

来源:stackoverflow

时间:2024-04-26 13:48:34 458浏览 收藏

偷偷努力,悄无声息地变强,然后惊艳所有人!哈哈,小伙伴们又来学习啦~今天我将给大家介绍《是go pprof随机挑选一个线程接收信号》,这篇文章主要会讲到等等知识点,不知道大家对其都有多少了解,下面我们就一起来看一吧!当然,非常希望大家能多多评论,给出合理的建议,我们一起学习,一起进步!

问题内容

在本文中:https://www.datadoghq.com/blog/engineering/profiling-improvements-in-go-1-18/。 下面这个词让我很困惑:reporting top 使用了 20 个 CPU 核心,预期信号速率应该是每秒 2,000 个信号。然而,生成的配置文件平均每秒仅包含 240 个堆栈跟踪。

令我困惑的是,在 func runtime.SetCPUProfileRate 中,仅将当前线程 profileHz 设置为 100。 我知道在linux中,信号是随机选择一个线程来执行的。 因此,profileHz 不为零的线程每次只会接收大约 2000 / 20 = 100 个信号。 因此平均堆栈跟踪约为每秒 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信号。

好了,本文到此结束,带大家了解了《是go pprof随机挑选一个线程接收信号》,希望本文对你有所帮助!关注golang学习网公众号,给大家分享更多Golang知识!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>