DTrace is an observability tool; it can observe all the layers of your program, all the way down to the kernel.
DTrace enabled OSes:
What about Linux? Nope. Licensing problems. Look at DTrace 4; it has about 40% of the features, but no application insight.
awk-like
#!/usr/sbin/dtrace -qFZs
# -q: quiet (no extraneous output)
# -F: track trace depth
# -Z: OK if no probes match
# -s: probes I care about...
# DTrace docs for python list all of the hooks
function-entry,
function-return
{
/* arg1 is subroutine name */
trace(copyinstr(arg1))
}
#!/usr/sbin/dtrace -qZs
# get the 10 most-called functions
function-entry
{
/* count sub entries by package and sub name
* arg0 = source file name
* arg1 = function name */
@[strjoin(strjoin(copyinstr(arg0),"-"),copyinstr(arg1))] = count()
}
END
{
/* give me top 10 higest counts; throw away rest */
trunc(@, 10)
}
Normally, you see the average of 1000 executions of your code with a profiler, but you lose the outliers. DTrace, using quantize, gives you a histogram so you can catch the outliers.
One of the few languages that's not supported out of the box.
Easiest way to get DTrace support is to use homebrew to build python with DTrace
function-entry
function-return
line
(FILE, FUNCTION, LINE)
instance-new-start
instance-new-done
instance-delete-start
instance-delete-done
(CLASS_NAME, FILE)
You can write your own DTrace probes in python using http://tmetsch.github.io/python-dtrace/ (on PyPI, too).
Because of Joyent, JavaScript probably has the best DTrace support right now