class Rack::AllocationStats::Tracer
Attributes
gc_report[R]
stats[R]
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
Rack::AllocationStats::Action::new
# File lib/rack/allocation_stats/tracer.rb, line 12 def initialize(*args) super request = Rack::Request.new(@env) # Once we're here, GET["ras"] better exist @scope = request.GET["ras"]["scope"] @times = (request.GET["ras"]["times"] || 1).to_i @gc_report = request.GET["ras"]["gc_report"] @output = (request.GET["ras"]["output"] || :columnar).to_sym @alias_paths = request.GET["ras"]["alias_paths"] || false @new_env = delete_custom_params(@env) end
Public Instance Methods
act()
click to toggle source
# File lib/rack/allocation_stats/tracer.rb, line 25 def act @stats = AllocationStats.trace do @times.times do @middleware.call_app(@new_env) end end end
default_groups_and_sort(allocations)
click to toggle source
# File lib/rack/allocation_stats/tracer.rb, line 60 def default_groups_and_sort(allocations) allocations. group_by(:sourcefile, :sourceline, :class_plus). sort_by_size. all end
delete_custom_params(env)
click to toggle source
# File lib/rack/allocation_stats/tracer.rb, line 67 def delete_custom_params(env) new_env = env get_params = Rack::Request.new(new_env).GET get_params.delete("ras") new_env.delete("rack.request.query_string") new_env.delete("rack.request.query_hash") new_env["QUERY_STRING"] = build_query(get_params) new_env end
response()
click to toggle source
# File lib/rack/allocation_stats/tracer.rb, line 33 def response allocations = scoped_allocations if @output == :interactive allocations = allocations.all @middleware.allocation_stats_response(Formatters::HTML.new(self, allocations).format) elsif @output == :json allocations = default_groups_and_sort(allocations) @middleware.allocation_stats_response(Formatters::JSON.new(self, allocations).format) else allocations = default_groups_and_sort(allocations) @middleware.allocation_stats_response(Formatters::Text.new(self, allocations).format) end end
scoped_allocations()
click to toggle source
# File lib/rack/allocation_stats/tracer.rb, line 48 def scoped_allocations allocations = @stats.allocations(alias_paths: @alias_paths) return allocations if @scope.nil? if @scope == "." return allocations.from_pwd else return allocations.from(@scope) end end