summaryrefslogtreecommitdiff
path: root/lib/gitlab/request_profiler/profile.rb
diff options
context:
space:
mode:
authorAhmad Sherif <me@ahmadsherif.com>2016-07-15 17:46:39 +0200
committerAhmad Sherif <me@ahmadsherif.com>2016-07-26 20:06:09 +0200
commit345cd22f21e4e5a6e340c35e50b43105ee107570 (patch)
treed1f3916535c9bca94cb9c8fe16559332dcbf762e /lib/gitlab/request_profiler/profile.rb
parent0c799be6b6fc0166473c82039ebf662a0558ed8f (diff)
downloadgitlab-ce-345cd22f21e4e5a6e340c35e50b43105ee107570.tar.gz
Profile requests when a header is passedfeature/profile-requests-conditionally
Diffstat (limited to 'lib/gitlab/request_profiler/profile.rb')
-rw-r--r--lib/gitlab/request_profiler/profile.rb43
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/gitlab/request_profiler/profile.rb b/lib/gitlab/request_profiler/profile.rb
new file mode 100644
index 00000000000..f89d56903ef
--- /dev/null
+++ b/lib/gitlab/request_profiler/profile.rb
@@ -0,0 +1,43 @@
+module Gitlab
+ module RequestProfiler
+ class Profile
+ attr_reader :name, :time, :request_path
+
+ alias_method :to_param, :name
+
+ def self.all
+ Dir["#{PROFILES_DIR}/*.html"].map do |path|
+ new(File.basename(path))
+ end
+ end
+
+ def self.find(name)
+ name_dup = name.dup
+ name_dup << '.html' unless name.end_with?('.html')
+
+ file_path = "#{PROFILES_DIR}/#{name_dup}"
+ return unless File.exist?(file_path)
+
+ new(name_dup)
+ end
+
+ def initialize(name)
+ @name = name
+
+ set_attributes
+ end
+
+ def content
+ File.read("#{PROFILES_DIR}/#{name}")
+ end
+
+ private
+
+ def set_attributes
+ _, path, timestamp = name.split(/(.*)_(\d+)\.html$/)
+ @request_path = path.tr('|', '/')
+ @time = Time.at(timestamp.to_i).utc
+ end
+ end
+ end
+end