2019-07-24 10:42:45 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Peek
|
|
|
|
module Views
|
|
|
|
class DetailedView < View
|
|
|
|
def results
|
|
|
|
{
|
|
|
|
duration: formatted_duration,
|
|
|
|
calls: calls,
|
|
|
|
details: details
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2019-07-26 09:03:00 -04:00
|
|
|
def detail_store
|
|
|
|
::Gitlab::SafeRequestStore["#{key}_call_details"] ||= []
|
|
|
|
end
|
|
|
|
|
2019-07-24 10:42:45 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def duration
|
2019-07-26 09:03:00 -04:00
|
|
|
detail_store.map { |entry| entry[:duration] }.sum # rubocop:disable CodeReuse/ActiveRecord
|
2019-07-24 10:42:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def calls
|
2019-07-26 09:03:00 -04:00
|
|
|
detail_store.count
|
2019-07-24 10:42:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def call_details
|
2019-07-26 09:03:00 -04:00
|
|
|
detail_store
|
2019-07-24 10:42:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def format_call_details(call)
|
2019-07-26 09:03:00 -04:00
|
|
|
call.merge(duration: (call[:duration] * 1000).round(3))
|
2019-07-24 10:42:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def details
|
|
|
|
call_details
|
|
|
|
.sort { |a, b| b[:duration] <=> a[:duration] }
|
|
|
|
.map(&method(:format_call_details))
|
|
|
|
end
|
|
|
|
|
|
|
|
def formatted_duration
|
|
|
|
ms = duration * 1000
|
|
|
|
|
|
|
|
if ms >= 1000
|
|
|
|
"%.2fms" % ms
|
|
|
|
else
|
|
|
|
"%.0fms" % ms
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|