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

ruby-changes:33293

From: nagachika <ko1@a...>
Date: Thu, 20 Mar 2014 20:50:23 +0900 (JST)
Subject: [ruby-changes:33293] nagachika:r45372 (ruby_2_0_0): merge revision(s) r45298: [Backport #9599]

nagachika	2014-03-20 20:50:16 +0900 (Thu, 20 Mar 2014)

  New Revision: 45372

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

  Log:
    merge revision(s) r45298: [Backport #9599]
    
    test/ruby/envutil.rb: compare RSS to check memory leak
    
    * test/ruby/envutil.rb (Test::Test#assert_no_memory_leak): compare
      also RSS if available.
    
    * test/ruby/memory_status.rb (Memory::Status.parse): read string
      form of an instance.

  Modified directories:
    branches/ruby_2_0_0/
  Modified files:
    branches/ruby_2_0_0/test/ruby/envutil.rb
    branches/ruby_2_0_0/test/ruby/memory_status.rb
    branches/ruby_2_0_0/version.h
Index: ruby_2_0_0/version.h
===================================================================
--- ruby_2_0_0/version.h	(revision 45371)
+++ ruby_2_0_0/version.h	(revision 45372)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1
 #define RUBY_VERSION "2.0.0"
 #define RUBY_RELEASE_DATE "2014-03-20"
-#define RUBY_PATCHLEVEL 459
+#define RUBY_PATCHLEVEL 460
 
 #define RUBY_RELEASE_YEAR 2014
 #define RUBY_RELEASE_MONTH 3
Index: ruby_2_0_0/test/ruby/memory_status.rb
===================================================================
--- ruby_2_0_0/test/ruby/memory_status.rb	(revision 45371)
+++ ruby_2_0_0/test/ruby/memory_status.rb	(revision 45372)
@@ -1,5 +1,3 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/memory_status.rb#L1
-require_relative "envutil"
-
 module Memory
   keys = []
   vals = []
@@ -110,5 +108,20 @@ module Memory https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/memory_status.rb#L108
     def initialize
       _update
     end
+
+    def to_s
+      status = each_pair.map {|n,v|
+        "#{n}:#{v}"
+      }
+      "{#{status.join(",")}}"
+    end
+
+    def self.parse(str)
+      status = allocate
+      str.scan(/(?:\A\{|\G,)(#{members.join('|')}):(\d+)(?=,|\}\z)/) do
+        status[$1] = $2.to_i
+      end
+      status
+    end
   end
 end
Index: ruby_2_0_0/test/ruby/envutil.rb
===================================================================
--- ruby_2_0_0/test/ruby/envutil.rb	(revision 45371)
+++ ruby_2_0_0/test/ruby/envutil.rb	(revision 45372)
@@ -341,6 +341,7 @@ eom https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/envutil.rb#L341
       end
 
       def assert_no_memory_leak(args, prepare, code, message=nil, limit: 1.5)
+        require_relative 'memory_status'
         token = "\e[7;1m#{$$.to_s}:#{Time.now.strftime('%s.%L')}:#{rand(0x10000).to_s(16)}:\e[m"
         token_dump = token.dump
         token_re = Regexp.quote(token)
@@ -351,16 +352,22 @@ eom https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/envutil.rb#L352
           "-v", "-",
         ]
         cmd = [
-          'END {STDERR.puts '"#{token_dump}"'"FINAL=#{Memory::Status.new.size}"}',
+          'END {STDERR.puts '"#{token_dump}"'"FINAL=#{Memory::Status.new}"}',
           prepare,
-          'STDERR.puts('"#{token_dump}"'"START=#{$initial_size = Memory::Status.new.size}")',
+          'STDERR.puts('"#{token_dump}"'"START=#{$initial_size = Memory::Status.new}")',
           code,
+          'GC.start',
         ].join("\n")
         _, err, status = EnvUtil.invoke_ruby(args, cmd, true, true)
-        before = err.sub!(/^#{token_re}START=(\d+)\n/, '') && $1.to_i
-        after = err.sub!(/^#{token_re}FINAL=(\d+)\n/, '') && $1.to_i
+        before = err.sub!(/^#{token_re}START=(\{.*\})\n/, '') && Memory::Status.parse($1)
+        after = err.sub!(/^#{token_re}FINAL=(\{.*\})\n/, '') && Memory::Status.parse($1)
         assert_equal([true, ""], [status.success?, err], message)
-        assert_operator(after.fdiv(before), :<, limit, message)
+        ([:size, :rss] & after.members).each do |n|
+          b = before[n]
+          a = after[n]
+          next unless a > 0 and b > 0
+          assert_operator(a.fdiv(b), :<, limit, message(message) {"#{n}: #{b} => #{a}"})
+        end
       end
 
       def assert_is_minus_zero(f)

Property changes on: ruby_2_0_0
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r45298


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

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