#!/usr/bin/ruby.ruby4.0 
# File: script/profile_subject

require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib ri_cal]))
require 'rubygems'
subject_name = ARGV[0] || "paris_eastern"

require File.expand_path(File.join(File.dirname(__FILE__), %w[.. performance], [subject_name], "subject"))

devnul = Object.new
def devnul.puts(string)
end

subject = Subject.new(devnul)

require 'ruby-prof'

result = RubyProf.profile do
  subject.run
end

out_file = File.expand_path(File.join(File.dirname(__FILE__), %w[.. performance_data], "#{subject_name}.calltree"))
puts "out_file is #{out_file}"
printer = RubyProf::CallTreePrinter.new(result)
puts "got printer"

File.open(out_file, 'w') do |f|
  printer.print(f)
end