[前][次][番号順一覧][スレッド一覧]

ruby-changes:30505

From: ko1 <ko1@a...>
Date: Fri, 16 Aug 2013 17:46:36 +0900 (JST)
Subject: [ruby-changes:30505] ko1:r42584 (trunk): * test/profile_test_all.rb: refactoring memory profiling tool for

ko1	2013-08-16 17:46:21 +0900 (Fri, 16 Aug 2013)

  New Revision: 42584

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42584

  Log:
    * test/profile_test_all.rb: refactoring memory profiling tool for
      test-all.
      Add profiling targets /proc/meminfo and /proc/self/status.
    * test/runner.rb: accept other than 'true'.

  Modified files:
    trunk/ChangeLog
    trunk/test/profile_test_all.rb
    trunk/test/runner.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42583)
+++ ChangeLog	(revision 42584)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Aug 16 17:32:02 2013  Koichi Sasada  <ko1@a...>
+
+	* test/profile_test_all.rb: refactoring memory profiling tool for
+	  test-all.
+	  Add profiling targets /proc/meminfo and /proc/self/status.
+
+	* test/runner.rb: accept other than 'true'.
+
 Fri Aug 16 11:23:35 2013  NAKAMURA Usaku  <usa@r...>
 
 	* file.c (rb_file_size, rb_file_flock): improve performance of Winodws.
Index: test/runner.rb
===================================================================
--- test/runner.rb	(revision 42583)
+++ test/runner.rb	(revision 42584)
@@ -12,7 +12,7 @@ end https://github.com/ruby/ruby/blob/trunk/test/runner.rb#L12
 
 ENV["GEM_SKIP"] = ENV["GEM_HOME"] = ENV["GEM_PATH"] = "".freeze
 
-require_relative 'profile_test_all' if ENV['RUBY_TEST_ALL_PROFILE'] == 'true'
+require_relative 'profile_test_all' if ENV.has_key?('RUBY_TEST_ALL_PROFILE')
 
 module Test::Unit
   module ZombieHunter
Index: test/profile_test_all.rb
===================================================================
--- test/profile_test_all.rb	(revision 42583)
+++ test/profile_test_all.rb	(revision 42584)
@@ -1,52 +1,83 @@ https://github.com/ruby/ruby/blob/trunk/test/profile_test_all.rb#L1
-require 'objspace'
-
 #
 # purpose:
 #  Profile memory usage of each tests.
 #
 # usage:
-#   RUBY_TEST_ALL_PROFILE=true make test-all
+#   RUBY_TEST_ALL_PROFILE=[file] make test-all
 #
 # output:
-#   ./test_all_profile
+#   [file] specified by RUBY_TEST_ALL_PROFILE
+#   If [file] is 'true', then it is ./test_all_profile
 #
 # collected information:
 #   - ObjectSpace.memsize_of_all
 #   - GC.stat
-#   - /proc/self/statm (if it exists)
+#   - /proc/meminfo     (some fields, if exists)
+#   - /proc/self/status (some fields, if exists)
+#   - /proc/self/statm  (if exists)
 #
 
+require 'objspace'
+
 class MiniTest::Unit::TestCase
   alias orig_run run
 
-  $test_all_profile_out = open('test_all_profile', 'w')
-  $test_all_profile_gc_stat_hash = {}
+  file = ENV['RUBY_TEST_ALL_PROFILE']
+  file = 'test-all-profile-result' if file == 'true'
+  TEST_ALL_PROFILE_OUT = open(file, 'w')
+  TEST_ALL_PROFILE_GC_STAT_HASH = {}
+  TEST_ALL_PROFILE_BANNER = ['name']
+  TEST_ALL_PROFILE_PROCS  = []
+
+  def self.add *name, &b
+    TEST_ALL_PROFILE_BANNER.concat name
+    TEST_ALL_PROFILE_PROCS << b
+  end
 
-  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")}"
+  add 'emsize_of_all', *GC.stat.keys do |result|
+    result << ObjectSpace.memsize_of_all
+    GC.stat(TEST_ALL_PROFILE_GC_STAT_HASH)
+    result.concat TEST_ALL_PROFILE_GC_STAT_HASH.values
+  end
+
+  def self.add_proc_meminfo file, fields
+    return unless FileTest.exist?(file)
+    regexp = /(#{fields.join("|")}):\s*(\d+) kB/
+    # check = {}; fields.each{|e| check[e] = true}
+    add *fields do |result|
+      text = File.read(file)
+      text.gsub(regexp){
+        # check.delete $1
+        result << $2
+        ''
+      }
+      # raise check.inspect unless check.empty?
     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
+
+  add_proc_meminfo '/proc/meminfo', %w(MemTotal MemFree)
+  add_proc_meminfo '/proc/self/status', %w(VmPeak VmSize VmHWM VmRSS)
+
+  if FileTest.exist?('/proc/self/statm')
+    add *%w(size resident share text lib data dt) do |result|
+      result.concat File.read('/proc/self/statm').split(/\s+/)
     end
   end
 
+  def memprofile_test_all_result_result
+    result = ["#{self.class}\##{self.__name__}"]
+    TEST_ALL_PROFILE_PROCS.each{|proc|
+      proc.call(result)
+    }
+    result.join("\t")
+  end
+
   def run runner
     result = orig_run(runner)
-    $test_all_profile_out.puts memprofile_test_all_result_result
-    $test_all_profile_out.flush
+    TEST_ALL_PROFILE_OUT.puts memprofile_test_all_result_result
+    TEST_ALL_PROFILE_OUT.flush
     result
   end
+
+  TEST_ALL_PROFILE_OUT.puts TEST_ALL_PROFILE_BANNER.join("\t")
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]