pprof

package
v1.2.7 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2025 License: Apache-2.0 Imports: 7 Imported by: 3

README

Pyroscope CPU Profiler HTTP Handler

This package facilitates the collection of CPU profiles via HTTP without disrupting the background operation of the Pyroscope profiler. It enables you to seamlessly gather CPU profiles through HTTP while continuously sending them to Pyroscope.

The standard Go pprof HTTP endpoint /debug/pprof/profile returns an error if profiling is already started:

Could not enable CPU profiling: CPU profiling already in use

The Pyroscope CPU Profiler HTTP handler serve this gracefully by communicating with the Pyroscope profiler, which collects profiles in the background.

Usage

The package does not register the handler automatically. It is highly recommended to avoid using the standard path /debug/pprof/profile and the default mux because attempting to register the handler on the same path will cause a panic. In many cases, the net/http/pprof package is imported by dependencies, and therefore there is no reliable way to avoid the conflict.

package main

import (
    "net/http"

    "github.com/grafana/pyroscope-go/http/pprof"
)

func main() {
	http.HandleFunc("/debug/pprof/cpu", pprof.Profile)
}

With each invocation of the handler, it suspends the Pyroscope profiler, gathers a CPU profile, dispatches the collected profile to both the caller and the Pyroscope profiler, and subsequently resumes the profiler.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Profile

func Profile(w http.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.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL