Created
August 27, 2014 16:16
-
-
Save cmdrkeene/42811590c9898cb58f2f to your computer and use it in GitHub Desktop.
Scrap of a GNUPlot chart
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
// set term png | |
// set xlabel 'Samples' | |
// set ylabel 'MB' | |
// set output 'name.png' | |
// plot | |
// "name.dat" using 1:($2/1e6) title 'Sys' with lines, | |
// "name.dat" using 1:($3/1e6) title 'Alloc' with lines, | |
// "name.dat" using 1:($4/1e6) title 'Idle' with lines | |
type chart struct { | |
filename string | |
file io.WriteCloser | |
samples int | |
m runtime.MemStats | |
} | |
func newChart(name string) *chart { | |
filename := name + ".dat" | |
os.Remove(filename) | |
file, err := os.Create(filename) | |
if err != nil { | |
panic(err) | |
} | |
c := &chart{ | |
filename: filename, | |
file: file, | |
} | |
c.header() | |
return c | |
} | |
func (c *chart) header() { | |
fmt.Fprint(c.file, "# Samples\tSys\tAlloc\tIdle\tReleased\tGoroutines\n") | |
} | |
func (c *chart) Sample() { | |
c.samples++ | |
runtime.ReadMemStats(&c.m) | |
fmt.Fprintf( | |
c.file, | |
"%d\t%d\t%d\t%d\t%d\t%d\n", | |
c.samples, | |
c.m.HeapSys, | |
c.m.HeapAlloc, | |
c.m.HeapIdle, | |
c.m.HeapReleased, | |
runtime.NumGoroutine(), | |
) | |
} | |
func (c *chart) Close() error { | |
return c.file.Close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment