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.