How to view profile output in Windows

1,545 views
Skip to first unread message

Greg Dow

unread,
Jun 24, 2013, 1:43:46 PM6/24/13
to golan...@googlegroups.com
Note:  I included the entire command I used (minus package name) because I don't know for sure which flags are affecting the results.

Given the following command running in Windows 7 64bit:

go test -cpu 2 -bench . -cpuprofile cpu.out -memprofile mem.out [my package name]

The command produces output in the files "cpu.out" and "mem.out" in a format I can't figure out.  It's not text (which I would have preferred), that much is certain.  Here is what I have looked into so far:

From what I can tell, "go tool pprof" is designed to run and profile a program, but not to parse and display results from previously generated profile output.  I tried installing Perl and Graphviz but am still stumped as to how or whether I am supposed to use those tools to interpret the files output during "go test".

What commands or tools am I supposed to use in a Windows environment to view profile output generated from the -cpuprofile and -memprofile flags in the "go test" command?  I have read the testing documentation at golang.org and I suspect I'm either looking in the wrong place or misunderstanding the docs that are there.

Thanks very much to those who took the time to read this.

peterGo

unread,
Jun 24, 2013, 3:57:55 PM6/24/13
to golan...@googlegroups.com
Greg,

Command go
http://golang.org/cmd/go/

Description of testing flags
http://golang.org/cmd/go/#hdr-Description_of_testing_flags

The 'go test' command takes both flags that apply to 'go test' itself and flags that apply to the resulting test binary.

Several of the flags control profiling and write an execution profile suitable for "go tool pprof"; run "go tool pprof help" for more information. The --alloc_space, --alloc_objects, and --show_bytes options of pprof control how the information is presented.

Profiling Go Programs
http://blog.golang.org/profiling-go-programs

gperftools
http://code.google.com/p/gperftools/

Peter

Greg Dow

unread,
Jun 25, 2013, 6:35:21 AM6/25/13
to golan...@googlegroups.com
Thanks, I read through all of those before posting my question and found no examples of how to actually parse something out of an existing execution profile file.  Do any of those resources you cited have an example that I missed or overlooked?  I'm imagining that the syntax would look something like this:

go tool pprof --flags_here C:\path\of\execution\profile.out

However, the existing documentation is not very clear on this and I don't even know if there are any options to provide a path to the profile file, or whether I'm supposed to start in the same directory and give filenames, or whether I am supposed to provide both a starting directory and a filename in the command line, etc.  If you or anyone else following this thread could either provide an example command line for parsing an existing profile file, or point out where in the documentation such an example can be found, I would be grateful.

Caleb Spare

unread,
Jun 25, 2013, 2:00:41 PM6/25/13
to golan...@googlegroups.com
Profiling Go Programs covers it. You need to build the binary and generate the profile, and then 'go tool pprof' to parse the output.

go tool pprof <binaryname> <profilename>

You can have go test save the binary for you with 'go test -c'.

See 'go help test' and 'go tool pprof -h' for more info.

-Caleb

brainman

unread,
Jun 25, 2013, 7:47:45 PM6/25/13
to golan...@googlegroups.com

then run `go tool pprof` to interpret the profile.

$ make havlak1.prof
./havlak1 -cpuprofile=havlak1.prof
# of loops: 76000 (including 1 artificial root node)
$ go tool pprof havlak1 havlak1.prof
Welcome to pprof!  For help, type 'help'.
(pprof)

So you need to provide your executable binary too, like:

go tool pprof --flags_here C:\your_program_executable.exe C:\path\of\execution\profile.out

Alex

Greg Dow

unread,
Jun 26, 2013, 1:31:15 PM6/26/13
to golan...@googlegroups.com
Thanks to everyone who lended assistance.  Now that I have a better understanding of the proper syntax and requirements, I was able to get pprof working and even view the web diagram on my Win7 box.  This is a great help!
Reply all
Reply to author
Forward
0 new messages