Thursday, April 04, 2013

lulip: a line-level profiler for LuaJIT

If you are doing profiling of code written in Lua and running in LuaJIT it can be useful to know where your code is 'hot'. Using the debug.sethook I've put together a small profiler that outputs an HTML page showing execution times on a per-line basis.  It's called lulip.

Usage is simple:
And it creates a HTML showing the lines that consume the most time with the total time in ms, the number of times the line was executed and the line itself colorized.

For example,

file:linecount elapsed (ms)line
wr.lua:11292822.455 hash = ngx_sha1_bin(value)
wr.lua:1172428470.849 captures, err = ngx_re_match(v, p)
wr.lua:11973762207.487 x = string_find(v, f)
wr.lua:212157154.386 string_gsub(v, "//([^/]+)//", "%1")
wr.lua:1196378887.475 for i=1,g() do
wr.lua:1158156352.906 if not f() then

LuaJIT is required because I used the FFI interface to get interface to the gettimeofday function to get microsecond timing. LuaJIT makes this trivial to do:


If you enjoyed this blog post, you might enjoy my travel book for people interested in science and technology: The Geek Atlas. Signed copies of The Geek Atlas are available.

<$BlogCommentBody$>

<$BlogCommentDateTime$> <$BlogCommentDeleteIcon$>

Post a Comment

Links to this post:

<$BlogBacklinkControl$> <$BlogBacklinkTitle$> <$BlogBacklinkDeleteIcon$>
<$BlogBacklinkSnippet$>
Create a Link

<< Home