WoW mod: TraceEvent 1.3

Ken Fox, kfox@vulpes.com
TraceEvent is in the public domain.
Download TraceEvent 1.3

TraceEvent collects function call counts, calls/second, peak calls/second and average per-call memory usage of Lua global functions. The original release was designed to trace all OnEvent functions, but v1.2 allows you to specify functions by name or pattern. V1.3 now allows tracing of OO methods.

Here's an example of tracing some FlexBar and WatchDog functions. FlexBarButton_ OnEvent has peaked at 1,125 calls/sec! FlexBarButton_ OnUpdate has been called 20,808 times with an average memory allocation of 220 bytes per call.

TraceEvent can be EXTREMELY INVASIVE -- it will hook the functions you tell it regardless of the wisdom of such actions. If you try to trace all global functions, you will almost certainly cause a serious stack over-flow.

That said, it is possible (and even useful!) to trace all custom add-on functions with the pattern "^[A-Z]%a+_". If you are a mod author, you can trace all your global functions with "^ModName_" where ModName is the prefix you use for your global functions. If you want to trace all event handlers, the pattern "_OnEvent$" works nicely.

In this version you may turn off tracing call counts or memory usage. When tracing is turned off, TraceEvent is harmless: all previously traced functions are restored to their original state. You shouldn't need to worry about disabling it from the AddOn manager any more. I leave mine enabled so I can easily run a trace whenever I want -- many WoW performance problems are extremely situational.

The TraceEvent UI will be visible at start up. You may move it by dragging the empty space in the lower left corner of the window. The TraceEvent UI can be hidden by clicking the "X" button, but merely hiding the window does not turn off tracing. The slash command "/trace" toggles the display on and off.

To start tracing a function: type the name or pattern into the edit box, then press the "Add" button. If you hold the shift key while pressing "Add", memory usage will be turned on, otherwise only call counting is turned on. Additional functions can be added; this does not remove other functions from the trace.

If you did not turn on memory usage when you added a function, holding the shift key and left clicking the function will turn it on. You may also just add the function again with the "Add" button, but this will reset the call counts of all functions. It's usually best to run some call counts first and then selectively enable memory usage on the most important functions. (Memory collection is much more invasive than call counting. Highly recursive functions may run out of stack space if memory usage is turned on.)

To stop tracing a function: left click on the function name in the scrolled window. This restores the function to its original state and turns off all tracing on it. You may stop all traces with the slash command "/trace clear".

To reset the trace data: press the "Reset" button. If you hold the shift key while pressing "Reset", memory usage will be turned on, otherwise only call counting is turned on. The slash command "/trace reset" will also reset trace data.

To sort the trace data: press the "Sort" button. If you hold the shift key while pressing "Sort", the functions will be sorted by total memory consumption.

TraceEvent displays the following information:

I am amazed by WoW's ability to tolerate this kind of instrumentation. Frame rate drops off a bit, but the game remains playable.


Last modified: Tue Jul 05 18:04:48 Eastern Daylight Time 2005