Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib/peek
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2019-07-21 08:34:46 +0300
committerStan Hu <stanhu@gmail.com>2019-07-24 07:38:05 +0300
commit291df05e434f5678c47bce9521ff15748d6c767f (patch)
treea9ebe8e457d875b18998ac1a997c2faa0b1889f8 /lib/peek
parent4482b82687e5b647459946338686eca0b53b7ce4 (diff)
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')
-rw-r--r--lib/peek/views/rugged.rb56
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