Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime/pprof: document the requirement to wait to capture any CPU profile samples #18504

Closed
rakyll opened this issue Jan 3, 2017 · 4 comments

Comments

@rakyll
Copy link
Contributor

rakyll commented Jan 3, 2017

Package's godoc example starts the CPU profiling and defers pprof.StopCPUProfile, but it fails to document that the function need to spend sometime before returning in order for any samples to be collected. We might want to add a time.Sleep to make it more obvious and document it throughly that time is required to collect samples.

if err := pprof.StartCPUProfile(f); err != nil {
    log.Fatal("could not start CPU profile: ", err)
}
defer pprof.StopCPUProfile()
@rakyll rakyll added this to the Go1.9 milestone Jan 3, 2017
@ALTree
Copy link
Member

ALTree commented Jan 3, 2017

IMHO a call to time.Sleep is not the right thing to add if the message you want to give is "and then the code that does the work starts". That would be quite confusing ("do I have to call Sleep to make the profiler work?", I'd ask myself).

Right now there's a line with three dots after the defer:

...

I agree that's confusing. It could be replaced with a go comment that explicitly explains that after setting up the profiler in the main function, you'll need to call the actual code (the one that does the work you're going to profile).

@bradfitz
Copy link
Contributor

bradfitz commented Jan 3, 2017

The example already contains the line:

    ...

Hah, @ALTree just said the same thing.

Let's just add another bit at the bottom:

    // ... rest of program ...

@rakyll
Copy link
Contributor Author

rakyll commented Jan 3, 2017

Sorry, what I meant is having a reference of starting, sleeping, stoping in a different goroutine to give an idea this is how you profile for x seconds. I see users copy/pasting this code without much questioning and fail to collect any samples.

Improving the ... comment would also work.

@gopherbot
Copy link

CL https://golang.org/cl/36430 mentions this issue.

@golang golang locked and limited conversation to collaborators Feb 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants