summaryrefslogtreecommitdiff
path: root/test/profile_test_all.rb
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-10-29 14:35:53 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-10-29 14:35:53 +0000
commit32623a16276b8c99a8c142c570cb2f50dc3df737 (patch)
tree167f8e540931b46a3dcc6c1c9bbe86abf9b58bca /test/profile_test_all.rb
parentf85b841a012bb07e4b5b22a792974d7d929a091d (diff)
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29627 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/profile_test_all.rb')
-rw-r--r--test/profile_test_all.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/test/profile_test_all.rb b/test/profile_test_all.rb
new file mode 100644
index 0000000000..52eaf364aa
--- /dev/null
+++ b/test/profile_test_all.rb
@@ -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