Archive

Archive for October, 2009

OSX/Cocoa UI Event Spy

October 11th, 2009 John No comments

I recently had to profile an application, and one of the metrics I wanted to obtain was the performance of the GUI, without (if possible) resorting to GUI testing frameworks. This metric would be the duration of time from when the user commanded a redraw/update, until the render of that redraw actually completed (effectively a complete client-server-client round-trip time).

To cut a long story short, there doesn’t seem to be a developer tool in OS X or XCode to spy on these UI events, but you can enable them on individual applications by supplying the -NSTraceEvents YES flag to the binary, which you must start from Terminal.

For example, here’s how you’d start TextEdit and spy on its events.

/Applications/TextEdit.app/Contents/MacOS/TextEdit -NSTraceEvents YES

In my case, I actually only wanted to have the mouse-up events which would trigger the refresh. Here’s how I did it:

/Applications/TextEdit.app/Contents/MacOS/TextEdit -NSTraceEvents YES 2>&1 | grep "Received event.*LMouseUp"

NSTraceEvents outputs the trace to the stderr stream, which is ignored by grep, so the 2>&1 is there to redirect stderr to stdout. The “Received event.*LMouseUp” regular expression selects the mouse-up events from the complete stream.

Result:

2009-10-11 16:56:13.291 TextEdit[29990:903]
Received event: LMouseUp at: 320.0,243.0 time: 199375872740000 flags: 0x100 win: 1832 ctxt: f0df data: 2531,1

  • Share/Bookmark
Categories: Software Engineering Tags: ,