Skip to content

Instantly share code, notes, and snippets.

@aub
aub / rails log analyzer
Created January 16, 2009 18:46
A script to check performance metrics from your rails log
#!/usr/bin/env ruby
# This script will take a look at the output from your rails application and print
# info about the number of selects, updates and inserts, as well as the slowest partials
# to render and the slowest selects.
#
# Usage... just pipe the output of your rails app or log to it:
#
# script/server | log_analyzer.rb
# or..
############### Named filter issues.
#
# 1) The table aliases for explicit joins are hacky. Obviously this is an easy fix, but we should
# talk about the best alternative. In this example, the resulting alias should not be "posts_blogs".
#
Post.filter do
join(Blog, :left, :posts_blogs) do
on(:blog_id => :id)
############### Named filter issues.
#
# 1) The table aliases for explicit joins are hacky. Obviously this is an easy fix, but we should
# talk about the best alternative. In this example, the resulting alias should not be "posts_blogs".
#
# => Agreed, although I can't think of anything really clever at the moment...
Post.filter do
join(Blog, :left, :posts_blogs) do
class Base
def self.some_method
puts 'Some method!'
end
def self.inherited(subclass)
puts 'Inherited!'
end
end
unless ENV['RAILS_ROOT']
ENV['RAILS_ROOT'] = Dir.pwd
end
STDERR.puts("Loading Rails environment...")
require File.join(ENV['RAILS_ROOT'], 'config', 'environment')
groups = CharacteristicGroup.filter do
with(:name).in(['Gender', 'Age', 'Lifestage', 'Internal QA'])
end
hKRib2R5hqhkZXRhY2hlZMOpaGFzaF90eXBlCqNrZXnEIwEgv4XjZCKusvmykV2W8afedmr/7bBWE34HnT8MDurQlSAKp3BheWxvYWTFAuJ7ImJvZHkiOnsia2V5Ijp7ImVsZGVzdF9raWQiOiIwMTIwYmY4NWUzNjQyMmFlYjJmOWIyOTE1ZDk2ZjFhN2RlNzY2YWZmZWRiMDU2MTM3ZTA3OWQzZjBjMGVlYWQwOTUyMDBhIiwiaG9zdCI6ImtleWJhc2UuaW8iLCJraWQiOiIwMTIwYmY4NWUzNjQyMmFlYjJmOWIyOTE1ZDk2ZjFhN2RlNzY2YWZmZWRiMDU2MTM3ZTA3OWQzZjBjMGVlYWQwOTUyMDBhIiwidWlkIjoiZTg4NWJiYWE3MmJiZ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