Adam Leventhal
ahl@eng.sun.com
|
|
|
|
More USDT enhancements
Posted:
Apr 5, 2006 9:11 PM
|
|
DTracers,
I realize you're only now getting access to builds of OpenSolaris with the new USDT methodology I posted about recently:
http://www.opensolaris.org/jive/thread.jspa?messageID=23815崇
But, we couldn't rest on our laurels. As has been alluded to on this forum, build 38 will contain a further enhancement to USDT (building on that previous addition) that allows for a new probe-like structure: a conditional that tells you if tracing is enabled:
if (PROVIDER_PROBE_ENABLED()) { PROVIDER_PROBE(args, ...); }
This isn't appropriate for all USDT uses -- USDT probes are basically free ('dtrace -G' converts a call to a fake-o function to a nop operation). Basically free and not completely free because they incur not only the cost of a nop (or 5) but also the cost of setting up the arguments to the probe (as well as register pressure, I$ impact, etc). The 'is-enabled' probes are designed to be used in situations where setting up the arguments is prohibitively expensive. The 'PROVIDER_PROBE_ENABLED()' call becomes a move of zero into the return value register. The overhead is, therefore, is a move, a compare, and a branch. When the probe is enabled, we stuff a one into that register thus altering the flow of control.
Here are two specific cases where you might want to use the is-enabled probes:
If you're using USDT probes to instrument function entry points for a dynamic language it can often be _very_ expensive to invoke the introspection mechanisms to identify the types and values of arguments to function entry. This is an ideal place to use is-enabled probes.
Another is for using a USDT provider in lieu of debug printfs for a 'debug<pid>:::message' probe (I'm particularly fond of this):
void dprintf(const char *fmt, ...) { va_list ap; char *buf, c; int n;
if (DEBUG_MESSAGE_ENABLED()) { va_start(ap, fmt); n = vsnprintf(NULL, 0, fmt, ap); va_end(ap);
buf = malloc(n + 1); va_start(ap, fmt); n = vsprintf(buf, fmt, ap); va_end(ap);
DEBUG_MESSAGE(buf);
free(buf); } }
This, of course, requires a provider definition like this:
provider debug { probe message(char *); };
If you run into any trouble using USDT or build something interesting let us know!
Adam
-- Adam Leventhal, Solaris Kernel Development http://blogs.sun.com/ahl _______________________________________________ dtrace-discuss mailing list dtrace-discuss at opensolaris dot org
|
|