{"id":207887,"date":"2025-07-08T09:03:24","date_gmt":"2025-07-08T01:03:24","guid":{"rendered":"https:\/\/server.hk\/cnblog\/207887\/"},"modified":"2025-07-08T09:03:24","modified_gmt":"2025-07-08T01:03:24","slug":"%e6%98%afgo-pprof%e9%9a%8f%e6%9c%ba%e6%8c%91%e9%80%89%e4%b8%80%e4%b8%aa%e7%ba%bf%e7%a8%8b%e6%8e%a5%e6%94%b6%e4%bf%a1%e5%8f%b7","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/207887\/","title":{"rendered":"\u662fgo pprof\u968f\u673a\u6311\u9009\u4e00\u4e2a\u7ebf\u7a0b\u63a5\u6536\u4fe1\u53f7"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>\u662fgo pprof\u968f\u673a\u6311\u9009\u4e00\u4e2a\u7ebf\u7a0b\u63a5\u6536\u4fe1\u53f7<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-26 13:48:34<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u5077\u5077\u52aa\u529b\uff0c\u6084\u65e0\u58f0\u606f\u5730\u53d8\u5f3a\uff0c\u7136\u540e\u60ca\u8273\u6240\u6709\u4eba\uff01\u54c8\u54c8\uff0c\u5c0f\u4f19\u4f34\u4eec\u53c8\u6765\u5b66\u4e60\u5566~\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u4ecb\u7ecd<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u662fgo pprof\u968f\u673a\u6311\u9009\u4e00\u4e2a\u7ebf\u7a0b\u63a5\u6536\u4fe1\u53f7\u300b<\/span>\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4f1a\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u4e0d\u77e5\u9053\u5927\u5bb6\u5bf9\u5176\u90fd\u6709\u591a\u5c11\u4e86\u89e3\uff0c\u4e0b\u9762\u6211\u4eec\u5c31\u4e00\u8d77\u6765\u770b\u4e00\u5427\uff01\u5f53\u7136\uff0c\u975e\u5e38\u5e0c\u671b\u5927\u5bb6\u80fd\u591a\u591a\u8bc4\u8bba\uff0c\u7ed9\u51fa\u5408\u7406\u7684\u5efa\u8bae\uff0c\u6211\u4eec\u4e00\u8d77\u5b66\u4e60\uff0c\u4e00\u8d77\u8fdb\u6b65\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u5728\u672c\u6587\u4e2d\uff1ahttps:\/\/www.datadoghq.com\/blog\/engineering\/profiling-improvements-in-go-1-18\/\u3002 \u4e0b\u9762\u8fd9\u4e2a\u8bcd\u8ba9\u6211\u5f88\u56f0\u60d1\uff1a<code>reporting top \u4f7f\u7528\u4e86 20 \u4e2a CPU \u6838\u5fc3\uff0c\u9884\u671f\u4fe1\u53f7\u901f\u7387\u5e94\u8be5\u662f\u6bcf\u79d2 2,000 \u4e2a\u4fe1\u53f7\u3002\u7136\u800c\uff0c\u751f\u6210\u7684\u914d\u7f6e\u6587\u4ef6\u5e73\u5747\u6bcf\u79d2\u4ec5\u5305\u542b 240 \u4e2a\u5806\u6808\u8ddf\u8e2a\u3002 <\/code>\u3002<\/p>\n<p>\u4ee4\u6211\u56f0\u60d1\u7684\u662f\uff0c\u5728 func runtime.SetCPUProfileRate \u4e2d\uff0c\u4ec5\u5c06\u5f53\u524d\u7ebf\u7a0b profileHz \u8bbe\u7f6e\u4e3a 100\u3002 \u6211\u77e5\u9053\u5728linux\u4e2d\uff0c\u4fe1\u53f7\u662f\u968f\u673a\u9009\u62e9\u4e00\u4e2a\u7ebf\u7a0b\u6765\u6267\u884c\u7684\u3002 \u56e0\u6b64\uff0cprofileHz \u4e0d\u4e3a\u96f6\u7684\u7ebf\u7a0b\u6bcf\u6b21\u53ea\u4f1a\u63a5\u6536\u5927\u7ea6 2000 \/ 20 = 100 \u4e2a\u4fe1\u53f7\u3002 \u56e0\u6b64\u5e73\u5747\u5806\u6808\u8ddf\u8e2a\u7ea6\u4e3a\u6bcf\u79d2 100 \u4e2a\u3002<\/p>\n<p>\u4e3a\u4ec0\u4e48\u672c\u6587\u8bf4\u5806\u6808\u8ddf\u8e2a\u6bcf\u79d2\u4f1a\u4ea7\u751f 240 \u4e2a\u751a\u81f3\u66f4\u591a\u5806\u6808\u8ddf\u8e2a\uff1f<\/p>\n<p> <\/p>\n<h2>\u6b63\u786e\u7b54\u6848<\/h2>\n<p> <\/p>\n<p>\u4f3c\u4e4e\u8981\u4e3a init \u4e2d\u7684\u6240\u6709\u7ebf\u7a0b\u6dfb\u52a0 sigmask\uff1a<\/p>\n<pre>\/\/ minitSignalStack is called when initializing a new m to set the\n\/\/ alternate signal stack. If the alternate signal stack is not set\n\/\/ for the thread (the normal case) then set the alternate signal\n\/\/ stack to the gsignal stack. If the alternate signal stack is set\n\/\/ for the thread (the case when a non-Go thread sets the alternate\n\/\/ signal stack and then calls a Go function) then set the gsignal\n\/\/ stack to the alternate signal stack. We also set the alternate\n\/\/ signal stack to the gsignal stack if cgo is not used (regardless\n\/\/ of whether it is already set). Record which choice was made in\n\/\/ newSigstack, so that it can be undone in unminit.\nfunc minitSignalStack() {<\/pre>\n<p>\u6240\u4ee5\u53ea\u6709\u542f\u52a8pprof\u7684\u7ebf\u7a0b\u624d\u80fd\u63a5\u6536\u5230sigprof\u4fe1\u53f7\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300a\u662fgo pprof\u968f\u673a\u6311\u9009\u4e00\u4e2a\u7ebf\u7a0b\u63a5\u6536\u4fe1\u53f7\u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591aGolang\u77e5\u8bc6\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-207887","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207887","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=207887"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207887\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=207887"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=207887"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=207887"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}