#!/usr/sbin/dtrace -s /* * rb_objcpu-type.d - measure Ruby method call times * * This example script is based off js_functime.d from the * helper monkey javascript package written by Brenden Gregg. */ #pragma D option quiet this string class; this string method; dtrace:::BEGIN { printf("Tracing... Hit Ctrl-C to end.\n"); depth = 0; } ruby$target:::function-entry { self->depth++; self->start[copyinstr(arg0), copyinstr(arg1), self->depth] = timestamp; } ruby$target:::function-return /(this->class = copyinstr(arg0)) != NULL && (this->method = copyinstr(arg1)) != NULL && self->start[this->class, this->method, self->depth]/ { this->elapsed = timestamp - self->start[this->class, this->method, self->depth]; @num[this->class, this->method] = count(); @eavg[this->class, this->method] = avg(this->elapsed); @esum[this->class, this->method] = sum(this->elapsed); @edist[this->class, this->method] = quantize(this->elapsed); self->start[this->class, this->method, self->depth] = 0; self->depth--; } dtrace:::END { normalize(@eavg, 1000); normalize(@esum, 1000); printf("ELAPSED TIME DISTRIBUTION,\n"); printa(@edist); setopt("aggsortpos", "2"); printf("%-33s %45s\n", "___ OVERLAP TIMES: ___", "______ ELAPSED ______"); printf("%-24s %-23s %6s %10s %12s\n", "CLASS", "METHOD", "COUNT", "AVG(us)", "SUM(us)"); printa("%-24.24s %-23.23s %@6d %@10d %@12d\n", @num, @eavg, @esum); }