summaryrefslogtreecommitdiffstats
path: root/docs/content/en/functions/debug
diff options
context:
space:
mode:
Diffstat (limited to 'docs/content/en/functions/debug')
-rw-r--r--docs/content/en/functions/debug/Dump.md34
-rw-r--r--docs/content/en/functions/debug/Timer.md37
-rw-r--r--docs/content/en/functions/debug/_index.md12
3 files changed, 83 insertions, 0 deletions
diff --git a/docs/content/en/functions/debug/Dump.md b/docs/content/en/functions/debug/Dump.md
new file mode 100644
index 000000000..67b264bed
--- /dev/null
+++ b/docs/content/en/functions/debug/Dump.md
@@ -0,0 +1,34 @@
+---
+title: debug.Dump
+description: Returns an object dump as a string.
+categories: []
+keywords: []
+action:
+ aliases: []
+ related: []
+ returnType: string
+ signatures: [debug.Dump VALUE]
+---
+
+```go-html-template
+<pre>{{ debug.Dump site.Data.books }}</pre>
+```
+
+```json
+[
+ {
+ "author": "Victor Hugo",
+ "rating": 4,
+ "title": "The Hunchback of Notre Dame"
+ },
+ {
+ "author": "Victor Hugo",
+ "rating": 5,
+ "title": "Les Misérables"
+ }
+]
+```
+
+{{% note %}}
+Output from this function may change from one release to the next. Use for debugging only.
+{{% /note %}}
diff --git a/docs/content/en/functions/debug/Timer.md b/docs/content/en/functions/debug/Timer.md
new file mode 100644
index 000000000..a0704dc01
--- /dev/null
+++ b/docs/content/en/functions/debug/Timer.md
@@ -0,0 +1,37 @@
+---
+title: debug.Timer
+description: Creates a named timer that reports elapsed time to the console.
+categories: []
+keywords: []
+action:
+ aliases: []
+ related: []
+ returnType: debug.Timer
+ signatures: [debug.Timer NAME]
+---
+
+{{< new-in 0.120.0 >}}
+
+Use the `debug.Timer` function to determine execution time for a block of code, useful for finding performance bottlenecks in templates.
+
+The timer starts when you instantiate it, and stops when you call its `Stop` method.
+
+```go-html-template
+{{ $t := debug.Timer "TestSqrt" }}
+{{ range seq 2000 }}
+ {{ $f := math.Sqrt . }}
+{{ end }}
+{{ $t.Stop }}
+```
+
+Use the `--logLevel info` command line flag when you build the site.
+
+```sh
+hugo --logLevel info
+```
+
+The results are displayed in the console at the end of the build. You can have as many timers as you want and if you don't stop them, they will be stopped at the end of build.
+
+```text
+INFO timer: name TestSqrt count 1002 duration 2.496017496s average 2.491035ms median 2.282291ms
+```
diff --git a/docs/content/en/functions/debug/_index.md b/docs/content/en/functions/debug/_index.md
new file mode 100644
index 000000000..418828515
--- /dev/null
+++ b/docs/content/en/functions/debug/_index.md
@@ -0,0 +1,12 @@
+---
+title: Debug functions
+linkTitle: debug
+description: Template functions to debug your templates.
+categories: []
+keywords: []
+menu:
+ docs:
+ parent: functions
+---
+
+Use these functions to debug your templates.