Sha256: 9337c756f7c8a379cdc40db6b2595a57149c6a24d24062f7137598d1e4cf7062
Contents?: true
Size: 1.26 KB
Versions: 6
Compression:
Stored size: 1.26 KB
Contents
namespace "profiler" do desc 'Aggregate profile data and display locations with the longest total durations' task :aggregate => :environment do top_n = ENV['max_lines'].present? ? ENV['max_lines'].to_i : 50 show_longest_sql = ENV['show_sql'] == 'true' ? true : false prefix = ENV['prefix'].present? ? ENV['prefix'] : nil compact = case ENV['compact'] when 'date' :date when 'hour' :hour else nil end if compact && prefix.nil? case compact when :date prefix = 1.day.ago.strftime(ActiveRecordProfiler::Collector::DATE_FORMAT) when :hour prefix = 1.hour.ago.strftime(ActiveRecordProfiler::Collector::DATE_FORMAT + ActiveRecordProfiler::HOUR_FORMAT) end end collector = ActiveRecordProfiler::Collector.new totals = collector.aggregate(:prefix => prefix, :compact => compact) top_locs = collector.sorted_locations(ActiveRecordProfiler::Collector::DURATION, top_n) top_locs.each do |loc| data = show_longest_sql ? totals[loc] : totals[loc][0..-2] puts "#{loc}: #{data.join(', ')}" end end desc 'Clear out the profiler data diretory' task :clear_data => :environment do ActiveRecordProfiler::Collector.clear_data end end
Version data entries
6 entries across 6 versions & 1 rubygems