Skip to content

fix: handle zero sample rate in pprof export - #39

Open
Jvlegod wants to merge 1 commit into
felixge:masterfrom
Jvlegod:fix-zero-sample-rate
Open

fix: handle zero sample rate in pprof export#39
Jvlegod wants to merge 1 commit into
felixge:masterfrom
Jvlegod:fix-zero-sample-rate

Conversation

@Jvlegod

@Jvlegod Jvlegod commented Jul 15, 2026

Copy link
Copy Markdown

Summary

Fix a panic in pprof export when wall-clock profiling is stopped before the first sample is collected.

In that case, sampleCount is zero, so the measured sample rate rounds to 0. Passing that value into exportPprof causes a divide-by-zero panic while calculating the profile
period.

This patch falls back to the configured sampling rate when the measured rate is less than 1.

Reproducer

A short-lived program can trigger this by starting and immediately stopping pprof-format profiling:

package main

import "github.com/felixge/fgprof"

func main() {
    stop := fgprof.Start(io.Discard, fgprof.FormatPprof)
    _ = stop()
}

Signed-off-by: Jvle <keke.oerv@isrc.iscas.ac.cn>
@Jvlegod
Jvlegod force-pushed the fix-zero-sample-rate branch from 1068571 to fd4bae0 Compare July 24, 2026 06:04
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.

1 participant