Skip to content

Instantly share code, notes, and snippets.

@xiegeo
Created May 18, 2020 08:30
Show Gist options
  • Save xiegeo/d9f12ce4cc33c16b554d861c2ce4eeee to your computer and use it in GitHub Desktop.
Save xiegeo/d9f12ce4cc33c16b554d861c2ce4eeee to your computer and use it in GitHub Desktop.
turn on go pprof with a compiler flag/tag
// +build pprof
// run `GODEBUG=gctrace=1,scavtrace=1 go test -bench=.* -benchmem -benchtime=1m -tags pprof` to prof benchmarks
package packagename
import (
"fmt"
"net/http"
_ "net/http/pprof"
"runtime"
"time"
)
func init() {
go http.ListenAndServe("localhost:8080", nil)
go func() {
for {
time.Sleep(time.Second)
runtime.GC()
fmt.Println(time.Now())
}
}()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment