Go pprof Operations: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(22 intermediate revisions by the same user not shown)
Line 4: Line 4:
=Make Sure an Executable Starts with the Profiling Subsystem Enabled=
=Make Sure an Executable Starts with the Profiling Subsystem Enabled=
<font color=darkkhaki>TODO</font>
<font color=darkkhaki>TODO</font>
=TLS and Certificates=


=Connect with a Browser to an Executable that Has the Profiling Subsystem Enabled=
=Connect with a Browser to an Executable that Has the Profiling Subsystem Enabled=
Line 11: Line 9:
Go to https://127.0.0.1:8443/debug/pprof/
Go to https://127.0.0.1:8443/debug/pprof/


If the process has TLS enabled, see [[]] for suggestions on how to address the issue.
If the process has TLS enabled, see [[#TLS_and_Certificates|TLS and Certificates]] for suggestions on how to address the issue.
 
=Dump Profiles=
 
Once a Go executable is started with the [[#Make_Sure_an_Executable_Starts_with_the_Profiling_Subsystem_Enabled|profiling subsystem enabled]], you can use <code>curl</code> to connect to the embedded web server and dump various [[Go_pprof_Concepts#Profile|profiles]]. Profiles can be dumped in text or binary formats.


The general syntax of the command to dump a profile in '''text''' format:
<syntaxhighlight lang='bash'>
curl -k https://localhost:<http-port>/debug/pprof/<profile-name>[?debug=1|2]
</syntaxhighlight>
where profile name can be one of <code>[[Go_pprof_Concepts#goroutine|goroutine]]</code>, <code>[[Go_pprof_Concepts#heap|heap]]</code>, <code>[[Go_pprof_Concepts#threadcreate|threadcreate]]</code>, <code>[[Go_pprof_Concepts#block|block]]</code>, <code>[[Go_pprof_Concepts#mutex|mutex]]</code>.


=Profile a Running Process=
<font color=darkkhaki>What is the difference between <code>debug=1</code> and <code>debug=2</code>?</font>


Assuming that your local 127.0.0.1 address is aliased to "localhost.somedomain.com" in <code>/etc/hosts</code> and the certificates are issued for "localhost.somedomain.com", set <code>CERT_PATH</code> to the directory that contains <code></code> and <code></code> and:
For example, to dump goroutines:
<syntaxhighlight lang='bash'>
curl -k https://localhost:8443/debug/pprof/goroutine?debug=2 > ~/tmp/goroutine-profile.txt
</syntaxhighlight>


To dump the profile in a '''binary''' format that can then be fed to [[#go_tool_pprof|go tool pprof]], use:
<syntaxhighlight lang='bash'>
<syntaxhighlight lang='bash'>
export CERT_PATH=/Users/ovidiu/some-project/config
curl -k --output ~/tmp/goroutine.bin https://localhost:8443/debug/pprof/goroutine
go tool pprof -http 127.0.0.1:8080 -tls_cert ${CERT_PATH}/localhost.somedomain.com.chain.pem -tls_key ${CERT_PATH}/localhost.somedomain.com.key.pem https://localhost.somedomain.com:8443
</syntaxhighlight>
</syntaxhighlight>


=Inspect a Running Process with a Browser=
=TLS and Certificates=
 




=Dump the Goroutines into a Text File=


=<tt>go tool pprof</tt>=
<code>go tool pprof</code> is the tool to analyze the profiles collected from the Go process.
The tool can analyze profile collected previously, or it an attach to a live process and start a web server that allows live interaction.
==<tt>go tool pprof</tt> Live==
Assuming that your local 127.0.0.1 address is aliased to "localhost.somedomain.com" in <code>/etc/hosts</code> and the certificates are issued for "localhost.somedomain.com", set <code>CERT_PATH</code> to the directory that contains the certificate and the key file:
<syntaxhighlight lang='bash'>
<syntaxhighlight lang='bash'>
curl -k https://localhost:8443/debug/pprof/goroutine?debug=2
export CERT_PATH=/Users/ovidiu/some-project/config
go tool pprof \
  -http 127.0.0.1:8080 \
  -tls_cert ${CERT_PATH}/localhost.somedomain.com.chain.pem \
  -tls_key ${CERT_PATH}/localhost.somedomain.com.key.pem \
  https://localhost.somedomain.com:8443
</syntaxhighlight>
</syntaxhighlight>


Replace the port with the actual HTTP(S) port the process is listening on.
=<tt>go tool trace</tt>=

Latest revision as of 04:33, 16 November 2024

Internal

Make Sure an Executable Starts with the Profiling Subsystem Enabled

TODO

Connect with a Browser to an Executable that Has the Profiling Subsystem Enabled

Go to https://127.0.0.1:8443/debug/pprof/

If the process has TLS enabled, see TLS and Certificates for suggestions on how to address the issue.

Dump Profiles

Once a Go executable is started with the profiling subsystem enabled, you can use curl to connect to the embedded web server and dump various profiles. Profiles can be dumped in text or binary formats.

The general syntax of the command to dump a profile in text format:

curl -k https://localhost:<http-port>/debug/pprof/<profile-name>[?debug=1|2]

where profile name can be one of goroutine, heap, threadcreate, block, mutex.

What is the difference between debug=1 and debug=2?

For example, to dump goroutines:

curl -k https://localhost:8443/debug/pprof/goroutine?debug=2 > ~/tmp/goroutine-profile.txt

To dump the profile in a binary format that can then be fed to go tool pprof, use:

curl -k --output ~/tmp/goroutine.bin https://localhost:8443/debug/pprof/goroutine

TLS and Certificates

go tool pprof

go tool pprof is the tool to analyze the profiles collected from the Go process.

The tool can analyze profile collected previously, or it an attach to a live process and start a web server that allows live interaction.

go tool pprof Live

Assuming that your local 127.0.0.1 address is aliased to "localhost.somedomain.com" in /etc/hosts and the certificates are issued for "localhost.somedomain.com", set CERT_PATH to the directory that contains the certificate and the key file:

export CERT_PATH=/Users/ovidiu/some-project/config
go tool pprof \
   -http 127.0.0.1:8080 \
   -tls_cert ${CERT_PATH}/localhost.somedomain.com.chain.pem \
   -tls_key ${CERT_PATH}/localhost.somedomain.com.key.pem \
   https://localhost.somedomain.com:8443

go tool trace