Skip to content

Instantly share code, notes, and snippets.

@Watson1978
Created November 20, 2012 12:34
Show Gist options
  • Save Watson1978/4117667 to your computer and use it in GitHub Desktop.
Save Watson1978/4117667 to your computer and use it in GitHub Desktop.
#!/usr/sbin/dtrace -s
#pragma D option quiet
BEGIN
{
printf("Target pid: %d\n\n", $target);
}
macruby$target:::method-entry
{
/* printf("%30s:%-5d %s#%s\n", copyinstr(arg2), arg3,
copyinstr(arg0), copyinstr(arg1));
*/
@methods_count[copyinstr(arg0), copyinstr(arg1)] = count();
}
END
{
printf("\n");
printf("%30s %-30s %s\n", "CLASS", "METHOD", "COUNT");
printf("--------------------------------------------------------------------------------\n");
printa("%30s %-30s %@d\n", @methods_count);
}
@Watson1978
Copy link
Author

$ sudo dtrace -qs method_count.d -p <プロセスID>


                         CLASS       METHOD                          COUNT
--------------------------------------------------------------------------------
             Benchmark::Report       initialize:                     1
                         Class       ===:                            1
                         Class       benchmark:                      1
                         Class       bm:                             1
                         Class       iterator?                       1
                    FalseClass       inspect                         1
                    FalseClass       to_s                            1
                            IO       sync                            1
                      NilClass       inspect                         1
                        String       *:                              1
                        String       +:                              1
                      TopLevel       bench_hash                      1
                         Class       print:                          2
                            IO       sync=:                          2
             Benchmark::Report       report:                         3
                Benchmark::Tms       format:                         3
                Benchmark::Tms       initialize:                     3
                Benchmark::Tms       real                            3
                Benchmark::Tms       stime                           3
                Benchmark::Tms       total                           3
                Benchmark::Tms       utime                           3
                         Class       format:                         3
                         Class       measure                         3
                        Fixnum       times                           3
                         Float       to_f                            3
                        String       dup                             3
                        String       initialize_copy:                3
                        String       ljust:                          3
                         Class       new:                            4
                          Proc       to_proc                         4
             Benchmark::Report       print:                          6
                         Class       alloc                           6
                         Class       at:                             6
                   Struct::Tms       cstime                          6
                   Struct::Tms       cutime                          6
                   Struct::Tms       initialize:                     6
                   Struct::Tms       stime                           6
                   Struct::Tms       utime                           6
                            IO       write:                          8
                         Class       times                           12
                        Fixnum       *:                              12
                        String       %:                              12
                        String       gsub!:                          21
                      TopLevel       inspect                         113
                      TopLevel       sprintf:                        10000

@Watson1978
Copy link
Author

MacRuby と同じ DTrace のプローブを使うことができます。
https://github.com/MacRuby/MacRuby/wiki/Using-DTrace

@Watson1978
Copy link
Author

アプリを終了させると、dtrace の結果が表示されます。

@Watson1978
Copy link
Author

dtrace のサンプルは
https://github.com/MacRuby/MacRubySamples/tree/master/DTrace
にいくつかあります。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment