Prev | Current Page 231 | Next

Brad Ediger

"Advanced Rails"

Jeremy Kemper recently added a new
request profiler to Rails, which will be released with the final version of Rails 2.0. Its
library is located at actionpack/lib/action_controller/request_profiler.rb, and it is
accessible through script/performance/request. It is a fairly simple wrapper around the
ruby-prof library, adding some commonly needed Rails functionality:
??? Rather than running a single action, the request profiler runs a specified integration
test script, so the test procedure can be arbitrarily complex. This also means
that we can profile non-GET requests, which is a must for the action we wish to
profile.
??? The request profiler can run a script multiple times, while only profiling time
actually spent in those actions (not the overhead of starting up the profiler).
??? The profiler script opens up both the flat and HTML graph profiles for us; we
will see later how both of these are useful.
156 | Chapter 6: Performance
First, we need to install the ruby-prof gem:
$ sudo gem install ruby-prof
We need to write an integration script that drives the profiler. As mentioned previously,
this script can be arbitrarily complicated, but ours will be a single request. The
script uses the same methods as integration scripts, except that the script??™s execution
is wrapped in an integration runner (technically, the script??™s text is inserted into
the runner using instance_eval), so the integration session methods can be called as
top-level methods.


Pages:
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243