Created
February 20, 2016 22:12
-
-
Save alk/568c0465f4f208196d8b to your computer and use it in GitHub Desktop.
Test program demonstrating skewed profile
This file contains 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
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