debian-mirror-gitlab/lib/gitlab/request_profiler/profile.rb

44 lines
986 B
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
module Gitlab
module RequestProfiler
class Profile
2019-10-12 21:52:04 +05:30
attr_reader :name, :time, :file_path, :request_path, :profile_mode, :type
2016-09-13 17:45:13 +05:30
alias_method :to_param, :name
def initialize(name)
@name = name
2019-10-12 21:52:04 +05:30
@file_path = File.join(PROFILES_DIR, name)
2016-09-13 17:45:13 +05:30
set_attributes
end
2019-10-12 21:52:04 +05:30
def valid?
@request_path.present?
end
def content_type
case type
when 'html'
'text/html'
when 'txt'
'text/plain'
end
2016-09-13 17:45:13 +05:30
end
private
def set_attributes
2019-10-12 21:52:04 +05:30
matches = name.match(/^(?<path>.*)_(?<timestamp>\d+)(_(?<profile_mode>\w+))?\.(?<type>html|txt)$/)
return unless matches
@request_path = matches[:path].tr('|', '/')
@time = Time.at(matches[:timestamp].to_i).utc
@profile_mode = matches[:profile_mode] || 'unknown'
@type = matches[:type]
2016-09-13 17:45:13 +05:30
end
end
end
end