diff options
author | Cameron Moore <moorereason@gmail.com> | 2017-09-26 21:03:04 +0300 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-09-26 21:03:04 +0300 |
commit | b4a14c25fe85c41b79497be27ead128502a4dd7b (patch) | |
tree | 99cdbb0d9ab7a7adf137ce492773750aeec8e431 /tpl/template.go | |
parent | cb8eb472602754b310eaf7a10271149d1e1f5d75 (diff) |
metrics: Add simple template metrics feature
Diffstat (limited to 'tpl/template.go')
-rw-r--r-- | tpl/template.go | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/tpl/template.go b/tpl/template.go index 7be496df9..bdb917ba9 100644 --- a/tpl/template.go +++ b/tpl/template.go @@ -15,6 +15,7 @@ package tpl import ( "io" + "time" "text/template/parse" @@ -22,6 +23,7 @@ import ( texttemplate "text/template" bp "github.com/gohugoio/hugo/bufferpool" + "github.com/gohugoio/hugo/metrics" ) var ( @@ -66,13 +68,16 @@ type TemplateDebugger interface { // TemplateAdapter implements the TemplateExecutor interface. type TemplateAdapter struct { Template + Metrics metrics.Provider } // Execute executes the current template. The actual execution is performed // by the embedded text or html template, but we add an implementation here so // we can add a timer for some metrics. func (t *TemplateAdapter) Execute(w io.Writer, data interface{}) error { - // TODO(moorereason) metrics fmt.Println("Execute:", t.Name()) + if t.Metrics != nil { + defer t.Metrics.MeasureSince(t.Name(), time.Now()) + } return t.Template.Execute(w, data) } |