2013-02-05 14:16:51 -05:00
|
|
|
# If Mini Profiler is included via gem
|
2014-07-16 18:34:30 -04:00
|
|
|
if Rails.configuration.respond_to?(:load_mini_profiler) && Rails.configuration.load_mini_profiler
|
2013-04-11 02:24:08 -04:00
|
|
|
require 'rack-mini-profiler'
|
2013-09-09 07:19:23 -04:00
|
|
|
require 'flamegraph'
|
2014-05-07 23:49:34 -04:00
|
|
|
require 'memory_profiler' if RUBY_VERSION >= "2.1.0"
|
2013-04-11 02:24:08 -04:00
|
|
|
# initialization is skipped so trigger it
|
|
|
|
Rack::MiniProfilerRails.initialize!(Rails.application)
|
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
if defined?(Rack::MiniProfiler)
|
|
|
|
|
2013-03-25 02:19:59 -04:00
|
|
|
# note, we may want to add some extra security here that disables mini profiler in a multi hosted env unless user global admin
|
|
|
|
# raw_connection means results are not namespaced
|
|
|
|
#
|
|
|
|
# namespacing gets complex, cause mini profiler is in the rack chain way before multisite
|
|
|
|
Rack::MiniProfiler.config.storage_instance = Rack::MiniProfiler::RedisStore.new(connection: DiscourseRedis.raw_connection)
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
# For our app, let's just show mini profiler always, polling is chatty so nuke that
|
2013-02-25 11:42:20 -05:00
|
|
|
Rack::MiniProfiler.config.pre_authorize_cb = lambda do |env|
|
2014-05-06 18:23:52 -04:00
|
|
|
path = env['PATH_INFO']
|
2013-11-12 00:47:01 -05:00
|
|
|
(env['HTTP_USER_AGENT'] !~ /iPad|iPhone|Nexus 7|Android/) &&
|
2014-05-06 18:23:52 -04:00
|
|
|
(path !~ /^\/message-bus/) &&
|
|
|
|
(path !~ /topics\/timings/) &&
|
|
|
|
(path !~ /assets/) &&
|
2014-05-26 22:38:42 -04:00
|
|
|
(path !~ /\/user_avatar\//) &&
|
2014-05-30 00:17:35 -04:00
|
|
|
(path !~ /\/letter_avatar\//) &&
|
2014-05-06 18:23:52 -04:00
|
|
|
(path !~ /qunit/) &&
|
|
|
|
(path !~ /srv\/status/) &&
|
|
|
|
(path !~ /commits-widget/) &&
|
2014-07-08 00:48:20 -04:00
|
|
|
(path !~ /^\/cdn_asset/) &&
|
2014-05-06 18:33:07 -04:00
|
|
|
(path !~ /^\/logs/)
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
2013-03-24 23:09:28 -04:00
|
|
|
# without a user provider our results will use the ip address for namespacing
|
|
|
|
# with a load balancer in front this becomes really bad as some results can
|
2013-06-19 15:06:23 -04:00
|
|
|
# be stored associated with ip1 as the user and retrieved using ip2 causing 404s
|
2013-03-24 22:52:03 -04:00
|
|
|
Rack::MiniProfiler.config.user_provider = lambda do |env|
|
2013-03-24 23:36:55 -04:00
|
|
|
request = Rack::Request.new(env)
|
|
|
|
id = request.cookies["_t"] || request.ip || "unknown"
|
|
|
|
id = id.to_s
|
|
|
|
# some security, lets not have these tokens floating about
|
|
|
|
Digest::MD5.hexdigest(id)
|
2013-03-24 22:52:03 -04:00
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
Rack::MiniProfiler.config.position = 'left'
|
|
|
|
Rack::MiniProfiler.config.backtrace_ignores ||= []
|
|
|
|
Rack::MiniProfiler.config.backtrace_ignores << /lib\/rack\/message_bus.rb/
|
|
|
|
Rack::MiniProfiler.config.backtrace_ignores << /config\/initializers\/silence_logger/
|
|
|
|
Rack::MiniProfiler.config.backtrace_ignores << /config\/initializers\/quiet_logger/
|
|
|
|
|
2013-08-30 02:44:17 -04:00
|
|
|
|
|
|
|
# Rack::MiniProfiler.counter_method(ActiveRecord::QueryMethods, 'build_arel')
|
|
|
|
# Rack::MiniProfiler.counter_method(Array, 'uniq')
|
2013-02-05 14:16:51 -05:00
|
|
|
# require "#{Rails.root}/vendor/backports/notification"
|
|
|
|
|
2013-03-24 23:09:28 -04:00
|
|
|
# inst = Class.new
|
|
|
|
# class << inst
|
|
|
|
# def start(name,id,payload)
|
|
|
|
# if Rack::MiniProfiler.current && name !~ /(process_action.action_controller)|(render_template.action_view)/
|
|
|
|
# @prf ||= {}
|
|
|
|
# @prf[id] ||= []
|
|
|
|
# @prf[id] << Rack::MiniProfiler.start_step("#{payload[:serializer] if name =~ /serialize.serializer/} #{name}")
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
|
|
|
|
# def finish(name,id,payload)
|
|
|
|
# if Rack::MiniProfiler.current && name !~ /(process_action.action_controller)|(render_template.action_view)/
|
|
|
|
# t = @prf[id].pop
|
|
|
|
# @prf.delete id unless t
|
|
|
|
# Rack::MiniProfiler.finish_step t
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
# end
|
2013-02-05 14:16:51 -05:00
|
|
|
# disabling for now cause this slows stuff down too much
|
|
|
|
# ActiveSupport::Notifications.subscribe(/.*/, inst)
|
|
|
|
|
|
|
|
# Rack::MiniProfiler.profile_method ActionView::PathResolver, 'find_templates'
|
|
|
|
end
|