doulierong0334 2015-02-10 08:17 采纳率: 100%
浏览 104

pprof,没有要打印的节点

I have a memory leak in a small program. In order to find the leak, I would like to use pprof.

I set it up like this:

func main() {
    f, _ := os.Create("my_pprof.pprof")
    pprof.StartCPUProfile(f)

    go func() {
        main2()
    }()

    time.Sleep(1*time.Minute)
    pprof.StopCPUProfile()
    f.Close()
    panic("QUIT")
}

When I want to generate the graph, I have the error:

$ go tool pprof --pdf my_prog my_pprof.pprof > callgraph.pdf
No nodes to print

Why isn't possible to get nodes?

UPDATE: This program will reproduce the issue.

package main

import (
    "fmt"
    "os/exec"
    "time"
    "os"
    "log"
    "runtime/pprof"
)

func pollExec() {
    ticker := time.NewTicker(5 * time.Millisecond)
    quit := make(chan struct{})
    for {
        select {
            case <-ticker.C:
                const command = "cat"
                const arg= "my_project/src/probe/test_pprof.go"
                log.Printf("Execute command: " + command + " " + arg)
                cmd := exec.Command(command, arg)
                out, err := cmd.Output()
                if err != nil {
                    panic("Can't execute command: " + command)
                }
                fmt.Printf("Output: %s
", out)

            case <-quit:
                ticker.Stop()
                return
        }
    }
}


func main() {
    const pprofFileName = "my_project/src/probe/test.pprof"
    f, err := os.Create(pprofFileName)
    if err != nil {
        panic("Can't open file: " + pprofFileName)
    }
    pprof.StartCPUProfile(f)

    go func() {
        pollExec()
    }()

    time.Sleep(1*time.Minute)
    pprof.StopCPUProfile()
    f.Close()
    panic("QUIT")
}

I run it on:

$ uname -a
Linux ubuntu 3.13.0-34-generic #60-Ubuntu SMP Wed Aug 13 15:45:27 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

The global context is that I have a very small program pushing information based on a Unix command result. The program size is around 3MB, I have only 40MB ram to run it 24/7. When I leave the example running, the size is growing and growing. I don't know where the leak is and I am very uncomfortable with go as this is my first program in this language. For the example provided in this post, the memory consumption increased with the time:

 PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                            
16723 paralle+  20   0    6408   1700    816 S   2.0  0.2   0:00.52 test_pprof
After few minutes…
16723 paralle+  20   0    6408   1960    832 S   1.7  0.2   0:04.76 test_pprof  
  • 写回答

1条回答 默认 最新

  • Weighteen18 2021-04-29 14:42
    关注

    你好,遇到同样的问题,请问你有解决么?

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题