05-profiling

command
v0.0.0-...-35bbffe Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2015 License: Apache-2.0 Imports: 5 Imported by: 0

README

Profiling Code

We can use the go tooling in conjunction with the Graph Visualization Tools and Ghostscript. These tools will allow us to graph the profiles we create.

Note: Profiling on the Mac is broken. This post talks about how to hack to OS X Kernel to make it work.
http://research.swtch.com/macpprof
https://godoc.org/rsc.io/pprof_mac_fix

Installing Tools

download files

Dave Cheney's Profile Package

go get Dave Cheney's profiling package. He has done a nice job abstracting all the boilerplate code required. If you are interested in understanding how to do this without the profile package, read this (http://saml.rilspace.org/profiling-and-creating-call-graphs-for-go-programs-with-go-tool-pprof)

go get github.com/davecheney/profile

Graph Visualization Tools

Download the package for your target OS/Arch: http://www.graphviz.org/Download.php

Ghostscript

This is not an easy step for Mac users since there is no prebuilt distribution.

Download and uncompress the source code: http://ghostscript.com/download/gsdnld.html

./configure
make
make install

Code Changes

We need to add some changes to main to get the profiling data we need.

import "github.com/davecheney/profile"

// main is the entry point for the application.
func main() {
	cfg := profile.Config{
		MemProfile:     true,
		CPUProfile:     true,
		ProfilePath:    ".",  // store profiles in current directory
		NoShutdownHook: true, // do not hook SIGINT
	}

	// p.Stop() must be called before the program exits to
	// ensure profiling information is written to disk.
	p := profile.Start(&cfg)
	defer p.Stop()

	. . .
}

Running and Creating Profile Graph

go build
./example1
go tool pprof --pdf ./example1 cpu.pprof > callgraph.pdf
go tool pprof --pdf ./example1 mem.pprof > callgraph.pdf

// See all the options
go tool pprof -h

http://golang.org/blog/profiling-go-programs

http://golang.org/pkg/runtime/pprof/

https://golang.org/pkg/net/http/pprof/

https://godoc.org/rsc.io/pprof_mac_fix

Code Review

HTTP Service (Go Playground)


Ardan Labs Ardan Studios GoingGo Blog


All material is licensed under the Apache License Version 2.0, January 2004.

Documentation

Overview

Sample program to show off Go and check programming environment.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL