Using DTrace with RubyMotion

Want to profile or analyze your RubyMotion application? How to use Instrument with motion
is not yet known, but you can always use powerful DTrace to do that.

Turns out running DTrace in RubyMotion is exactly same as that in MacRuby (no surprise!).
motion-dtrace is a proof of concept to simplify
running dtrace with your app.

Installation

gem install motion-dtrace

Usage

Edit the Rakefile of your RubyMotion project and add the following require line.

require 'rubygems'
require 'motion-dtrace'

Start simulator process:

rake

On another terminal, start dtrace:

rake dtrace

When you terminate the app, you get a trace similar to following:

                         CLASS#METHOD                          TOTAL TIME µsec
--------------------------------------------------------------------------------
                       CGPoint#y=:                             3
                        String#nil?                            3
                         Array#last                            4
                        CGRect#origin                          4
                Evernote::Note#title                           4
                          Hash#empty?                          4
                          ........
                         Class#all:                            19867
                       UIImage#thumbnail                       24226
                  DTWebArchive#thumbnail                       24415
                      ClipItem#thumbnail                       24451
                    __NSArrayM#each                            24717
          ClipperTableViewCell#item=:                          25143

Extra

You may specify your own dtrace file via:

rake dtrace DTRACE=/Users/siuying/Documents/workspace/motion/motion-dtrace/dtrace/methods_duration.d

TODO

Currently this gem is just a hack to simplify command lines.

We shall investigate can we do real integration with project.

Credit