profiling

package
v1.38.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0, Apache-2.0 Imports: 26 Imported by: 0

README

profiling

Continuous profiling for coroot-node-agent.

profiling.go, goheap.go and prune.go are the agent's own code: process discovery, the collect and upload loop, the Go heap profiler and the async-profiler integration for the JVM.

Everything else in this directory is the eBPF CPU profiler that was ported from the ebpf module of grafana/pyroscope (Apache License 2.0, see LICENSE). Upstream stopped developing that module in March 2025. The code was taken from coroot/pyroscope at commit 758a0e72a, which already carried our fixes on top of upstream: perf map symbols, Go 1.26 pclntab, symbol bounds for stripped binaries and Python 3.14 offsets.

Compared to upstream, the port is trimmed to what the agent needs: targets are a plain service name and container id resolved by the agent (no Alloy service discovery or per-target options), logging goes through klog, the Alloy debug info plumbing is gone, and the agent decides which processes are CPython interpreters.

Layout

path what
ebpfspy/ the profiling session: attaches the perf events and kprobes, reads the stack maps, symbolizes samples
bpf/ BPF C sources, the vendored libbpf and vmlinux headers
pyrobpf/ bpf2go output for bpf/profile.bpf.c (native frame-pointer unwinder)
python/ bpf2go output for bpf/pyperf.bpf.c and the CPython, glibc and musl struct offsets per version
symtab/ ELF, Go pclntab and perf map symbol tables with caches
pprof/ builds pprof profiles from the collected samples
demangle/, cpuonline/ helpers used by the session
dwarfdump/, cmd/*_dwarfdump generators for the Python, glibc and musl offset tables

Regenerating the BPF objects

pyrobpf/*_bpfel_*.{go,o} and python/perf_bpfel_*.{go,o} are committed. After changing anything under bpf/, run:

make -C profiling bpf-generate

It runs go generate for both packages inside a Docker container with clang. The go:generate directives pin bpf2go to cilium/ebpf v0.12.3. That is the generation of bpf2go that produced the committed files: with Debian clang 14 it reproduces pyrobpf/*.o byte for byte. Releases from v0.13 on name the outputs differently (profile_x86_bpfel.o instead of profile_bpfel_x86.o) and from v0.17 on reject -type global_config_t because they emit the type on their own, so bumping the pin means regenerating and renaming the committed files in the same change.

Offset tables and test fixtures

No binary fixtures are kept in this repository. The Python, glibc and musl binaries that the offset tables under python/ are generated from, and the ELF fixtures the symtab tests use (elf/, with the Dockerfile that builds them), live in https://github.com/coroot/pyroscope-ebpf-testdata (about 3.4 GB). It is not a submodule any more. Clone it into profiling/testdata with:

make -C profiling testdata

Then make -C profiling python-offsets, glibc-offsets or musl-offsets rewrites the corresponding tables. Add the new interpreter or libc build to the fixtures repository first.

Tests that need those fixtures skip when profiling/testdata is absent. ebpfspy.TestEBPFPythonProfiler loads BPF programs and runs Docker containers, so it needs root on a Linux host and only runs when VM=1 is set, like the tracer tests.

Documentation

Index

Constants

View Source
const (
	CollectInterval = time.Minute
	SampleRate      = 100
	UploadTimeout   = 10 * time.Second
)

Variables

This section is empty.

Functions

func Init

func Init(hostId, hostName string) (chan<- containers.ProcessInfo, chan *containers.ProfilingUpdate)

func Start

func Start()

func Stop

func Stop()

Types

type TargetFinder

type TargetFinder struct {
	// contains filtered or unexported fields
}

func (*TargetFinder) FindTarget

func (tf *TargetFinder) FindTarget(pid uint32) *ebpfspy.Target

func (*TargetFinder) RemoveDeadPID

func (tf *TargetFinder) RemoveDeadPID(pid uint32)

func (*TargetFinder) Reset added in v1.38.0

func (tf *TargetFinder) Reset(pid uint32)

func (*TargetFinder) Update

func (tf *TargetFinder) Update()

Directories

Path Synopsis
cmd
glibc_dwarfdump command
musl_dwarfdump command
Package ebpfspy provides integration with Linux eBPF.
Package ebpfspy provides integration with Linux eBPF.
Code generated by glibc_dwarfdump.
Code generated by glibc_dwarfdump.
elf

Jump to

Keyboard shortcuts

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