Questions tagged [pprof]

pprof is a golang package used to profile various runtime properties of golang's http server.

Golang's pprof package serves via its HTTP server runtime profiling data in the format expected by the pprof visualization tool.

The package is typically only imported for the side effect of registering its HTTP handlers. The handled paths all begin with /debug/pprof/.

To use pprof, link this package into your program:

import _ "net/http/pprof"

If your application is not already running an http server, you need to start one. Add "net/http" and "log" to your imports and the following code to your main function:

go func() {
    log.Println(http.ListenAndServe("localhost:6060", nil))
}()

Then use the pprof tool to look at the heap profile:

go tool pprof http://localhost:6060/debug/pprof/heap

Useful links

133 questions
7
votes
1 answer

How does gperftools work under the hood?

I am looking for a simple explanation of how gperftools works. So far, this is what I have learned: It runs a stop-the-world sampler. In other words, it periodically stops the program being profiled to collect information. Golang's pprof library…
Ben Sandler
  • 2,223
  • 5
  • 26
  • 36
7
votes
2 answers

Go(lang): How to use PPROF heap profile to find memory leaks?

I am trying to use pprof to verify memory leaks. Can any explain how to read the heap profile that you find at: http://localhost:6060/debug/pprof/heap?debug=1 Also, is it normal that by typing the web command after starting go tool pprof…
Daniele B
  • 19,801
  • 29
  • 115
  • 173
6
votes
1 answer

How to interpret go pprof/mutex showing waiting on Unlock?

I'm optimizing Go program performance. While looking at mutex profiling, I got > go tool pprof -seconds 30 -ignore .*Shopify.* http://HOST/debug/pprof/mutex (pprof) top 20 Active filters: ignore=.*Shopify.* Showing nodes accounting for 3.08mins,…
Ray Wu
  • 993
  • 16
  • 34
6
votes
1 answer

Can I download a heap dump to run pprof on later?

I'm trying to find a way to store the heap data from pprof so that I can share it, view it later, attach to issues and so on. My attempts so far have not worked. If I run go tool pprof http://my-server/debug/pprof/heap and then run web, I get a full…
captncraig
  • 22,118
  • 17
  • 108
  • 151
6
votes
2 answers

pprof CPU profile of a go application does not show any samples

I'm profiling a Go application with pprof. The application is using about 4-10% CPU and leaving it running for a short while produces a profile of around 6-11kb. This suggests to me that it should be able to sample some activity. When I view the…
Arnout Engelen
  • 6,709
  • 1
  • 25
  • 36
6
votes
3 answers

Can't get golang pprof working

I have tried to profile some golang applications but I couldn't have that working, I have followed these two tutorials:…
Fersca
  • 946
  • 2
  • 9
  • 10
6
votes
1 answer

Is it possible to increase the sample rate when profiling go programs?

I have a small program in go that executes most of its code in parallel using go routines. I start CPU profiling as described in the blog on profiling go programs, but when I look at the data I see only 3-5 samples (the actual runtime of the program…
Benjamin K.
  • 1,085
  • 3
  • 15
  • 24
6
votes
1 answer

Why 'Total MB' in golang heap profile is less than 'RES' in top?

I have a service written in go that takes 6-7G memory at runtime (RES in top). So I used the pprof tool trying to figure out where the problem is. go tool pprof --pdf http:///debug/pprof/heap > heap_prof.pdf But there are only about 1-2G…
Tianran Shen
  • 921
  • 2
  • 9
  • 11
5
votes
2 answers

Strange behavior of time.Since()

I am running a GO (1.9.2) program and I have code similar to: startTime := time.Now() ... ... fmt.Printf("%v (1) %v \n", user.uid, int64(time.Since(startTime))) fmt.Printf("%v (F) %v \n", user.uid, int64(time.Since(startTime))) (The two fmt…
Buzzy
  • 2,905
  • 3
  • 22
  • 31
5
votes
1 answer

How to get a function-duration breakdown in go (profiling)

Update (Jan 24, 2019): This question was asked 4 years ago about Go 1.4 (and is still getting views). Profiling with pprof has changed dramatically since then. Original Question: I'm trying to profile a go martini based server I wrote, I want to…
Ronna
  • 1,150
  • 14
  • 24
4
votes
1 answer

How and when does Go allocate memory for bounded-queue channels?

I'm using Go's pprof tool to investigate my service's memory usage. Almost all of the memory usage comes from a single function that sets up multiple bounded-queue channels. I'm somewhat confused by what pprof is telling me here: $ go tool pprof…
Greg Owen
  • 947
  • 8
  • 19
4
votes
0 answers

How to run CPU profile of a specific function using pprof?

This blog details how to run CPU profile using pprof. When profiling, a function like main may disappear from the sample because pprof truncates the sample to the bottom 100 stack frames. This is documented: In fact the total for main.FindLoops and…
bli00
  • 2,215
  • 2
  • 19
  • 46
4
votes
1 answer

How to calculate pprof output and avoid pprof to drop nodes which their cum is less than 0.10s

I'm trying to figure out how pprof calculates the %cum of each node in my Go application output. I've attached part of my pprof png output to emphesise the problem which I'm trying to figure out pprof png output In this part of the pprof output…
torpido
  • 63
  • 9
4
votes
1 answer

"Memory used" metric: Go tool pprof vs docker stats

I wrote a golang application running in each of my docker containers. It communicates with each other using protobufs via tcp and udp and I use Hashicorp's memberlist library to discover each of the containers in my network. On docker stats I see…
Anu
  • 400
  • 1
  • 4
  • 19
4
votes
1 answer

Go pprof: Got Error unrecognized profile format

I'm developing a web program with Go revel framework(my go version is 1.6.2). And I got issues with the memory usage. The memory occupied by revel is increasing almost hundreds of MB every day. So I want to tune the program. Then I learn to use the…
Victor
  • 51
  • 1
  • 6
1
2
3
8 9