class Sidekiq::Metrics::Query

def top_jobs(class_filter: nil, minutes: nil, hours: nil)

+hours+: the number of coarser-grained 10-minute buckets to retrieve, in hours
+minutes+: the number of fine-grained minute buckets to retrieve
+class_filter+: return only results for classes matching filter
Get metric data for all jobs from the last hour
def top_jobs(class_filter: nil, minutes: nil, hours: nil)
  time = @time
  minutes = 60 unless minutes || hours
  # DoS protection, sanity check
  minutes = 60 if minutes && minutes > 480
  hours = 72 if hours && hours > 72
  granularity = hours ? :hourly : :minutely
  result = Result.new(granularity)
  result.ends_at = time
  count = hours ? hours * 6 : minutes
  stride, keyproc = ROLLUPS[granularity]
  redis_results = @pool.with do |conn|
    conn.pipelined do |pipe|
      count.times do |idx|
        key = keyproc.call(time)
        pipe.hgetall key
        time -= stride
      end
    end
  end
  result.starts_at = time
  time = @time
  redis_results.each do |hash|
    hash.each do |k, v|
      kls, metric = k.split("|")
      next if class_filter && !class_filter.match?(kls)
      result.job_results[kls].add_metric metric, time, v.to_i
    end
    time -= stride
  end
  result.marks = fetch_marks(result.starts_at..result.ends_at, granularity)
  result
end