| 
 | 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>.  | 
0 commit comments