Improved the swig_gc.rb interface.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9718 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
ca5f54f668
commit
c1119d264a
3 changed files with 42 additions and 26 deletions
|
|
@ -23,12 +23,11 @@ require 'newobject1'
|
||||||
|
|
||||||
include Newobject1
|
include Newobject1
|
||||||
|
|
||||||
|
GC.track_class = Foo
|
||||||
GC.stats(Foo)
|
GC.start
|
||||||
100.times { foo1 = Foo.makeFoo; foo2 = foo1.makeMore }
|
100.times { foo1 = Foo.makeFoo; foo2 = foo1.makeMore }
|
||||||
GC.stats(Foo)
|
GC.stats
|
||||||
swig_assert( 'Foo.fooCount == 200', "but is #{Foo.fooCount}" )
|
swig_assert( 'Foo.fooCount == 200', "but is #{Foo.fooCount}" )
|
||||||
GC.start
|
GC.start
|
||||||
GC.stats(Foo)
|
|
||||||
swig_assert( 'Foo.fooCount <= 2', "but is #{Foo.fooCount}" )
|
swig_assert( 'Foo.fooCount <= 2', "but is #{Foo.fooCount}" )
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,11 @@ require 'newobject2'
|
||||||
|
|
||||||
include Newobject2
|
include Newobject2
|
||||||
|
|
||||||
GC.stats(Foo)
|
GC.track_class = Foo
|
||||||
|
GC.stats
|
||||||
100.times { foo1 = makeFoo }
|
100.times { foo1 = makeFoo }
|
||||||
GC.stats(Foo)
|
GC.stats
|
||||||
swig_assert( 'fooCount == 100', "but is #{fooCount}" )
|
swig_assert( 'fooCount == 100', "but is #{fooCount}" )
|
||||||
GC.start
|
GC.start
|
||||||
GC.stats(Foo)
|
|
||||||
swig_assert( 'fooCount <= 1', "but is #{fooCount}" )
|
swig_assert( 'fooCount <= 1', "but is #{fooCount}" )
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,27 +11,44 @@
|
||||||
# VERY nice function from Robert Klemme to check memory leaks
|
# VERY nice function from Robert Klemme to check memory leaks
|
||||||
# and check on what GC has collected since last call.
|
# and check on what GC has collected since last call.
|
||||||
#
|
#
|
||||||
module GC
|
if $VERBOSE
|
||||||
@@last_stat = nil
|
module GC
|
||||||
def self.stats(klass = nil)
|
|
||||||
return unless $VERBOSE
|
|
||||||
|
|
||||||
stats = Hash.new(0)
|
class << self
|
||||||
ObjectSpace.each_object {|o| stats[o.class] += 1}
|
|
||||||
|
attr :last_stat
|
||||||
|
attr_accessor :track_class
|
||||||
|
|
||||||
if klass
|
alias :_start :start
|
||||||
v = stats[klass]
|
|
||||||
printf "\t%-30s %10d", klass.to_s, v
|
def start
|
||||||
printf " | delta %10d", (v - @@last_stat[klass]) if @@last_stat
|
_start
|
||||||
puts
|
stats
|
||||||
else
|
end
|
||||||
stats.sort {|(k1,v1),(k2,v2)| v2 <=> v1}.each do |k,v|
|
|
||||||
printf "\t%-30s %10d", k, v
|
def stats
|
||||||
printf " | delta %10d", (v - @@last_stat[k]) if @@last_stat
|
stats = Hash.new(0)
|
||||||
puts
|
ObjectSpace.each_object {|o| stats[o.class] += 1}
|
||||||
|
|
||||||
|
if track_class
|
||||||
|
v = stats[track_class]
|
||||||
|
printf "\t%-30s %10d", track_class.to_s, v
|
||||||
|
if last_stat
|
||||||
|
printf " | delta %10d", (v - last_stat[track_class])
|
||||||
|
end
|
||||||
|
puts
|
||||||
|
else
|
||||||
|
stats.sort {|(k1,v1),(k2,v2)| v2 <=> v1}.each do |k,v|
|
||||||
|
printf "\t%-30s %10d", k, v
|
||||||
|
printf " | delta %10d", (v - last_stat[k]) if last_stat
|
||||||
|
puts
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
last_stat = stats
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@last_stat = stats
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue