diff --git a/main.go b/main.go index 84dcf01..8b8d547 100644 --- a/main.go +++ b/main.go @@ -3,11 +3,12 @@ // // usage: // -// gcvis program [arguments]... +// gcvis program [arguments]... package main import ( "bufio" + "encoding/json" "fmt" "html/template" "io" @@ -24,10 +25,9 @@ import ( "github.com/pkg/browser" ) -func startSubprocess(w io.Writer) { +func startSubprocess(args []string, w io.Writer) { env := os.Environ() env = append(env, "GODEBUG=gctrace=1") - args := os.Args[1:] cmd := exec.Command(args[0], args[1:]...) cmd.Env = env cmd.Stdin = os.Stdin @@ -80,7 +80,7 @@ var mu sync.RWMutex func index(w http.ResponseWriter, req *http.Request) { mu.RLock() defer mu.RUnlock() - visTmpl.Execute(w, struct { + visIndexTmpl.Execute(w, struct { HeapUse, ScvgInuse, ScvgIdle, ScvgSys, ScvgReleased, ScvgConsumed []graphPoints Title string }{ @@ -92,10 +92,30 @@ func index(w http.ResponseWriter, req *http.Request) { ScvgConsumed: scvgconsumed, Title: strings.Join(os.Args[1:], " "), }) +} +func ajax(w http.ResponseWriter, req *http.Request) { + mu.RLock() + defer mu.RUnlock() + toJsonString := func(g []graphPoints) string { + j, _ := json.Marshal(g) + return string(j) + } + visAjaxTmpl.Execute(w, struct { + HeapUse, ScvgInuse, ScvgIdle, ScvgSys, ScvgReleased, ScvgConsumed string + Title string + }{ + HeapUse: toJsonString(heapuse), + ScvgInuse: toJsonString(scvginuse), + ScvgIdle: toJsonString(scvgidle), + ScvgSys: toJsonString(scvgsys), + ScvgReleased: toJsonString(scvgreleased), + ScvgConsumed: toJsonString(scvgconsumed), + Title: strings.Join(os.Args[1:], " "), + }) } -var visTmpl = template.Must(template.New("vis").Parse(` +var visIndexTmpl = template.Must(template.New("vis-index").Parse(` gcvis - {{ .Title }} @@ -107,73 +127,115 @@ var visTmpl = template.Must(template.New("vis").Parse(`