property.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29634 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2010-10-29 23:50:57 +00:00
parent aeab9011fe
commit 4e11a8997d

View File

@ -1,52 +1,52 @@
require 'objspace' require 'objspace'
# #
# purpose: # purpose:
# Profile memory usage of each tests. # Profile memory usage of each tests.
# #
# usage: # usage:
# RUBY_TEST_ALL_PROFILE=true make test-all # RUBY_TEST_ALL_PROFILE=true make test-all
# #
# output: # output:
# ./test_all_profile # ./test_all_profile
# #
# collected information: # collected information:
# - ObjectSpace.memsize_of_all # - ObjectSpace.memsize_of_all
# - GC.stat # - GC.stat
# - /proc/self/statm (if it exists) # - /proc/self/statm (if it exists)
# #
class MiniTest::Unit::TestCase class MiniTest::Unit::TestCase
alias orig_run run alias orig_run run
$test_all_profile_out = open('test_all_profile', 'w') $test_all_profile_out = open('test_all_profile', 'w')
$test_all_profile_gc_stat_hash = {} $test_all_profile_gc_stat_hash = {}
if FileTest.exist?('/proc/self/statm') if FileTest.exist?('/proc/self/statm')
# for Linux (only?) # for Linux (only?)
$test_all_profile_out.puts "name\tmemsize_of_all\t" + $test_all_profile_out.puts "name\tmemsize_of_all\t" +
(GC.stat.keys + (GC.stat.keys +
%w(size resident share text lib data dt)).join("\t") %w(size resident share text lib data dt)).join("\t")
def memprofile_test_all_result_result def memprofile_test_all_result_result
"#{self.class}\##{self.__name__}\t" \ "#{self.class}\##{self.__name__}\t" \
"#{ObjectSpace.memsize_of_all}\t" \ "#{ObjectSpace.memsize_of_all}\t" \
"#{GC.stat($test_all_profile_gc_stat_hash).values.join("\t")}\t" \ "#{GC.stat($test_all_profile_gc_stat_hash).values.join("\t")}\t" \
"#{File.read('/proc/self/statm').split(/\s+/).join("\t")}" "#{File.read('/proc/self/statm').split(/\s+/).join("\t")}"
end end
else else
$test_all_profile_out.puts "name\tmemsize_of_alls\t" + GC.stat.keys.join("\t") $test_all_profile_out.puts "name\tmemsize_of_alls\t" + GC.stat.keys.join("\t")
def memprofile_test_all_result_result def memprofile_test_all_result_result
"#{self.class}\##{self.__name__}\t" \ "#{self.class}\##{self.__name__}\t" \
"#{ObjectSpace.memsize_of_all}\t" \ "#{ObjectSpace.memsize_of_all}\t" \
"#{GC.stat($test_all_profile_gc_stat_hash).values.join("\t")}" "#{GC.stat($test_all_profile_gc_stat_hash).values.join("\t")}"
end end
end end
def run runner def run runner
result = orig_run(runner) result = orig_run(runner)
$test_all_profile_out.puts memprofile_test_all_result_result $test_all_profile_out.puts memprofile_test_all_result_result
$test_all_profile_out.flush $test_all_profile_out.flush
result result
end end
end end