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
4
votes
3 answers

How to profile number of goroutines

Basically I want to find if my program is leaking goroutines over time. So I want to see how many goroutines are running over time. Is there any way to do this through pprof? I've done go tool pprof http://localhost:8888/debug/pprof/block. Which…
tommy_p1ckles
  • 595
  • 2
  • 6
  • 17
4
votes
1 answer

What are the dashed/dotted lines in Go's pprof web output?

In the web output of go tool pprof, what are the dashed/dotted lines? I find some mention that it could represent inlined functions, but there's no canonical reference.
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
4
votes
1 answer

golang profile with pprof, how to get hit count not duration?

how to get hit count like: (pprof) top Total: 2525 samples 298 11.8% 11.8% 345 13.7% runtime.mapaccess1_fast64 268 10.6% 22.4% 2124 84.1% main.FindLoops not, durations like: (pprof) top 2220ms of 3080ms total…
chen_767
  • 337
  • 2
  • 8
3
votes
1 answer

Format of google-perftools/pprof with heap profiling

There is a pprof utility in google-perftools package. It is utility to convert profile files from google-perftools cpuprofiler and heapprofiler into beautiful images: like https://github.com/gperftools/gperftools/tree/master/doc/pprof-test-big.gif…
osgx
  • 90,338
  • 53
  • 357
  • 513
3
votes
1 answer

Interpret pprof cpu profile - which function causes calls to allocSpan in the attached profile

The pprof cpu profile shows user code (on the left) and code from the runtime package with their consumption of cpu time. I am wondering whether it is possible to make the connection between the two except for looking at the user code, changing it,…
larsbeck
  • 665
  • 2
  • 7
  • 11
3
votes
1 answer

How to determine which goroutine is blocking execution?

all. I have a small parser that writes found data to Postgres, as database framework I use https://github.com/jackc/pgx. I write parsed data to an unbuffered channel from various goroutines. I have special goroutine where I read data from this…
3
votes
1 answer

Observing average wait time for goroutines

I'm running a server application serving a high number of QPS and for each query I perform some computation which is heavily CPU bounded. I took a trace and put a screenshot below. The x-axis is the time and the y axis is the number of…
jeremie
  • 971
  • 9
  • 19
3
votes
1 answer

"go test -cpuprofile" does not generate a full trace

Issue I have a go package, with a test suite. When I run the test suite for this package, the total runtime is ~ 7 seconds : $ go test ./mydbpackage/ -count 1 ok mymodule/mydbpackage 7.253s However, when I add a -cpuprofile=cpu.out option,…
LeGEC
  • 46,477
  • 5
  • 57
  • 104
3
votes
1 answer

go tool pprof -inuse_space much smaller than linux top shows

My program runs in background. I use linux top command, it shows 16g memory. But when I want to use go pprof -inuse_space to check the point, I gives only 200M. Where do the other memory go?
darjun
  • 63
  • 1
  • 2
3
votes
1 answer

Can I run something under pprof and pass it command line arguments?

I have a go binary, which uses cobra for subcommands. Each subcommand has it's own flags. I'd like to be able to create a CPU profile for a command with a specific set of parameters, like for example: myBinary dryRun -c configs/config.json However,…
Geo
  • 93,257
  • 117
  • 344
  • 520
3
votes
0 answers

pprof usage and interpretation

We believe our go app has a memory leak. In order to find out what's going on, we are trying with pprof. We are having a hard time though understanding the reads. When connecting to go tool pprof http://localhost:6060/debug/pprof/heap?debug=1, a…
transient_loop
  • 5,984
  • 15
  • 58
  • 117
3
votes
1 answer

golang memory explosion: newdefer

I have an program that listens on udp for log traffic, attempts to parse it, and then insert it into Redis. At a certain level of traffic, the memory seems to "explode" (Rapidly increase from a few hundred Megabytes to Gigabytes. I've grabbed a heap…
Kyle Brandt
  • 26,938
  • 37
  • 124
  • 165
2
votes
0 answers

golang pprof through http got empty profile output

We use the code below to register http endpoints and do pprof through http. However, we got almost empty output for a 30-seconds CPU profiling. Any suggestions on what we missed? func pprofRouter(router *httprouter.Router) { …
yuyang
  • 1,511
  • 2
  • 15
  • 40
2
votes
1 answer

memory usage discrepency between pprof and ps

I have been trying to profile the heap usage of a cli tool built with cobra. The pprof tool is showing like the following, Flat Flat% Sum% Cum Cum% Name Inlined? 1.58GB 49.98% 49.98% 1.58GB 49.98% os.ReadFile 1.58GB 49.98% …
arif
  • 579
  • 1
  • 7
  • 21
2
votes
1 answer

Specify jwt token when fetch profile via "go tool pprof"

My api is protected via jwt, is it possible to specify a jwt token when fetch profile via go tool pprof ? Currently, I have to config jwt middleware to bypass the /debug/pprof routes.
Eric
  • 22,183
  • 20
  • 145
  • 196
1 2
3
8 9