Skip to content

Instantly share code, notes, and snippets.

@cmdrkeene
Created August 27, 2014 16:16
Show Gist options
  • Save cmdrkeene/42811590c9898cb58f2f to your computer and use it in GitHub Desktop.
Save cmdrkeene/42811590c9898cb58f2f to your computer and use it in GitHub Desktop.
Scrap of a GNUPlot chart
// 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