ruby-changes:17619
From: ko1 <ko1@a...>
Date: Fri, 29 Oct 2010 23:36:02 +0900 (JST)
Subject: [ruby-changes:17619] Ruby:r29627 (trunk): * test/profile_test_all.rb: added.
ko1 2010-10-29 23:35:53 +0900 (Fri, 29 Oct 2010) New Revision: 29627 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29627 Log: * test/profile_test_all.rb: added. You can use test-all profiler with the following command: RUBY_TEST_ALL_PROFILE=true make test-all This command generates ./test_all_profile and you can analyse which tests consume memories. * test/runner.rb: ditto. Added files: trunk/test/profile_test_all.rb Modified files: trunk/ChangeLog trunk/test/runner.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 29626) +++ ChangeLog (revision 29627) @@ -1,3 +1,13 @@ +Fri Oct 29 23:32:36 2010 Koichi Sasada <ko1@a...> + + * test/profile_test_all.rb: added. + You can use test-all profiler with the following command: + RUBY_TEST_ALL_PROFILE=true make test-all + This command generates ./test_all_profile and you can analyse + which tests consume memories. + + * test/runner.rb: ditto. + Fri Oct 29 10:02:03 2010 NARUSE, Yui <naruse@r...> * tool/enc-unicode.rb, Index: test/runner.rb =================================================================== --- test/runner.rb (revision 29626) +++ test/runner.rb (revision 29627) @@ -6,6 +6,8 @@ src_testdir = File.dirname(File.expand_path(__FILE__)) srcdir = File.dirname(src_testdir) +require_relative 'profile_test_all' if ENV['RUBY_TEST_ALL_PROFILE'] == 'true' + tests = Test::Unit.new {|files, options| options[:base_directory] = src_testdir if files.empty? Index: test/profile_test_all.rb =================================================================== --- test/profile_test_all.rb (revision 0) +++ test/profile_test_all.rb (revision 29627) @@ -0,0 +1,52 @@ +require 'objspace' + +# +# purpose: +# Profile memory usage of each tests. +# +# usage: +# RUBY_TEST_ALL_PROFILE=true make test-all +# +# output: +# ./test_all_profile +# +# collected information: +# - ObjectSpace.memsize_of_all +# - GC.stat +# - /proc/self/statm (if it exists) +# + +class MiniTest::Unit::TestCase + alias orig_run run + + $test_all_profile_out = open('test_all_profile', 'w') + $test_all_profile_gc_stat_hash = {} + + if FileTest.exist?('/proc/self/statm') + # for Linux (only?) + $test_all_profile_out.puts "name\tmemsize_of_all\t" + + (GC.stat.keys + + %w(size resident share text lib data dt)).join("\t") + + def memprofile_test_all_result_result + "#{self.class}\##{self.__name__}\t" \ + "#{ObjectSpace.memsize_of_all}\t" \ + "#{GC.stat($test_all_profile_gc_stat_hash).values.join("\t")}\t" \ + "#{File.read('/proc/self/statm').split(/\s+/).join("\t")}" + end + else + $test_all_profile_out.puts "name\tmemsize_of_alls\t" + GC.stat.keys.join("\t") + def memprofile_test_all_result_result + "#{self.class}\##{self.__name__}\t" \ + "#{ObjectSpace.memsize_of_all}\t" \ + "#{GC.stat($test_all_profile_gc_stat_hash).values.join("\t")}" + end + end + + def run runner + result = orig_run(runner) + $test_all_profile_out.puts memprofile_test_all_result_result + $test_all_profile_out.flush + result + end +end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/