diff options
author | Stan Hu <stanhu@gmail.com> | 2019-07-20 22:34:46 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2019-07-23 21:38:05 -0700 |
commit | 291df05e434f5678c47bce9521ff15748d6c767f (patch) | |
tree | a9ebe8e457d875b18998ac1a997c2faa0b1889f8 /lib/peek/views/rugged.rb | |
parent | 4482b82687e5b647459946338686eca0b53b7ce4 (diff) | |
download | gitlab-ce-291df05e434f5678c47bce9521ff15748d6c767f.tar.gz |
Add Rugged calls to performance bar
This will help diagnose the source of excessive I/O from Rugged
calls. To implement this, we need to obtain the full list of arguments
sent to each request method.
Diffstat (limited to 'lib/peek/views/rugged.rb')
-rw-r--r-- | lib/peek/views/rugged.rb | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/lib/peek/views/rugged.rb b/lib/peek/views/rugged.rb new file mode 100644 index 00000000000..7e2730e2ae4 --- /dev/null +++ b/lib/peek/views/rugged.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +module Peek + module Views + class Rugged < View + def duration + ::Gitlab::RuggedInstrumentation.query_time + end + + def calls + ::Gitlab::RuggedInstrumentation.query_count + end + + def results + { + duration: formatted_duration, + calls: calls, + details: details + } + end + + private + + def details + ::Gitlab::RuggedInstrumentation.list_call_details + .sort { |a, b| b[:duration] <=> a[:duration] } + .map(&method(:format_call_details)) + end + + def format_call_details(call) + call.merge(duration: (call[:duration] * 1000).round(3), + args: format_args(call[:args])) + end + + def format_args(args) + args.map do |arg| + # Needed to avoid infinite as_json calls + if arg.is_a?(Gitlab::Git::Repository) + arg.to_s + else + arg + end + end + end + + def formatted_duration + ms = duration * 1000 + if ms >= 1000 + "%.2fms" % ms + else + "%.0fms" % ms + end + end + end + end +end |