<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Pprof on pemako</title>
    <link>http://pemako.cn/tags/pprof/</link>
    <description>Recent content in Pprof on pemako</description>
    <image>
      <title>pemako</title>
      <url>http://pemako.cn/images/papermod-cover.png</url>
      <link>http://pemako.cn/images/papermod-cover.png</link>
    </image>
    <generator>Hugo -- 0.146.6</generator>
    <language>en</language>
    <lastBuildDate>Thu, 09 Apr 2026 20:00:00 +0800</lastBuildDate>
    <atom:link href="http://pemako.cn/tags/pprof/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Go pprof 性能分析</title>
      <link>http://pemako.cn/go/pprof/</link>
      <pubDate>Thu, 09 Apr 2026 20:00:00 +0800</pubDate>
      <guid>http://pemako.cn/go/pprof/</guid>
      <description>&lt;p&gt;pprof 是 Golang自带的一款开箱即用的性能监控和分析工具。 go的pprof提供了2个工具供我们使用，runtime/pprof中是它的源码，net/http/pprof对源码做了简单封装，能让你在http服务中直接使用。&lt;/p&gt;
&lt;p&gt;它可以采样程序运行时的CPU、堆内存、Goroutine、锁竞争、阻塞调用、系统线程的使用情况。然后通过可视化终端或网页的形式展示给用户，用户可以通过列表、调用图、源码、火焰图、反汇编等视图去展示采集到的性能指标&lt;/p&gt;
&lt;p&gt;使用步骤&lt;/p&gt;
&lt;p&gt;1， 在代码中使用 &lt;code&gt;net/http/pprof&lt;/code&gt; 来开启，基于 &lt;code&gt;HTTP Server&lt;/code&gt; 运行&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-go&#34; data-lang=&#34;go&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;_&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;net/http/pprof&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;2， 生产 profile 文件&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-shell&#34; data-lang=&#34;shell&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# http 服务对外暴露的端口，可以是本地也可以是远程的地址&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;go tool pprof http://localhost:8090/debug/pprof/profile
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;3，使用 &lt;code&gt;web ui&lt;/code&gt; 来查看 &lt;code&gt;profile&lt;/code&gt; 文件&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-shell&#34; data-lang=&#34;shell&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt; go tool pprof -http localhost:6060 profile.gz
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;实际使用示例&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;# 第一步获取 profile 文件信息， 获取后可以直接命令行模式下查看
go tool pprof http://10.0.0.212:7866/debug/pprof/profile
Fetching profile over HTTP from http://10.0.0.212:7866/debug/pprof/profile
Saved profile in /Users/mako/pprof/pprof.polaris-server.samples.cpu.003.pb.gz
File: polaris-server
Type: cpu
Time: Jul 15, 2024 at 2:57pm (CST)
Duration: 30.03s, Total samples = 5.45s (18.15%)
Entering interactive mode (type &amp;#34;help&amp;#34; for commands, &amp;#34;o&amp;#34; for options)
(pprof)


# 使用web ui 查看
go tool pprof -http localhost:6060 pprof.polaris-server.samples.cpu.003.pb.gz
Serving web UI on http://localhost:6060
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;效果&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
