Thursday, July 28, 2016

Counting function calls per second

Say you want to know how often you're allocating tiles in Firefox or the rate of some other thing. There's an easy way to do this using dtrace. The following dtrace script counts calls to any functions matching the pattern '*SharedMemoryBasic*Create*' in XUL in the target process.

One of the simplest most useful features of aggregations is to use ustack() as the aggregation key to get stack traces along with the count of each unique stack trace:

pid$target:XUL:*SharedMemoryBasic??*:entry { @a[ustack()]=count(); }

profile:::tick-1sec { printa(@a); trunc(@a); }

Another key you can try is "@a[probefunc]=count();".

I've found that you can use two question marks to match the :: in a C++ method probe. This makes matching a little more exact. Here's the output I get tracing *SharedMemoryBasic??* with probefunc as the aggregation key.