package memsizeui
import (
"html/template"
"strconv"
"sync"
"github.com/fjl/memsize"
)
var (
base *template.Template // the "base" template
baseInitOnce sync.Once
)
func baseInit() {
base = template.Must(template.New("base").Parse(`
memsize
{{template "content" .}}
`))
base.Funcs(template.FuncMap{
"quote": strconv.Quote,
"humansize": memsize.HumanSize,
})
template.Must(base.New("rootbuttons").Parse(`
Overview
{{- range $root := .Roots -}}
{{- end -}}`))
}
func contentTemplate(source string) *template.Template {
baseInitOnce.Do(baseInit)
t := template.Must(base.Clone())
template.Must(t.New("content").Parse(source))
return t
}
var rootTemplate = contentTemplate(`
Memsize
{{template "rootbuttons" .}}
Reports
`)
var notFoundTemplate = contentTemplate(`
{{.Data}}
{{template "rootbuttons" .}}
`)
var reportTemplate = contentTemplate(`
{{- $report := .Data -}}
Memsize Report {{$report.ID}}
Root: {{quote $report.RootName}}
Date: {{$report.Date}}
Duration: {{$report.Duration}}
Bitmap Size: {{$report.Sizes.BitmapSize | humansize}}
Bitmap Utilization: {{$report.Sizes.BitmapUtilization}}
{{$report.Sizes.Report}}
`)