Skip to content

Instantly share code, notes, and snippets.

@awreece
Created April 15, 2012 20:30
Show Gist options
  • Save awreece/2394699 to your computer and use it in GitHub Desktop.
Save awreece/2394699 to your computer and use it in GitHub Desktop.
go tool pprof error
$ ./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
// 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