Created
July 31, 2018 16:25
-
-
Save RaheelYawar/431ea1751da4caa1ff9171467cbd9d03 to your computer and use it in GitHub Desktop.
Golang Memory Profiler
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
var memProfile = flag.String("memprofile", "./profile/mem.prof", "write profile to file") | |
// Run the memory profiler and write profile to file. | |
func executeMemoryProfiler() { | |
flag.Parse() | |
if *memProfile != "" { | |
f, err := os.Create(*memProfile) | |
if err != nil { | |
log.Fatal("could not create memory profile: ", err) | |
} | |
runtime.GC() // get up-to-date statistics | |
if err := pprof.WriteHeapProfile(f); err != nil { | |
log.Fatal("could not write memory profile: ", err) | |
} | |
f.Close() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment