mirror of
https://github.com/mvvasilev/last_light.git
synced 2025-04-19 20:59:51 +03:00
25 lines
376 B
Go
25 lines
376 B
Go
|
package engine
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"os"
|
||
|
"runtime/pprof"
|
||
|
)
|
||
|
|
||
|
func Profile(profileName string, what func()) {
|
||
|
// Create a CPU profile file
|
||
|
f, err := os.Create(fmt.Sprintf("%s.prof", profileName))
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
defer f.Close()
|
||
|
|
||
|
// Start CPU profiling
|
||
|
if err := pprof.StartCPUProfile(f); err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
defer pprof.StopCPUProfile()
|
||
|
|
||
|
what()
|
||
|
}
|