mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-21 21:35:28 +02:00
metrics: Add simple template metrics feature
This commit is contained in:
committed by
Bjørn Erik Pedersen
parent
cb8eb47260
commit
b4a14c25fe
@@ -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)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user