Sha256: 8bb5b442e2a2657b042e036f41501b9b40d35a75a344d2e7c5facf4f8ae78f09

Contents?: true

Size: 675 Bytes

Versions: 4

Compression:

Stored size: 675 Bytes

Contents

class Allocations
	def initialize(app)
		@app = app
	end
	
	def allocations
		counts = Hash.new{|h,k| h[k] = 0}
		
		ObjectSpace.each_object do |object|
			counts[object.class] += 1
		end
		
		return counts
	end
	
	def print_allocations(minimum = 100)
		buffer = StringIO.new
		
		total = allocations.values.sum
		
		allocations.select{|k,v| v >= minimum}.sort_by{|k,v| -v}.each do |key, value|
			buffer.puts "#{key}: #{value} allocations"
		end
		
		buffer.puts "** Total: #{total} allocations."
		
		return buffer.string
	end
	
	def call(env)
		if env["PATH_INFO"] == "/allocations"
			return [200, [], [print_allocations]]
		else
			return @app.call(env)
		end
	end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
falcon-0.35.2 examples/memory/allocations.rb
falcon-0.35.1 examples/memory/allocations.rb
falcon-0.35.0 examples/memory/allocations.rb
falcon-0.34.5 examples/memory/allocations.rb