Is there an easy way to log every SQL call to the database? I’d
like to log mysql queries and their respective execution times into a table so
that I can closely monitor/report the performance of my application and
identify potential bottlenecks.
In case anyone in the future cares, I found a pretty good solution for
tracking db layer performance:
1) I implemented the Query Stats plugin:
http://code.google.com/p/query-stats/
2) set an after_filter to insert the results of those calls to the
database. see below:
after_filter :logging_dbstats
def logging_dbstats
# log sql stats here (pull from footer)
sql = "insert into
logging_dbstats(controller,action,controller_queries,view_queries,execution_time)
values
('#{params[:controller]}','#{params[:action]}','#{queries.count_with_label
:controller}', '#{queries.count_with_label :view}',
'#{queries.total_time}')"
ActiveRecord::Base.connection.execute(sql)
end