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

Add ProfileFilename #53

Open
josharian opened this issue Jan 28, 2020 · 2 comments
Open

Add ProfileFilename #53

josharian opened this issue Jan 28, 2020 · 2 comments

Comments

@josharian
Copy link

Every time I use this package, I think that I can do something like:

var flagCPUProfile = flag.String("cpuprofile", "", "write a cpuprofile to `cpuprofile`")

func main() {
	if *flagCPUProfile != "" {
		defer profile.Start(profile.ProfilePath(*flagCPUProfile)).Stop()
	}

And then I run the program with -cpuprofile=somename.pprof. And there is no profile to be found.

And then I dig through the docs and discover ProfilePath is supposed to be a directory. And then I wish there was a way to provide a filename. This is because I sometimes do multiple runs, and I want to write the results to different profiles so that I can combine them, and I don't want to have to deal with creating and cleaning up a directory per profile.

May I send a PR to add ProfileFilename, or something like it?

@davecheney
Copy link
Member

Thanks for your issue. Something which is underdocuumented and arguably shouldn't be optional is the profile.ProfilePath option function.

If you use

defer profile.Start(profile.ProfilePath(".")).Stop()

It will write cpu.pprof to the $CWD.

I'm not opposed to a profile.ProfileFilename option, but I'm regretting using $TMPDIR as the default location for profiles.

@josharian
Copy link
Author

I always find ProfilePath -- the problem is that I misinterpret it as the path to the output file instead of as the path to the directory containing the output file, which will be named cpu.pprof, and which must already exist.

I definitely agree that defaulting to putting profiles in the CWD would be better.

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

No branches or pull requests

2 participants