Movatterモバイル変換


[0]ホーム

URL:


pprof

packagestandard library
go1.25.2Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2025 License:BSD-3-ClauseImports:19Imported by:33,337

Details

Repository

cs.opensource.google/go/go

Links

Documentation

Overview

Package pprof serves via its HTTP server runtime profiling datain the format expected by the pprof visualization tool.

The package is typically only imported for the side effect ofregistering its HTTP handlers.The handled paths all begin with /debug/pprof/.As of Go 1.22, all the paths must be requested with GET.

To use pprof, link this package into your program:

import _ "net/http/pprof"

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

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

By default, all the profiles listed inruntime/pprof.Profile areavailable (viaHandler), in addition to theCmdline,Profile,Symbol,andTrace profiles defined in this package.If you are not using DefaultServeMux, you will have to register handlerswith the mux you are using.

Parameters

Parameters can be passed via GET query params:

  • debug=N (all profiles): response format: N = 0: binary (default), N > 0: plaintext
  • gc=N (heap profile): N > 0: run a garbage collection cycle before profiling
  • seconds=N (allocs, block, goroutine, heap, mutex, threadcreate profiles): return a delta profile
  • seconds=N (cpu (profile), trace profiles): profile for the given duration

Usage examples

Use the pprof tool to look at the heap profile:

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

Or to look at a 30-second CPU profile:

go tool pprof http://localhost:6060/debug/pprof/profile?seconds=30

Or to look at the goroutine blocking profile, after callingruntime.SetBlockProfileRate in your program:

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

Or to look at the holders of contended mutexes, after callingruntime.SetMutexProfileFraction in your program:

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

The package also exports a handler that serves execution trace datafor the "go tool trace" command. To collect a 5-second execution trace:

curl -o trace.out http://localhost:6060/debug/pprof/trace?seconds=5go tool trace trace.out

To view all available profiles, openhttp://localhost:6060/debug/pprof/in your browser.

For a study of the facility in action, visithttps://blog.golang.org/2011/06/profiling-go-programs.html.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

funcCmdline

func Cmdline(whttp.ResponseWriter, r *http.Request)

Cmdline responds with the running program'scommand line, with arguments separated by NUL bytes.The package initialization registers it as /debug/pprof/cmdline.

funcHandler

func Handler(namestring)http.Handler

Handler returns an HTTP handler that serves the named profile.Available profiles can be found inruntime/pprof.Profile.

funcIndex

func Index(whttp.ResponseWriter, r *http.Request)

Index responds with the pprof-formatted profile named by the request.For example, "/debug/pprof/heap" serves the "heap" profile.Index responds to a request for "/debug/pprof/" with an HTML pagelisting the available profiles.

funcProfile

func Profile(whttp.ResponseWriter, r *http.Request)

Profile responds with the pprof-formatted cpu profile.Profiling lasts for duration specified in seconds GET parameter, or for 30 seconds if not specified.The package initialization registers it as /debug/pprof/profile.

funcSymbol

func Symbol(whttp.ResponseWriter, r *http.Request)

Symbol looks up the program counters listed in the request,responding with a table mapping program counters to function names.The package initialization registers it as /debug/pprof/symbol.

funcTraceadded ingo1.5

func Trace(whttp.ResponseWriter, r *http.Request)

Trace responds with the execution trace in binary form.Tracing lasts for duration specified in seconds GET parameter, or for 1 second if not specified.The package initialization registers it as /debug/pprof/trace.

Types

This section is empty.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp