Last active
August 29, 2015 14:23
-
-
Save xlab/93eb6b259893456cb508 to your computer and use it in GitHub Desktop.
goprofile graphs
This file contains hidden or 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
memstats := cmd.Flag.Lookup("memstats").Value.String() | |
if memstats != "" { | |
interval := cmd.Flag.Lookup("meminterval").Value.Get().(time.Duration) | |
context.fileMemStats, err = os.Create(memstats) | |
if err != nil { | |
return err | |
} | |
context.fileMemStats.WriteString("# Time\tHeapSys\tHeapAlloc\tHeapIdle\tHeapReleased\n") | |
go func() { | |
var stats runtime.MemStats | |
start := time.Now().UnixNano() | |
for { | |
runtime.ReadMemStats(&stats) | |
if context.fileMemStats != nil { | |
context.fileMemStats.WriteString(fmt.Sprintf("%d\t%d\t%d\t%d\t%d\n", | |
(time.Now().UnixNano()-start)/1000000, stats.HeapSys, stats.HeapAlloc, stats.HeapIdle, stats.HeapReleased)) | |
time.Sleep(interval) | |
} else { | |
break | |
} | |
} | |
}() | |
} |
This file contains hidden or 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
set output 'mem.png' | |
set term png | |
set key box left | |
set xlabel "Time (msec)" | |
set ylabel "Mem (MB)" | |
plot "mem.dat" using 1:($2/1e6) title 'HeapSys' with lines, "mem.dat" using 1:($3/1e6) title 'HeapAlloc' with lines, "mem.dat" using 1:($4/1e6) title 'HeapIdle' with lines |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment