tag:blogger.com,1999:blog-1386948037384435441.post3266791214411717898..comments2024-03-01T18:53:33.429-08:00Comments on Jeff Muizelaar: Counting function calls per secondJeff Muizelaarhttp://www.blogger.com/profile/17483047845050494642noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-1386948037384435441.post-25026135466068059712016-07-30T00:00:40.150-07:002016-07-30T00:00:40.150-07:00Hey,
Regarding the dtrace example, increments of ...Hey,<br /><br />Regarding the dtrace example, increments of a dtrace global variable aren't made to be atomic by dtrace (last I checked). Hence your results could be incorrect on a multithreaded code base.<br /><br />But, you can use dtrace aggregations to do this without the race condition. For example,<br /><br /> pid$target:XUL:*SharedMemoryBasic??*:entry<br /> {<br /> @a["calls per second"]=count();<br /> }<br /><br /> profile:::tick-1sec<br /> {<br /> printa(@a);<br /> trunc(@a);<br /> }<br /><br />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:<br /><br /> pid$target:XUL:*SharedMemoryBasic??*:entry<br /> {<br /> @a[ustack()]=count();<br /> }<br /><br /> profile:::tick-1sec<br /> {<br /> printa(@a);<br /> trunc(@a);<br /> }<br /><br />Another key you can try is "@a[probefunc]=count();".<br /><br />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.<br /><br /> 0 351742 :tick-1sec <br /> mozilla::ipc::SharedMemoryBasic::CloseHandle() 3<br /> mozilla::ipc::SharedMemoryBasic::Create(unsigned long) 3<br /> mozilla::ipc::SharedMemoryBasic::Map(unsigned long) 3<br /> mozilla::ipc::SharedMemoryBasic::ShareToProcess(int, unsigned int*) 3<br /> mozilla::ipc::SharedMemoryBasic::SharedMemoryBasic() 3<br /> mozilla::ipc::SharedMemoryBasic::Type() const 3<br /> mozilla::ipc::SharedMemoryBasic::memory() const 69<br /><br />The right column is the number of calls in the last 1-second interval.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-1386948037384435441.post-1122047767504754012016-07-29T07:39:51.177-07:002016-07-29T07:39:51.177-07:00Indeed. Something like the following seems to work...Indeed. Something like the following seems to work:<br /><br />global call_count;<br />probe process.function("some_function_name") { call_count++; }<br /><br />probe timer.s(1) {<br /> printf("%d/sec\n", call_count);<br /> call_count = 0;<br />}<br /><br />run as:<br /><br />$ stap $SCRIPT_NAME -x $PIDJeff Muizelaarhttps://www.blogger.com/profile/17483047845050494642noreply@blogger.comtag:blogger.com,1999:blog-1386948037384435441.post-52168901605896573682016-07-29T06:48:04.617-07:002016-07-29T06:48:04.617-07:00I'd be surprised if you couldn't do someth...I'd be surprised if you couldn't do something similar with SystemTap: https://sourceware.org/systemtap/Andrew Overholthttps://www.blogger.com/profile/04952441032916530560noreply@blogger.com