debian-mirror-gitlab/bin/profile-url

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
1.5 KiB
Text
Raw Permalink Normal View History

2018-03-17 18:26:18 +05:30
#!/usr/bin/env ruby
require 'optparse'
options = {}
opt_parser = OptionParser.new do |opt|
opt.banner = <<DOCSTRING
Profile a URL on this GitLab instance.
Usage:
2022-11-25 23:54:43 +05:30
#{__FILE__} url --output=<profile-dump> --sql=<sql-log> [--user=<user>] [--post=<post-data>]
2018-03-17 18:26:18 +05:30
Example:
2022-11-25 23:54:43 +05:30
#{__FILE__} /dashboard/issues --output=dashboard-profile.dump --sql=dashboard.log --user=root
2018-03-17 18:26:18 +05:30
DOCSTRING
opt.separator ''
opt.separator 'Options:'
2022-11-25 23:54:43 +05:30
opt.on('-o', '--output=/tmp/profile.dump', 'profile output filename') do |output|
2018-03-17 18:26:18 +05:30
options[:profile_output] = output
end
opt.on('-s', '--sql=/tmp/profile_sql.txt', 'SQL output filename') do |sql|
options[:sql_output] = sql
end
opt.on('-u', '--user=root', 'User to authenticate as') do |username|
options[:username] = username
end
opt.on('-p', "--post='user=john&pass=test'", 'Send HTTP POST data') do |post_data|
options[:post_data] = post_data
end
end
opt_parser.parse!
options[:url] = ARGV[0]
if options[:url].nil? ||
options[:profile_output].nil? ||
options[:sql_output].nil?
puts opt_parser
exit
end
require File.expand_path('../config/environment', File.dirname(__FILE__))
2022-11-25 23:54:43 +05:30
Gitlab::Profiler.profile(options[:url],
logger: Logger.new(options[:sql_output]),
post_data: options[:post_data],
user: UserFinder.new(options[:username]).find_by_username,
private_token: ENV['PRIVATE_TOKEN'],
profiler_options: { out: options[:profile_output] })