komamitsu-gc_monitor 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.rdoc +3 -0
  2. data/lib/gc_monitor.rb +9 -16
  3. metadata +4 -3
data/README.rdoc CHANGED
@@ -8,6 +8,9 @@ If you want to monitor the specific class, you may include GcMonitor into the cl
8
8
 
9
9
  class Foo
10
10
  attr_accessor :dummy
11
+ end
12
+
13
+ class Foo
11
14
  include GcMonitor
12
15
  end
13
16
 
data/lib/gc_monitor.rb CHANGED
@@ -1,8 +1,6 @@
1
1
  require 'thread'
2
2
 
3
3
  module GcMonitor
4
- VERSION = '0.0.2'
5
-
6
4
  class << self
7
5
  def remaining_objects
8
6
  @remaining_objects ||= {}
@@ -14,10 +12,14 @@ module GcMonitor
14
12
  @mutex
15
13
  end
16
14
 
15
+ def out_of_scope?(klass)
16
+ [GcMonitor, Time, Mutex].include?(klass)
17
+ end
18
+
17
19
  def include_in_subclasses(klass = Object)
18
20
  ObjectSpace.each_object(class << klass; self; end) do |cls|
19
21
  next if cls.ancestors.include?(Exception)
20
- next if [GcMonitor, Time].include?(cls)
22
+ next if out_of_scope?(cls)
21
23
  cls.__send__(:include, GcMonitor)
22
24
  end
23
25
  end
@@ -27,12 +29,14 @@ module GcMonitor
27
29
  end
28
30
 
29
31
  def regist(obj, caller)
32
+ return if out_of_scope?(obj.class)
30
33
  mutex.synchronize do
31
34
  remaining_objects[GcMonitor.key(obj)] = {:time => Time.now, :caller => caller}
32
35
  end
33
36
  end
34
37
 
35
38
  def release(obj, caller)
39
+ return if out_of_scope?(obj.class)
36
40
  mutex.synchronize do
37
41
  remaining_objects.delete(GcMonitor.key(obj))
38
42
  end
@@ -70,6 +74,7 @@ module GcMonitor
70
74
  return if @gc_monitor_included
71
75
  @gc_monitor_included = true
72
76
  end
77
+
73
78
  return unless base.private_methods.include?("initialize")
74
79
  begin
75
80
  base.__send__(:alias_method, :initialize_without_gc_monitor_pre, :initialize)
@@ -78,14 +83,6 @@ module GcMonitor
78
83
  end
79
84
  base.__send__(:alias_method, :initialize, :initialize_with_gc_monitor_pre)
80
85
 
81
- def base.method_added(name)
82
- return unless name == :initialize
83
- return if @made_initialize_with_gc_monitor_post
84
- @made_initialize_with_gc_monitor_post = true
85
- alias_method :initialize_without_gc_monitor_post, :initialize
86
- alias_method :initialize, :initialize_with_gc_monitor_post
87
- end
88
-
89
86
  def base.release_hook(proc_str)
90
87
  @@gc_monitor_release_hook = proc_str
91
88
  end
@@ -131,13 +128,9 @@ module GcMonitor
131
128
  end
132
129
 
133
130
  def initialize_with_gc_monitor_pre(*args, &blk)
131
+ return if caller.detect{|c| c =~ /in `initialize(?:_with_gc_monitor_pre)?'\z/}
134
132
  initialize_without_gc_monitor_pre(*args, &blk)
135
133
  regist_gc_monitor(caller)
136
134
  end
137
-
138
- def initialize_with_gc_monitor_post(*args, &blk)
139
- initialize_without_gc_monitor_post(*args, &blk)
140
- regist_gc_monitor(caller)
141
- end
142
135
  end
143
136
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: komamitsu-gc_monitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - komamitsu
@@ -37,8 +37,9 @@ has_rdoc: true
37
37
  homepage: http://github.com/komamitsu/gc_monitor
38
38
  licenses:
39
39
  post_install_message:
40
- rdoc_options: []
41
-
40
+ rdoc_options:
41
+ - --main
42
+ - README.rdoc
42
43
  require_paths:
43
44
  - lib
44
45
  required_ruby_version: !ruby/object:Gem::Requirement