Rails Profiling: Getting Easier
Last year we looked at using ruby-prof to gather profiling data for a Rails application. But it's worth revisiting the subject now that ruby-prof 0.7.0 is out: gathering profile test data for a Rails application is almost absurdly easy now.
As detailed by gem author Charlie Savage, hooking everything up begins with creating a profile environment for your Rails application. Sprinkle in a new test helper (that comes with the gem), include
RubyProf::Test in your tests, save them to test/profile, and just execute them like any other tests.
The results? A quick summary in the output is just the tip of the iceberg:
MyControllerTest#test_get (0.01s warmup) .......... process_time: 0.11 seconds . Finished in 0.509442 seconds.
You also get text and HTML reports with detailed information, including the number of times each method is called, how long they took, and links back into your source code. There are still problems to be solved - notably, how to track changes in performance over time - but the basic process of measuring the performance of a Rails application in a repeatable way can now be regarded as finished.