Simple Rails Log Query Analyzer

Intro

This is a simple rails log analyzer. The initial goal is to
identify SQL queries that could be optimized or find queries that are being
called more often than they should be.

In its current state it is little more than simple regexes. My goal, however is
to build more useful tools on top of it. I’ve added it to a git repository to
allow anyone to make edits and improvements.

It’s not really ready for prime-time (for instance, it doesn’t work well
with log colorization), but I have found it useful so I thought I would share
it. If nothing else it could save someone else 10 minutes to write
a similar script.

What it does

Right now all this does is read a log file and extract SQL “SELECT” statements
and organize them by the amount of time they take. It will also show a summary
of the number of queries called to load each model.

How to get it


git clone \
git://gitorious.org/simple_rails_log_analyzer/mainline.git \
simple_rails_log_analyzer

How to use it

The typical work flow looks like this:

rake log:clear
# hit the URL of the page we want to profile, run the rake task, etc
ruby bin/query_log_analyzer.rb log/development.log

Or visit http://gitorious.org/projects/simple_rails_log_analyzer

TODO

  • Deal with the colorization of the logs
  • Update the code to not be so SELECT centric. Support other types of queries
  • Be smarter about each request’s individual queries

Contributions

I’ve placed this in a git repository, so feel free to submit any patches and
I’ll integrate them into this master.

Similar Projects

Share:
  • del.icio.us
  • Reddit
  • Technorati
  • Twitter
  • Facebook
  • Google Bookmarks
  • HackerNews
  • PDF
  • RSS
This entry was posted in programming, rails, ruby. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.
  • Aaron

    Trying to clone your repo and it wants a password.

  • Nate Murray

    Ah, my bad. The command should be:

    git clone git://gitorious.org/simple_rails_log_analyzer/mainline.git simple_rails_log_analyzer

    Updated the article.

  • http://www.xcombinator.com/2008/04/04/the-symlink-trick/ the symlink trick

    [...] an hour of tweaking, optimizing queries, and piggy-backing some attributes I was able to get down to 9,839 queries and the page rendered in [...]

  • http://jacqueschirag.wordpress.com/2008/10/15/rails-log-analyzers/ Rails log analyzers « So far, it’s RoR

    [...] Simple Rails Log Query Analyzer [...]

  • http://www.question-defense.com/2008/10/15/rails-log-analyzers/ Rails Log Analyzers | Question Defense

    [...] Simple Rails Log Query Analyzer [...]