Watson1978
7/28/2011 - 12:54 PM

DTrace for MacRuby

DTrace for MacRuby

% DYLD_LIBRARY_PATH=~/src/macruby-master sudo ./methods.d -c "/Users/watson/src/macruby-master/macruby /Users/watson/tmp/t.rb"
"a"
-> _GLOBAL__I__ZN12_GLOBAL__N_115ForceJITLinkingE
<- _GLOBAL__I__ZN12_GLOBAL__N_115ForceJITLinkingE = 0x1
-> __static_initialization_and_destruction_0(int, int)
<- __static_initialization_and_destruction_0(int, int) = 0x1
-> start
-> main
-> ruby_sysinit
<- ruby_sysinit = 0x3f
-> ruby_init
-> rb_ary_new
<- rb_ary_new = 0x0
-> rb_ary_new2
<- rb_ary_new2 = 0x40010a0e0
-> rb_ary_new
<- rb_ary_new = 0x7fff77fcabd3
-> rb_ary_new2
<- rb_ary_new2 = 0x40010a0a0
-> rb_ary_new
<- rb_ary_new = 0x7fff77fcabd3
-> rb_ary_new2
<- rb_ary_new2 = 0x40040a300
-> rb_objc_create_class
-> rb_vm_generate_objc_class_name
<- rb_vm_generate_objc_class_name = 0x1
<- rb_objc_create_class = 0x400309d60
  ....

$ sudo ./times.d -c "macruby t.rb"
"a"
Function                                    | time [ns]
-------------------------------------------------------
  rb_ivar_get                                                    1954
  ruby_options                                                   2067
  rb_fix2int                                                     2089
  rb_trap_exit                                                   2154
  rb_str_to_str                                                  2198
  rb_thgroup_add                                                 2198
  rb_const_get                                                   2247
  ....


#!/usr/sbin/dtrace -qs

#pragma D option quiet

pid$target:*macruby*::entry
{
    printf("-> %s\n", probefunc);
    /*
      buf = alloca(32);
      copyinto(arg0, 32, buf);
      tracemem(buf, 32);
    */
}

pid$target:*macruby*::return
{
    printf("<- %s = 0x%p\n", probefunc, arg1);
}


macruby$target:::method-entry
{
    printf("%s#%s\n", copyinstr(arg0), copyinstr(arg1))
}

macruby$target:::method-return
{
}
#!/usr/sbin/dtrace -qs

#pragma D option quiet

BEGIN
{
}

pid$target:*ruby*::entry
{
    self->time = timestamp;
}

pid$target:*ruby*::return
{
    @times[probefunc] = sum(timestamp - self->time);
}

END
{
    printf("Function                                    | time [ns]\n");
    printf("-------------------------------------------------------");
    printa(@times);
}