DTrace predicate hack
One of the things I keep wanting in DTrace’s D language but isn’t there (right?) is a richer set of string comparison functions. Ideally I want full regular expression functionality, so that I can predicate actions on, say, regex matches of a class and/or method name. For instance, a while back, while profiling some Java, I wanted to only count time spent in methods of classes that belonged to a particular package (org/apache/solr) or to its subpackages. There is no “starts with” string operator in D. However, the following did the trick:
hotspot$target:::method-entry
/(self->class = copyinstr(arg1)) != NULL && self->class >= "org/apache/solr/" && self->class < "org/apache/sols"/
{
/* action goes here */
}A little ugly, but it worked. The choice of “org/apache/sols” as the upper bound was somewhat arbitrary.
November 7th, 2008 at 9:32 pm
good original post. fwiw, dtrace is a fantastic tool, though i’m also confused by the lack of text searching (dare i bring up RE?) within the predicates.
i really hope i just haven’t found out how to do it instead of it not being there at all….