Randomness for you since 1976
As the time nears for one of my applications to move towards general release, performance is the concern of the day. There are still bugs to fix, visual indiscretions to … discrete, etc. My good man Becker got some profiling code into the application, but I found the results difficult to read through. Last week I attended Ruby East and caught a nice presentation by Ezra Zygmuntowicz of Engine Yard regarding Ruby performance and optimization. During the presentation, he showed a bit of code he includes in his applications to make wrapping select blocks of code for profiling easier. He was nice enough to share his code with me, and allow me to present it here for all of you.
Where does the code go?
Well, you can put it anywhere really. For my quick and dirty testing I put it at the bottom of RAILS_APP/config/environment.rb, but you could just as easily put it in it’s own file in your RAILS_APP/lib directory, or any number of other options.
OK, now how do I use it?
All you have to do to use the profiler is wrap whatever block of code you want to profile in __profile__
Now what do I do?
An HTML file will be created in RAILS_APP/log/something.html. Where something is the string that you passed to the __profile__ call when you wrapped it around your code. In my example the file would have been called “monkey_profile.html”. Pop it open in your favorite browser and take a look.
This is confusing, what do all these numbers mean?
I don’t know. Really, I don’t. I am rather new to profiling, so I can’t really explain the generated report with any accuracy. Take a look at the ruby-prof docs, or find someone who knows about profilers in general and ask them to explain it to you. If you are a profiling genius, or you know of any good online resources for getting useful information out of ruby-prof reports, please let me know.
Happy profiling.
This blog is a dumping grounds for my experiences as a web developer, a parent, an artist, a writer and a human being. Maybe someday there will be something here that is worth your time, some sort of useful information or words that piece your very soul. Probably not though.
Peter Williams
October 1st, 2007 at 9:04 pm
You might take a look at http://cfis.savagexi.com/articles/2007/07/10/how-to-profile-your-rails-application. Charlie is a maintainer of ruby-prof so he this stuff. Also I am not too bad at reading profiles.
Peter Williams
October 1st, 2007 at 9:05 pm
Remove the trailing period from the URI in the previous comment to make it work.