Skip to content

Instantly share code, notes, and snippets.

@alk
Created February 20, 2016 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alk/568c0465f4f208196d8b to your computer and use it in GitHub Desktop.
Save alk/568c0465f4f208196d8b to your computer and use it in GitHub Desktop.
Test program demonstrating skewed profile
package main
import (
"log"
"os"
"runtime/pprof"
"time"
)
func maybeStartProfile() func() {
v := os.Getenv("CPUPROFILE")
if v == "" {
return func() {}
}
f, err := os.OpenFile(v, os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
log.Printf("Failed to initiate profiling: %s. Ignoring", err)
return func() {}
}
pprof.StartCPUProfile(f)
return func() {
pprof.StopCPUProfile()
_ = f.Close()
}
}
func routine1() {
for {
}
}
func routine2() {
for {
}
}
func main() {
defer maybeStartProfile()()
go routine1()
go routine2()
time.Sleep(30 * time.Second)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment