Commit 45d6a2b3 authored by Sean McGivern's avatar Sean McGivern

Add bin/profile-url tool and docs

parent b16c0080
#!/usr/bin/env ruby
require 'optparse'
options = {}
opt_parser = do |opt|
opt.banner = <<DOCSTRING
Profile a URL on this GitLab instance.
#{__FILE__} url --output=<profile-html> --sql=<sql-log> [--user=<user>] [--post=<post-data>]
#{__FILE__} /dashboard/issues --output=dashboard-profile.html --sql=dashboard.log --user=root
opt.separator ''
opt.separator 'Options:'
opt.on('-o', '--output=/tmp/profile.html', 'profile output filename') do |output|
options[:profile_output] = output
opt.on('-s', '--sql=/tmp/profile_sql.txt', 'SQL output filename') do |sql|
options[:sql_output] = sql
opt.on('-u', '--user=root', 'User to authenticate as') do |username|
options[:username] = username
opt.on('-p', "--post='user=john&pass=test'", 'Send HTTP POST data') do |post_data|
options[:post_data] = post_data
options[:url] = ARGV[0]
if options[:url].nil? ||
options[:profile_output].nil? ||
puts opt_parser
require File.expand_path('../config/environment', File.dirname(__FILE__))
result = Gitlab::Profiler.profile(options[:url],
post_data: options[:post_data],
user: User.find_by_username(options[:username]),
private_token: ENV['PRIVATE_TOKEN'])
printer =
file =[:profile_output], 'w')
......@@ -36,7 +36,8 @@ graphs/dashboards.
GitLab provides built-in tools to aid the process of improving performance:
* [Sherlock](
* [Profiling](
* [Sherlock](
* [GitLab Performance Monitoring](../administration/monitoring/performance/
* [Request Profiling](../administration/monitoring/performance/
* [QueryRecoder]( for preventing `N+1` regressions
......@@ -4,6 +4,41 @@ To make it easier to track down performance problems GitLab comes with a set of
profiling tools, some of these are available by default while others need to be
explicitly enabled.
## Profiling a URL
There is a `Gitlab::Profiler.profile` method, and corresponding
`bin/profile-url` script, that enable profiling a GET or POST request to a
specific URL, either as an anonymous user (the default) or as a specific user.
When using the script, command-line documentation is available by passing no
When using the method in an interactive console session, any changes to the
application code within that console session will be reflected in the profiler
For example:
# Returns a RubyProf::Profile for the regular operation of this request
class UsersController; def show; sleep 100; end; end
# Returns a RubyProf::Profile where 100 seconds is spent in UsersController#show
Passing a `logger:` keyword argument to `Gitlab::Profiler.profile` will send
ActiveRecord and ActionController log output to that logger. Further options are
documented with the method source.
[GitLab-Profiler]( is a project
that builds on this to add some additional niceties, such as allowing
configuration with a single Yaml file for multiple URLs, and uploading of the
profile and log output to S3.
For, you can find the latest results here:
## Sherlock
Sherlock is a custom profiling tool built into GitLab. Sherlock is _only_
......@@ -27,13 +62,3 @@ Bullet will log query problems to both the Rails log as well as the Chrome
As a follow up to finding `N+1` queries with Bullet, consider writing a [QueryRecoder test]( to prevent a regression.
## GitLab Profiler
[Gitlab-Profiler]( was built to
help developers understand why specific URLs of their application may be slow
and to provide hard data that can help reduce load times.
For, you can find the latest results here:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment