Sha256: c1d692da217940f59695e64abb2679d43a0a24e971860f0b8946baeb10760154

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 KB

Contents

#!/usr/sbin/dtrace -s 
#pragma D option quiet
#pragma D option aggsortrev
#pragma D option dynvarsize=64m

/* 
 * Trace all ruby function calls and display their total time, average time
 * an invocation number (slower first).
 *
 * Usage:
 *
 *     sudo /usr/bin/xray_profile_ruby_function_calls.d -p <a pid>
 *
 *     sudo /usr/bin/xray_profile_ruby_function_calls.d -c "ruby -v"
 *
 *     sudo dtrace -s /usr/bin/xray_profile_ruby_function_calls.d -p <a pid>
 */
 
this string str;

dtrace:::BEGIN
{
   printf("Tracing, please be patient... Ctrl-C to interrupt.\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->func  = copyinstr(arg1)) != NULL && \
 self->start[this->class, this->func, self->depth]/
{
    this->elapsed = timestamp - self->start[this->class, this->func, self->depth];
    @num[this->class, this->func] = count();
    @eavg[this->class, this->func] = avg(this->elapsed);
    @esum[this->class, this->func] = sum(this->elapsed);
    self->start[this->class, this->func, self->depth] = 0;
    self->depth--;
}

dtrace:::END
{
    normalize(@eavg, 1000);
    normalize(@esum, 1000);
    setopt("aggsortpos", "0");   /* Sort on total time */
    printf("%95s\n", "_______ ELAPSED ______");
    printf("%-40s %-30s %12s %10s %6s\n", "Class", "Method", "Total (us)", "Avg (us)", "Count\n");
    printa("%-40.40s %-30.30s %@12d %@10d %@6d\n", @esum, @eavg, @num);
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
xray-1.1 bin/xray_profile_ruby_function_calls.d