

Profile Ruby 2.0 apps using DTrace - part 2 - gnufied
http://crypt.codemancers.com/posts/2013-05-04-profile-ruby-2-dot-0-apps-using-dtrace-part-2/

======
garysweaver
Neat! Note that using Ruby's profiler is a heck of a lot easier. For example,
here's how you can profile a call to a model method in Rails:
[http://stufftohelpyouout.blogspot.com/2013/05/profiling-
in-r...](http://stufftohelpyouout.blogspot.com/2013/05/profiling-in-rails-
with-rubys-profiler.html)

    
    
        rails c 2>&1 | tee profile.txt
        require 'profile'
        SomeClass.some_method
        exit (or ctrl-d)
        grep -E "SomeClass\#|cumulative   self|seconds    call" profile.txt
    

Example of results:

    
    
          %   cumulative   self              self     total
         time   seconds   seconds    calls  ms/call  ms/call  name
        1.05     0.79      0.01        5     2.00     2.00  SomeClass#_validate_callbacks
        0.00     0.95      0.00       13     0.00     0.00  SomeClass#_create_callbacks
        0.00     0.95      0.00       13     0.00     0.00  SomeClass#_update_callbacks
        0.00     0.95      0.00       15     0.00     0.00  SomeClass#reflections
        0.00     0.95      0.00       12     0.00     0.00  SomeClass#_save_callbacks
        ...
    

Other things to look at:

* Benchmark: [http://www.ruby-doc.org/stdlib-1.9.3/libdoc/benchmark/rdoc/B...](http://www.ruby-doc.org/stdlib-1.9.3/libdoc/benchmark/rdoc/Benchmark.html)

* Rails perf testing: <http://guides.rubyonrails.org/performance_testing.html>

* Ruby-prof: <https://github.com/rdp/ruby-prof>

* Tracer: [http://www.ruby-doc.org/stdlib-1.9.3/libdoc/tracer/rdoc/inde...](http://www.ruby-doc.org/stdlib-1.9.3/libdoc/tracer/rdoc/index.html)

* TracePoint: <https://github.com/rubyunworks/tracepoint>

* Autolog: <https://github.com/garysweaver/autolog>

* set_trace_func: <http://apidock.com/ruby/Kernel/set_trace_func>

See also: <http://stackoverflow.com/a/16700778/178651>

