Created
December 11, 2010 20:52
-
-
Save ehrenmurdick/737643 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
if ARGV.any? {|arg| %w[--drb -X --generate-options -G --help -h --version -v].include?(arg)} | |
require 'rubygems' unless ENV['NO_RUBYGEMS'] | |
else | |
gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9 | |
ENV["RAILS_ENV"] ||= 'test' | |
require File.expand_path(File.dirname(__FILE__) + "/../config/environment") unless defined?(RAILS_ROOT) | |
end | |
require 'spec/autorun' | |
if GC.respond_to?(:enable_stats) | |
module Spec | |
module Runner | |
class CommandLine | |
class << self | |
def run_with_gc_stats | |
GC.enable_stats | |
start_time = Time.now | |
out = run_without_gc_stats | |
end_time = Time.now | |
show_gc_stats(start_time, end_time) | |
out | |
end | |
alias_method_chain :run, :gc_stats | |
def show_gc_stats(start_time, end_time) | |
gc_time_in_seconds = GC.time.to_f / 1000000.to_f | |
gc_malloc_limit = ENV['RUBY_GC_MALLOC_LIMIT'] | |
file = File.open('tmp/gc_stats.txt', 'a') | |
$stderr.reopen(file) | |
gc_stats = <<STR | |
=========================================== | |
Test Start Time: #{start_time} | |
Test Finish Time: #{end_time} | |
Test Run Time: #{end_time - start_time} seconds | |
RUBY_GC_MALLOC_LIMIT = #{gc_malloc_limit} | |
#{GC.dump} | |
Seconds spent in GC: #{gc_time_in_seconds} | |
=========================================== | |
STR | |
# File.open('tmp/gc_stats.txt', 'a') { |f| f.puts gc_stats } | |
file.puts gc_stats | |
file.close | |
$stdout.puts gc_stats | |
end | |
private :show_gc_stats | |
end | |
end | |
end | |
end | |
end | |
exit ::Spec::Runner::CommandLine.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment