Skip to content

Commit 43d4a29

Browse files
committed
[docs] dev-docs - add performance profiling directory
1 parent 3ec9918 commit 43d4a29

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
To perform fine-grained profiling of Pandoc Lua filters, we use custom binaries:
2+
3+
- a patch of Lua that supports sample-based profiling
4+
- a custom binary of Pandoc linked against that version of Lua
5+
6+
## Compile the custom Lua version
7+
8+
This has currently only been tested on Macos and Linux.
9+
10+
```
11+
$ git clone [email protected]:cscheid/lua-fast-profiler.git
12+
$ cd lua-fast-profiler
13+
$ git checkout feature/fast-profiler-5.4
14+
$ make
15+
```
16+
17+
You should have `lua` and `liblua.a` in the `lua-fast-profiler` directory.
18+
19+
This version of Lua adds a new debugging hook, "time".
20+
This hook triggers at specified intervals, and is enabled using the letter `t` in the `debug.sethook` call.
21+
The debug hook callback also supports the "alarm" hook, used when calling the `sethook` callback.
22+
23+
Quarto ships with a custom Lua profiler that supports these hooks and performs low-overhead stack profiling.
24+
25+
## Compile the custom Pandoc binary
26+
27+
Clone the Pandoc repository, and then
28+
29+
```
30+
$ C_INCLUDE_PATH=<path-lua-fast-profiler> LIBRARY_PATH=<path-lua-fast-profiler> cabal build pandoc-cli --constraint 'lua +system-lua'
31+
```
32+
33+
## Use the custom Pandoc binary
34+
35+
```
36+
$ QUARTO_PANDOC=<path-to-built-pandoc> quarto render ...
37+
```
38+
39+
To get Lua profiling output from Quarto, use the `lua-profiler-output` metadata option to provide an output file name.
40+
The output will be written as JSON, in a format compatible with [Perfetto](https://ui.perfetto.dev).
41+
The default sampling interval is 5ms, but you can customize that by setting the `lua-profiler-interval-ms` metadata option.
42+
43+
## Analyze profile
44+
45+
The resulting profile can be visualized and analyzed as a trace file at <https://ui.perfetto.dev>.

src/resources/filters/ast/runemulation.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ local function emulate_pandoc_filter(filters, afterFilterPass)
131131
return {
132132
traverse = 'topdown',
133133
Pandoc = function(doc)
134-
local profiling = option("profiler-output", false)
134+
local profiling = option("lua-profiler-output", false)
135135
if not profiling then
136136
return run_emulated_filter_chain(doc, filters, afterFilterPass), false
137137
end
@@ -141,7 +141,7 @@ local function emulate_pandoc_filter(filters, afterFilterPass)
141141
profiler = require('profiler')
142142
end
143143
pandoc.system.with_temporary_directory("temp", function(tmpdir)
144-
profiler.start(tmpdir .. "/prof.txt")
144+
profiler.start(tmpdir .. "/prof.txt", tonumber(option("lua-profile-interval-ms", "5")))
145145
doc = run_emulated_filter_chain(doc, filters, afterFilterPass, profiling)
146146
profiler.stop()
147147
-- os.execute("cp " .. tmpdir .. "/prof.txt /tmp/prof.out")

0 commit comments

Comments
 (0)