Skip to content

Conversation

@tbg
Copy link
Member

@tbg tbg commented Jan 7, 2026

Previously, when requesting profiles like allocs, heap, block, or mutex through the pprof UI endpoint (/debug/pprof/ui/allocs/?seconds=10), the seconds parameter was ignored and an immediate snapshot was returned. This differed from the behavior of Go's standard pprof handler at /debug/pprof/allocs?seconds=10, which correctly collected a delta profile over the specified duration.

The issue was in profileLocal() which handled these profile types in the default case without respecting req.Seconds. Now, when Seconds > 0 is specified, we collect two profile snapshots separated by the requested duration and compute their difference (delta profile) using the same algorithm as Go's net/http/pprof: scale the first profile by -1 and merge with the second.

This enables the pprof UI to show "recent allocations" over a specific time window rather than cumulative allocations since process start.

Release note (bug fix): Fixed a bug where the pprof UI endpoints for allocs, heap, block, and mutex profiles ignored the seconds parameter and returned immediate snapshots instead of delta profiles.

TODO: fix lint error: server/status_local_file_retrieval.go:165: ts := time.Now().UnixNano() <- forbidden; use 'timeutil' instead

Epic: none

@blathers-crl
Copy link

blathers-crl bot commented Jan 7, 2026

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

Previously, when requesting profiles like allocs, heap, block, or mutex
through the pprof UI endpoint (/debug/pprof/ui/allocs/?seconds=10), the
seconds parameter was ignored and an immediate snapshot was returned.
This differed from the behavior of Go's standard pprof handler at
/debug/pprof/allocs?seconds=10, which correctly collected a delta
profile over the specified duration.

The issue was in profileLocal() which handled these profile types in
the default case without respecting req.Seconds. Now, when Seconds > 0
is specified, we collect two profile snapshots separated by the
requested duration and compute their difference (delta profile) using
the same algorithm as Go's net/http/pprof: scale the first profile
by -1 and merge with the second.

This enables the pprof UI to show "recent allocations" over a specific
time window rather than cumulative allocations since process start.

Release note (bug fix): Fixed a bug where the pprof UI endpoints for
allocs, heap, block, and mutex profiles ignored the seconds parameter
and returned immediate snapshots instead of delta profiles.
@tbg tbg force-pushed the heap-recent-allocs branch from eaa0288 to df62cf3 Compare January 8, 2026 16:28
@tbg tbg marked this pull request as ready for review January 9, 2026 07:22
@tbg tbg requested a review from a team as a code owner January 9, 2026 07:22
@tbg tbg requested review from jasonlmfong and removed request for a team January 9, 2026 07:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants