Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`go tool pprof` - how to specify source when using go modules?

Tags:

go

pprof

I switched to go modules recently and I can't seem to make pprof recognize the source files. Maybe someone here knows how to?

I tried using the -source_path and -trim_path options but I can't figure it out how to make it work.

Interestingly, typing o in the interactive mode of pprof shows the the trim_path option but not the source_path.

Just to be sure: pprof does work with local modules and showing their sources in the stack traces, right?

like image 645
Michael Nischt Avatar asked Feb 25 '26 03:02

Michael Nischt


1 Answers

It does work, I just figured it out.

You need to use both -trim_path and -source_path together.

-source_path should be set to the absolute path to your source code.

-trim_path should be set to the path that go tool pprof is saying the code should be at.

So if pprof is saying the path does not exist at /abc/your/code/main.go then set the trim path to /abc/your/code/ make sure that the -source_path contains the main.go though.

like image 81
Simon C Avatar answered Feb 27 '26 02:02

Simon C



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!