diff options
author | Qingyu Zhao <qzhao@gitlab.com> | 2019-06-27 16:42:14 +0300 |
---|---|---|
committer | Qingyu Zhao <qzhao@gitlab.com> | 2019-07-18 16:11:08 +0300 |
commit | 10e51ac5f7087bb9cbc495fc15195994fb8763e4 (patch) | |
tree | db910ca437f1187f726fd60f7567592d5042673b /lib/gitlab/request_profiler/profile.rb | |
parent | 0854f18352e72c2bcc0beca601d1ea48b490d1be (diff) |
Add profile mode to extend request profiling
Extend the support for "X-Profile-Token: <token>" to have an additional
header that defines type of profile we are looking for, like:
X-Profile-Mode: execution
X-Profile-Mode: memory
Diffstat (limited to 'lib/gitlab/request_profiler/profile.rb')
-rw-r--r-- | lib/gitlab/request_profiler/profile.rb | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/lib/gitlab/request_profiler/profile.rb b/lib/gitlab/request_profiler/profile.rb index 46996ef8c51..74f2ec1d083 100644 --- a/lib/gitlab/request_profiler/profile.rb +++ b/lib/gitlab/request_profiler/profile.rb @@ -3,28 +3,26 @@ module Gitlab module RequestProfiler class Profile - attr_reader :name, :time, :request_path + attr_reader :name, :time, :file_path, :request_path, :profile_mode, :type alias_method :to_param, :name def self.all - Dir["#{PROFILES_DIR}/*.html"].map do |path| + Dir["#{PROFILES_DIR}/*.{html,txt}"].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}" + file_path = File.join(PROFILES_DIR, name) return unless File.exist?(file_path) - new(name_dup) + new(name) end def initialize(name) @name = name + @file_path = File.join(PROFILES_DIR, name) set_attributes end @@ -33,12 +31,23 @@ module Gitlab File.read("#{PROFILES_DIR}/#{name}") end + def content_type + case type + when 'html' + 'text/html' + when 'txt' + 'text/plain' + end + end + private def set_attributes - _, path, timestamp = name.split(/(.*)_(\d+)\.html$/) + _, path, timestamp, profile_mode, type = name.split(/(.*)_(\d+)_(.*)\.(html|txt)$/) @request_path = path.tr('|', '/') @time = Time.at(timestamp.to_i).utc + @profile_mode = profile_mode + @type = type end end end |