{"id":3555,"date":"2021-07-04T15:57:06","date_gmt":"2021-07-04T07:57:06","guid":{"rendered":"https:\/\/wyxxt.org.cn\/?p=3555"},"modified":"2023-12-04T15:18:51","modified_gmt":"2023-12-04T07:18:51","slug":"go%e9%97%ae%e9%a2%98%e6%8e%92%e6%9f%a5","status":"publish","type":"post","link":"https:\/\/wyxxt.org.cn\/?p=3555","title":{"rendered":"go\u95ee\u9898\u6392\u67e5"},"content":{"rendered":"<h1>\u7ebf\u4e0a\u95ee\u9898\u6392\u67e5\u601d\u8def\uff08\u5982\u5ffd\u7136\u8bbf\u95ee\u53d8\u6162\uff09<\/h1>\n<ol>\n<li>\u94fe\u8def\u8ffd\u8e2a\uff08zipkin skywalking\u7b49\uff09\uff0c\u786e\u8ba4\u95ee\u9898\u5728\u54ea\u6761\u94fe\u8def\u4e0a\uff08\u662f\u5426\u662f\u56e0\u4e3a\u8c03\u7528\u522b\u4eba\u7684\u63a5\u53e3\u5f15\u8d77\u7684\uff0c\u89e3\u51b3\u65b9\u6848\u7194\u65ad\u964d\u7ea7\uff09<\/li>\n<li>\u67e5\u770b\u76f8\u5e94\u5bb9\u5668\u7684prometheus\uff0c\u89c2\u5bdfcpu\u3001\u5185\u5b58\u3001\u7f51\u5361\u3001\u78c1\u76d8\u7b49\u7b49<\/li>\n<li>cpu\u3001\u5185\u5b58\u95ee\u9898\uff0c\u6253\u5f00\u6027\u80fd\u8c03\u8bd5pprof\u5177\u4f53\u8c03\u8bd5cup\u6216\u5185\u5b58<\/li>\n<\/ol>\n<p>\u5185\u5b58\u6cc4\u6f0f\u95ee\u9898\uff0c\u901a\u5e38\u662fgoroutine\u6cc4\u6f0f\u6240\u5f15\u8d77\u7684\u3002<\/p>\n<p>\u67e5\u770bgoroutine\u6570\u91cf\uff0c\u5982\u679cgoroutine\u6570\u91cf\u8fc7\u591a\uff0c\u53ef\u80fd\u662f\u56e0\u4e3agoroutine\u6ca1\u6709\u53ca\u65f6\u9000\u51fa\u5bfc\u81f4\u5185\u5b58\u6cc4\u6f0f\u3002top\u3001list\u5b9a\u4f4d\u5230\u5177\u4f53\u4ee3\u7801\uff0c\u67e5\u770b\u6b64goroutine\u9000\u51fa\u673a\u5236\u662f\u5426\u6709\u95ee\u9898<\/p>\n<p>\u6781\u5c11\u60c5\u51b5\u662f\u4ee3\u7801\u95ee\u9898\u5bfc\u81f4\u7684\u5185\u5b58\u6cc4\u6f0f\uff0c\u9700\u8981\u8c03\u8bd5\u5185\u5b58\u6027\u80fd\uff0ctop\u547d\u4ee4\u67e5\u770b\u6d88\u8017\u5185\u5b58\u7684\u51fd\u6570 list\u547d\u4ee4\u76f4\u63a5\u5b9a\u4f4d\u76f8\u5173\u6d88\u8017\u5185\u5b58\u7684\u4ee3\u7801<\/p>\n<p>cpu\u98d9\u5347\uff0c\u901a\u5e38\u662f\u56e0\u4e3aio\u95ee\u9898\u5bfc\u81f4\u7684\uff0c\u6781\u5c11\u60c5\u51b5\u662f\u4ee3\u7801\u95ee\u9898\uff0c\u5982\u6b7b\u5faa\u73af<\/p>\n<p>\u67e5\u770b\u6027\u80fd\u76d1\u63a7\u5982prometheus\uff0c\u5982\u679ccpu wait\u8017\u65f6\uff0c\u5219\u786e\u5b9a\u662fio\u95ee\u9898<\/p>\n<p>\u6392\u67e5\u601d\u8def\u4e0e\u4e0a\u9762\u4e00\u6837\uff0ctop\u3001list\u6392\u67e5<\/p>\n<p>pprof\u8fd8\u53ef\u4ee5\u6253\u5f00\u53ef\u89c6\u5316\u754c\u9762\u67e5\u770b\uff0c\u7528\u6237\u66f4\u53cb\u597d<\/p>\n<h1>debugcharts<\/h1>\n<blockquote><p>\n  debugcharts \u76d1\u63a7\u5360\u7528\u5185\u5b58\u5927\uff0c\u751f\u4ea7\u73af\u5883\u4e0d\u5efa\u8bae\u5f00\u542f\u3002\n<\/p><\/blockquote>\n<p>\u4e00\u4e2a\u53ef\u4ee5\u5b9e\u65f6\u67e5\u770bgolang\u7a0b\u5e8f\u5185\u5b58\u3001CPU\u3001GC\u3001\u534f\u7a0b\u7b49\u53d8\u5316\u60c5\u51b5\u7684\u53ef\u89c6\u5316\u5de5\u5177<\/p>\n<pre><code class=\"language-go line-numbers\">_ \"github.com\/mkevac\/debugcharts\"\n\ngo func() {\n        log.Println(http.ListenAndServe(\"localhost:8081\", nil))\n    }()\n<\/code><\/pre>\n<p>\u8bbf\u95ee\u5730\u5740 localhost:8081\/debug\/charts<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/oss.wyxxt.org.cn\/images\/2021\/09\/18\/image-20210709161917278.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/oss.wyxxt.org.cn\/images\/2021\/09\/18\/image-20210709161928107.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/oss.wyxxt.org.cn\/images\/2021\/09\/18\/image-20210709161940501.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/oss.wyxxt.org.cn\/images\/2021\/09\/18\/image-20210709161954142.png\" alt=\"\" \/><\/p>\n<h1>prometheus<\/h1>\n<p>prometheus \u662f grafana \u7684\u63d2\u4ef6\uff0c\u652f\u6301 go \u76d1\u63a7\u7684\u53ef\u89c6\u5316<\/p>\n<pre><code class=\"language-go line-numbers\">\"github.com\/prometheus\/client_golang\/prometheus\/promhttp\"\n\ngo func() {\n        http.Handle(\"\/metrics\", promhttp.Handler())\n        log.Println(http.ListenAndServe(\"localhost:8081\", nil))\n    }()\n<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/oss.wyxxt.org.cn\/images\/2021\/09\/18\/dashboard-by-type.png\" alt=\"\" \/><\/p>\n<h1>pprof<\/h1>\n<h2>\u5f00\u542f<\/h2>\n<p>\u5f00\u542fpprof\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u8981\u52a0\u5165\u4e0b\u9762\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"language-go line-numbers\">import (\n    \"net\/http\"\n    _ \"net\/http\/pprof\"\n)\ngo func() {\n            log.Println(http.ListenAndServe(\"localhost:8081\", nil))\n}()\n<\/code><\/pre>\n<p>http:\/\/localhost:8081\/debug\/pprof\/<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/oss.wyxxt.org.cn\/images\/2021\/09\/18\/image-20210708150113829.png\" alt=\"\" \/><\/p>\n<p>heap \u5806\u5185\u5b58\u4f7f\u7528\u60c5\u51b5<\/p>\n<p>goroutine \u5f53\u524d\u5728\u8fd0\u884c\u7684goroutine\u60c5\u51b5\u4ee5\u53ca\u603b\u6570<\/p>\n<p>profile cpu\u8017\u65f6\uff0c\u4f1a\u8be6\u7ec6\u5217\u51fa\u6bcf\u4e2a\u51fd\u6570\u7684\u597d\u4e8b<\/p>\n<h2>\u4ea4\u4e92\u547d\u4ee4<\/h2>\n<pre><code class=\"language-shell line-numbers\"># \u751f\u6210 cpu profile\ngo tool pprof http:\/\/localhost:8081\/debug\/pprof\/profile\n\n# \u751f\u6210 heap profile\ngo tool pprof http:\/\/localhost:8081\/debug\/pprof\/heap\n\n# \u751f\u6210 goroutine profile\ngo tool pprof http:\/\/localhost:8081\/debug\/pprof\/goroutine\n\n# \u751f\u6210 block profile\ngo tool pprof http:\/\/localhost:8081\/debug\/pprof\/block\n\n# \u751f\u6210 mutex profile\ngo tool pprof http:\/\/localhost:8081\/debug\/pprof\/mutex\n\n# \u67e5\u770b\u524d20\n(pprof) top 20\n\n# \u76f4\u63a5\u5b9a\u4f4d\u76f8\u5173\u8017\u65f6\u7684\u4ee3\u7801\nlist func_name\n\n# web\u67e5\u770bsvg\n(pprof) web\n\n# \u751f\u6210png\u6587\u4ef6\n(pprof) png\n\n# \u67e5\u770b\u5df2\u7ecf\u4fdd\u5b58\u7684profile\u6587\u4ef6\ngo tool pprof profile \/Users\/xingzhiwei\/pprof\/pprof.samples.cpu.001.pb.gz\n<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/oss.wyxxt.org.cn\/images\/2021\/09\/18\/image-20210708152739383.png\" alt=\"\" \/><\/p>\n<pre><code class=\"language-shell line-numbers\"># \u67e5\u770b\u524d20\n(pprof) top 20\n<\/code><\/pre>\n<p>[<img decoding=\"async\" src=\"https:\/\/oss.wyxxt.org.cn\/images\/2021\/09\/18\/image-20210709143711153.png\" alt=\"\" \/><\/p>\n<pre><code class=\"language-shell line-numbers\"># \u76f4\u63a5\u5b9a\u4f4d\u76f8\u5173\u8017\u65f6\u7684\u4ee3\u7801\nlist writePacket\n<\/code><\/pre>\n<p>[<img decoding=\"async\" src=\"https:\/\/oss.wyxxt.org.cn\/images\/2021\/09\/18\/image-20210709143855178.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/oss.wyxxt.org.cn\/images\/2021\/09\/18\/profile002.png\" alt=\"\" \/><\/p>\n<pre><code class=\"language-shell line-numbers\"># \u5217\u51fa\u51fd\u6570\u8c03\u7528\u6808\n(pprof)traces\n<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/oss.wyxxt.org.cn\/images\/2021\/09\/18\/image-20210709144049481.png\" alt=\"\" \/><\/p>\n<h2>\u53ef\u89c6\u5316\u64cd\u4f5c\u754c\u9762\uff08\u5e26\u706b\u7130\u56fe\uff09<\/h2>\n<pre><code class=\"language-shell line-numbers\">go tool pprof --http=:8082 \/Users\/xingzhiwei\/pprof\/pprof.samples.cpu.004.pb.gz\n<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/oss.wyxxt.org.cn\/images\/2021\/09\/18\/image-20210709144756264.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/oss.wyxxt.org.cn\/images\/2021\/09\/18\/image-20210709144834053.png\" alt=\"\" \/><\/p>\n<h2>\u89e3\u51b3\u95ee\u9898<\/h2>\n<ol>\n<li>cpu\u8fc7\u9ad8<\/li>\n<li>\u5185\u5b58\u6cc4\u6f0f<\/li>\n<li>\u7a0b\u5e8f\u6162<\/li>\n<li>\u9501\u7684\u4e89\u7528<\/li>\n<li>\u7a0b\u5e8f\u963b\u585e<\/li>\n<\/ol>\n<p>\u67e5\u770bcpu profile\uff0c\u805a\u7126\u957f\u8017\u65f6\u51fd\u6570<\/p>\n<p>\u5982\u679c\u6709 runtime.mallocgc \u8fd9\u548c\u5185\u5b58\u5206\u914d\u4e0e\u5783\u573e\u56de\u6536\u6709\u5173<\/p>\n<h2>\u67e5\u627e\u5185\u5b58\u6cc4\u6f0f<\/h2>\n<p><strong>\u4f7f\u7528\u5185\u5b58profiling\u4e0d\u80fd\u591f\u53d1\u73b0\u5185\u5b58\u6cc4\u9732<\/strong><\/p>\n<p>profiling\u53ea\u8bb0\u5f55\u5bf9\u5185\u5b58\u5206\u914d\u60c5\u51b5\u4ee5\u53ca\u8c03\u7528\u6808\u4fe1\u606f<\/p>\n<p>\u4f7f\u7528\u76d1\u63a7\u5de5\u5177 Promethues \u89c2\u5bdf\u5185\u5b58\u8d70\u52bf\uff0c\u53ef\u4ee5\u77e5\u9053\u662f\u5426\u6709\u53d1\u751f\u5185\u5b58\u6cc4\u6f0f<\/p>\n<p><code>\u5185\u5b58\u6cc4\u6f0f\u901a\u5e38\u662f\u56e0\u4e3agoroutine\u6cc4\u6f0f\u6240\u5f15\u8d77\u7684<\/code><\/p>\n<pre><code class=\"language-shell line-numbers\"># \u751f\u6210 heap profile\ngo tool pprof http:\/\/localhost:8081\/debug\/pprof\/heap\n\ntop 5\n\nlist main.main\n<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/oss.wyxxt.org.cn\/images\/2021\/09\/18\/image-20210823103716760.png\" alt=\"\" \/><\/p>\n<pre><code class=\"language-shell line-numbers\">(pprof) trace\n#\u6253\u5370\u6240\u6709\u8c03\u7528\u6808\uff0c\u4ee5\u53ca\u8c03\u7528\u6808\u7684\u6307\u6807\u4fe1\u606f\n<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/oss.wyxxt.org.cn\/images\/2021\/09\/18\/image-20210823103917401.png\" alt=\"\" \/><\/p>\n<pre><code class=\"language-shell line-numbers\"># -sample_index \u53c2\u6570\uff0c\u53ef\u4ee5\u5207\u6362\u5185\u5b58\u5206\u6790\u7684\u7c7b\u578b\ngo tool pprof -sample_index=alloc_space \/Users\/xingzhiwei\/pprof\/pprof.alloc_objects.alloc_space.inuse_objects.inuse_space.002.pb.gz\n\ngo tool pprof --http=:8082 \/Users\/xingzhiwei\/pprof\/pprof.alloc_objects.alloc_space.inuse_objects.inuse_space.002.pb.gz\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>\u7c7b\u578b<\/th>\n<th>\u542b\u4e49<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>inuse_space<\/td>\n<td>amount of memory allocated and npt released yet<\/td>\n<\/tr>\n<tr>\n<td>inuse_objects<\/td>\n<td>amount of objects allocated and not released yet<\/td>\n<\/tr>\n<tr>\n<td>alloc_space<\/td>\n<td>total amount of memory allocated (regardless of released)<\/td>\n<\/tr>\n<tr>\n<td>alloc_objects<\/td>\n<td>total amount of objects allocated (regardless of released)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><img decoding=\"async\" src=\"https:\/\/oss.wyxxt.org.cn\/images\/2021\/09\/18\/image-20210701111108034.png\" alt=\"\" \/><\/p>\n<h2>goroutine\u6cc4\u6f0f<\/h2>\n<ol>\n<li>\u6bcf\u4e2agoroutine\u53602kb<\/p>\n<\/li>\n<li>\n<p>goroutine\u6267\u884c\u8fc7\u7a0b\u4e2d\uff0c\u6709\u4e9b\u53d8\u91cf\u53ea\u60f3\u5806\u5185\u5b58\uff0cgc\u56de\u8ba4\u4e3a\u5185\u5b58\u4ecd\u7136\u5728\u4f7f\u7528\uff0c\u4e0d\u4f1a\u56de\u6536\uff08\u8fd9\u90e8\u5206heap profile\u80fd\u4f53\u73b0\u51fa\u6765\uff09<\/p>\n<blockquote><p>\n  \u5982\u679c\u4e0d\u77e5\u9053\u4f55\u65f6\u505c\u6b62\u4e00\u4e2agoroutine\uff0c\u8fd9\u4e2agoroutine\u5c31\u662f\u6f5c\u5728\u7684\u5185\u5b58\u6cc4\u9732\n<\/p><\/blockquote>\n<\/li>\n<\/ol>\n<p>\u5982\u4f55\u5224\u65ad\u662fgoroutine\u6cc4\u6f0f\u5bfc\u81f4\u7684\u5185\u5b58\u6cc4\u6f0f\uff0c\u76d1\u63a7goroutine\u6570\u91cf\uff0cgoroutine\u6301\u7eed\u589e\u957f\uff0c\u5219\u53ef\u80fd\u662fgoroutine\u6cc4\u6f0f<\/p>\n<pre><code class=\"language-shell line-numbers\"># \u751f\u6210 goroutine profile\ngo tool pprof http:\/\/localhost:8081\/debug\/pprof\/goroutine\n\ntop\n\n# \u91cd\u590d\u4e24\u6b21\u4ee5\u4e0a\u64cd\u4f5c\uff0c\u770b\u770b\u662f\u54ea\u4e2agoroutine\u6cc4\u6f0f\n\n# \u4e24\u4e2a\u6bd4\u8f83\ngo tool pprof -base pprof.leak_demo.goroutine.001.pb.gz pprof.leak_demo.goroutine.002.pb.gz\n\nlist\n\ngo tool trace trace.out\n\ntraces\n\n\n<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/oss.wyxxt.org.cn\/images\/2021\/09\/18\/image-20210823110010097.png\" alt=\"\" \/><\/p>\n<h1>trace<\/h1>\n<h3>gc trace<\/h3>\n<ol>\n<li>GODEBUG=gctrace=1<\/li>\n<\/ol>\n<pre><code class=\"language-shell line-numbers\">go build main.go -o main\nGODEBUGE=gctrace=1 .\/main\n\nGODEBUG=gctrace=1 go run main.go\n\n# GODEBUG \u53c2\u6570\u8fd8\u6709 schedtrace=1 scheddetail=1 Go Runtime Scheduler \u72b6\u6001\u4fe1\u606f\n<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/oss.wyxxt.org.cn\/images\/2021\/09\/18\/image-20210706094959970.png\" alt=\"\" \/><\/p>\n<table>\n<thead>\n<tr>\n<th align=\"left\">\u5b57\u6bb5<\/th>\n<th align=\"left\">\u542b\u4e49<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"left\">gc 1<\/td>\n<td align=\"left\">\u7b2c\u4e00\u4e2agc\u5468\u671f<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">@0.005s<\/td>\n<td align=\"left\">\u7a0b\u5e8f\u5f00\u59cb\u540e\u76840.005s<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">4%<\/td>\n<td align=\"left\">\u6539gc\u5468\u671f\u4e2dcpu\u7684\u4f7f\u7528\u7387<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">0.013<\/td>\n<td align=\"left\">\u6807\u8bb0\u5f00\u59cb\u65f6\uff0cSTW\u6240\u82b1\u8d39\u7684\u65f6\u95f4\uff08wall clock\uff09<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">0.72<\/td>\n<td align=\"left\">\u6807\u8bb0\u8fc7\u7a0b\u4e2d\uff0c\u5e76\u53d1\u6807\u8bb0\u6240\u82b1\u8d39\u7684\u65f6\u95f4\uff08wall clock\uff09<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">0.059<\/td>\n<td align=\"left\">\u6807\u8bb0\u7ec8\u6b62\u65f6\uff0cSTW\u6240\u82b1\u8d39\u7684\u65f6\u95f4\uff08wall clock\uff09<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">0.10<\/td>\n<td align=\"left\">\u6807\u8bb0\u5f00\u59cb\u65f6\uff0cSTW\u6240\u82b1\u8d39\u7684\u65f6\u95f4\uff08cpu time\uff09<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">0.94<\/td>\n<td align=\"left\">\u6807\u8bb0\u8fc7\u7a0b\u4e2d\uff0c\u6807\u8bb0\u8f85\u52a9\u6240\u82b1\u8d39\u7684\u65f6\u95f4\uff08cpu time\uff09<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">0.78<\/td>\n<td align=\"left\">\u6807\u8bb0\u8fc7\u7a0b\u4e2d\uff0c\u5e76\u53d1\u6807\u8bb0\u6240\u82b1\u8d39\u7684\u65f6\u95f4\uff08cpu time\uff09<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">0<\/td>\n<td align=\"left\">\u6807\u8bb0\u8fc7\u7a0b\u4e2d\uff0cgc\u7a7a\u95f2\u7684\u65f6\u95f4\uff08cpu time\uff09<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">0.47<\/td>\n<td align=\"left\">\u6807\u8bb0\u7ec8\u6b62\u65f6\uff0cSTW\u6240\u82b1\u8d39\u7684\u65f6\u95f4\uff08cpu time\uff09<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">4<\/td>\n<td align=\"left\">\u6807\u8bb0\u5f00\u59cb\u65f6\uff0c\u5806\u7684\u5927\u5c0f\u7684\u5b9e\u9645\u503c<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">4<\/td>\n<td align=\"left\">\u6807\u8bb0\u7ed3\u675f\u65f6\uff0c\u5806\u7684\u5927\u5c0f\u7684\u5b9e\u9645\u503c<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">1<\/td>\n<td align=\"left\">\u6807\u8bb0\u7ed3\u675f\u65f6\uff0c\u6807\u8bb0\u4e3a\u5b58\u6d3b\u7684\u5bf9\u8c61\u5927\u5c0f<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">5<\/td>\n<td align=\"left\">\u6807\u8bb0\u7ed3\u675f\u65f6\uff0c\u5806\u7684\u5927\u5c0f\u7684\u9884\u6d4b\u503c<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">8<\/td>\n<td align=\"left\">P\u7684\u6570\u91cf<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>wall clock \u662f\u6307\u5f00\u59cb\u6267\u884c\u5230\u5b8c\u6210\u6240\u7ecf\u5386\u7684\u5b9e\u9645\u65f6\u95f4\uff0c\u5305\u62ec\u5176\u4ed6\u7a0b\u5e8f\u548c\u672c\u7a0b\u5e8f\u6240\u6d88\u8017\u7684\u65f6\u95f4\uff1b<\/p>\n<p>cpu time \u662f\u6307\u7279\u5b9a\u7a0b\u5e8f\u4f7f\u7528 cpu \u7684\u65f6\u95f4\uff1b\u5b83\u4eec\u5b58\u5728\u4ee5\u4e0b\u5173\u7cfb\uff1a<\/p>\n<blockquote><p>\n  wall clock &lt; cpu time:\u5145\u5206\u5229\u7528\u591a\u6838<\/p>\n<p>  wall clock \u2248 cpu time:\u672a\u5e76\u884c\u6267\u884c<\/p>\n<p>  wall clock > cpu time:\u591a\u6838\u4f18\u52bf\u4e0d\u660e\u663e\n<\/p><\/blockquote>\n<h3>trace \u5de5\u5177<\/h3>\n<ol start=\"2\">\n<li>go tool trace<\/li>\n<\/ol>\n<pre><code class=\"language-go line-numbers\">f, err := os.Create(\"trace.out\")\n    if err != nil {\n        panic(err)\n    }\n    defer f.Close()\n\n    err = trace.Start(f)\n    if err != nil {\n        panic(err)\n    }\n    defer trace.Stop()\n<\/code><\/pre>\n<pre><code class=\"language-shell line-numbers\">go tool trace trace.out\n<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/oss.wyxxt.org.cn\/images\/2021\/09\/18\/image-20210706100746357.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/oss.wyxxt.org.cn\/images\/2021\/09\/18\/image-20210706100811783.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/oss.wyxxt.org.cn\/images\/2021\/09\/18\/image-20210706100850922.png\" alt=\"\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7ebf\u4e0a\u95ee\u9898\u6392\u67e5\u601d\u8def\uff08\u5982\u5ffd\u7136\u8bbf\u95ee\u53d8\u6162\uff09 \u94fe\u8def\u8ffd\u8e2a\uff08zipkin skywalking\u7b49\uff09\uff0c\u786e\u8ba4\u95ee\u9898\u5728\u54ea\u6761\u94fe\u8def\u4e0a\uff08\u662f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[15],"tags":[398],"class_list":["post-3555","post","type-post","status-publish","format-standard","hentry","category-15","tag-go"],"_links":{"self":[{"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=\/wp\/v2\/posts\/3555","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3555"}],"version-history":[{"count":2,"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=\/wp\/v2\/posts\/3555\/revisions"}],"predecessor-version":[{"id":3582,"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=\/wp\/v2\/posts\/3555\/revisions\/3582"}],"wp:attachment":[{"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3555"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3555"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3555"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}