You've already forked go-profiler-notes
mirror of
https://github.com/DataDog/go-profiler-notes.git
synced 2025-07-15 23:54:16 +02:00
Add CPU profiler section
This commit is contained in:
37
guide/cpu-max-stack-depth.go
Normal file
37
guide/cpu-max-stack-depth.go
Normal file
@ -0,0 +1,37 @@
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"runtime/pprof"
|
||||
)
|
||||
|
||||
func main() {
|
||||
pprof.StartCPUProfile(os.Stdout)
|
||||
defer pprof.StopCPUProfile()
|
||||
|
||||
belowLimit()
|
||||
aboveLimit()
|
||||
}
|
||||
|
||||
func belowLimit() {
|
||||
atDepth(32, cpuHog)
|
||||
}
|
||||
|
||||
func aboveLimit() {
|
||||
atDepth(64, cpuHog)
|
||||
}
|
||||
|
||||
func cpuHog() {
|
||||
for i := 0; i < 5000*1000*1000; i++ {
|
||||
}
|
||||
}
|
||||
|
||||
func atDepth(n int, fn func()) {
|
||||
if n > 0 {
|
||||
atDepth(n-1, fn)
|
||||
} else {
|
||||
fn()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user