When I wrote the fixed width integer part of my Lua number library there were some performance issues. Even though I kept it simple and I knew a it wasn’t going to be quick, I did find there were a few places that needed to be optimized. To this end I wrote a bit of code to do some tracing and give me some statistics about what was happening. For example, the reduction code that handles wrapping was a major bottleneck.

The profiling code ended up being so useful I also used it while developing my pure Lua hash library. Since I’ve now used it with two different projects I decided it would be a good idea to make it into a robust, reusable, and easy to use module.

To this end, I’ve released it as lua-perforator!

It does flow tracing and gathers a variety of statistics. Such as, number of time a function is called, what functions are called, and how long they took to run. It can even generate a Dot file of the execution flow.

So far I’ve found it invaluable and I hope others find it as useful as I have.