Skip to content

Instantly share code, notes, and snippets.

@zhangguanzhang
Last active September 15, 2025 08:56
Show Gist options
  • Save zhangguanzhang/22fade9396d65372869ee8b39ae6a07d to your computer and use it in GitHub Desktop.
Save zhangguanzhang/22fade9396d65372869ee8b39ae6a07d to your computer and use it in GitHub Desktop.

Revisions

  1. zhangguanzhang revised this gist Mar 17, 2022. 1 changed file with 17 additions and 1 deletion.
    18 changes: 17 additions & 1 deletion docker_pprof.md
    Original file line number Diff line number Diff line change
    @@ -32,4 +32,20 @@ go tool pprof -http=0.0.0.0:8080 test.goroutine
    ```

    other:
    - https://segmentfault.com/a/1190000016412013
    - https://segmentfault.com/a/1190000016412013

    curl http://192.168.111.2:8001/debug/pprof/
    # output:
    <table>
    <thead><td>Count</td><td>Profile</td></thead>
    <tr><td>4524</td><td><a href='allocs?debug=1'>allocs</a></td></tr>
    <tr><td>0</td><td><a href='block?debug=1'>block</a></td></tr>
    <tr><td>0</td><td><a href='cmdline?debug=1'>cmdline</a></td></tr>
    <tr><td>1947</td><td><a href='goroutine?debug=1'>goroutine</a></td></tr>
    <tr><td>4524</td><td><a href='heap?debug=1'>heap</a></td></tr>
    <tr><td>0</td><td><a href='mutex?debug=1'>mutex</a></td></tr>
    <tr><td>0</td><td><a href='profile?debug=1'>profile</a></td></tr>
    <tr><td>10</td><td><a href='threadcreate?debug=1'>threadcreate</a></td></tr>
    <tr><td>0</td><td><a href='trace?debug=1'>trace</a></td></tr>
    </table>
  2. zhangguanzhang revised this gist Mar 17, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions docker_pprof.md
    Original file line number Diff line number Diff line change
    @@ -22,6 +22,8 @@ go tool pprof http://1x.xxx.45.162:8080/debug/pprof/goroutine

    # 或者
    curl -s http://1x.xxx.45.162:8080/debug/pprof/goroutine > test.goroutine
    curl -s http://1x.xxx.45.162:8080/debug/pprof/heap

    # 然后把`test.goroutine`拿回来转换成pdf
    yum install -y graphviz
    go tool pprof --pdf test.goroutine > goroutine.pdf
  3. zhangguanzhang created this gist Dec 1, 2021.
    33 changes: 33 additions & 0 deletions docker_pprof.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    离线环境来从现场获取docker的pprof信息步骤

    获取go的镜像

    ```shell
    while read img;
    do docker run --rm --entrypoint go $img version 2>/dev/null | grep -qw version && { echo $img;break; };
    done < <(docker images --format '{{.Repository}}:{{.Tag}}')
    ```

    转发docker的sock成tcp

    ```shell
    socat -d -d TCP-LISTEN:8081,fork,bind=0.0.0.0 UNIX:/var/run/docker.sock
    socat -d -d TCP-LISTEN:18081,fork,bind=0.0.0.0 TCP4:1.1.1.1:30000
    ```

    镜像起容器获取pprof文件

    ```shell
    go tool pprof http://1x.xxx.45.162:8080/debug/pprof/goroutine

    # 或者
    curl -s http://1x.xxx.45.162:8080/debug/pprof/goroutine > test.goroutine
    # 然后把`test.goroutine`拿回来转换成pdf
    yum install -y graphviz
    go tool pprof --pdf test.goroutine > goroutine.pdf

    go tool pprof -http=0.0.0.0:8080 test.goroutine
    ```

    other:
    - https://segmentfault.com/a/1190000016412013