Created
April 15, 2012 20:30
-
-
Save awreece/2394699 to your computer and use it in GitHub Desktop.
go tool pprof error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./malloctest --proc=2 --iters=100 --prof 2>out2.prof | |
$ go tool pprof malloctest out2.prof | |
out2.prof: header size >= 2**16 | |
go tool pprof: exit status 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// malloc test for false sharing | |
package main | |
import ( | |
"flag" | |
"os" | |
"runtime" | |
"runtime/pprof" | |
"sync" | |
) | |
var ( | |
procs int | |
allocsize int | |
niters int | |
prof bool | |
) | |
func init() { | |
flag.IntVar(&procs, "procs", 1, "Value to set GOMAXPROCS") | |
flag.IntVar(&allocsize, "size", 16, "Size of block to allocate") | |
flag.IntVar(&niters, "iters", 10000, "Number of repetitions to make") | |
flag.BoolVar(&prof, "proff", false, "Emit profiling data to stderr") | |
} | |
func do_thread(niters int, wg *sync.WaitGroup) { | |
runtime.LockOSThread() | |
for iter := 0; iter < niters; iter++ { | |
b := make([]byte, allocsize) | |
// Write a bunch to b. | |
for i, _ := range b { | |
b[i] = byte(i) | |
} | |
// Intentionally drop a reference to b. | |
b = nil | |
} | |
wg.Done() | |
runtime.UnlockOSThread() | |
} | |
func main() { | |
flag.Parse() | |
runtime.GC() // clean up garbage from init | |
runtime.GOMAXPROCS(procs) | |
if prof { | |
pprof.StartCPUProfile(os.Stderr) | |
} | |
var wg sync.WaitGroup | |
for i := 0; i < procs; i++ { | |
wg.Add(1) | |
go do_thread(niters/procs, &wg) | |
} | |
wg.Wait() | |
if prof { | |
pprof.StopCPUProfile() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment