#!/usr/bin/env ruby
# Script to profile thin using ruby-prof.
# Takes the same arguments as the thin script.
require 'rubygems'
require 'ruby-prof'

$: << File.join(File.dirname(__FILE__), '..', 'lib')
require 'thin'

class Adapter
  def call(env)
    [200, {'content-type' => 'text/html', 'content-length' => '11'}, ['hello world']]
  end
end

# Profile the code
result = RubyProf.profile do
  Thin::Server.start('0.0.0.0', 3000) do
    run Adapter.new
  end
end

# Print a graph profile to text
printer = RubyProf::GraphPrinter.new(result)
printer.print(STDOUT, 0)