DTrace is a dynamic tracing framework, and you may trace application without changing by DTrace. MacRuby provides some probe for DTrace to trace the methods behavior.
Probe Name
Calling timing
arg0
arg1
arg2
arg3
method-entry
At the start of the method
Class name
Method name
File name
Line number
method-return
At the end of the method
Class name
Method name
File name
Line number
raise
An exception raises
Class name
File name
Line number
-
Using these probes, you may easily trace the count of method calling or trace the execution time.
Here is DTrace script which trace the total execution time of String methods.
1234567891011121314151617181920212223
/* time.d */#pragmaDoptionquietmacruby$target:::method-entry/copyinstr(arg0)=="String"//* invokes only String methods */{self->starttime=walltimestamp/1000;}macruby$target:::method-return/copyinstr(arg0)=="String"//* invokes only String methods */{@invoked_time[copyinstr(arg0),copyinstr(arg1)]=sum((walltimestamp/1000)-self->starttime);}END{printf("\n");printf("%-10s %-15s %s\n","CLASS","METHOD","TOTAL TIME µsec");printf("--------------------------------------------------------------------------------\n");printa("%-10s %-15s %@d\n",@invoked_time);}
Prepare your application to trace the execution time.