minstrel 0.2.20110404021920 → 0.2.20110428123747
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/minstrel.rb +43 -10
- metadata +29 -18
data/lib/minstrel.rb
CHANGED
@@ -23,6 +23,7 @@ module Minstrel; class Instrument
|
|
23
23
|
|
24
24
|
class << self
|
25
25
|
@@deferred_wraps = {}
|
26
|
+
@@deferred_method_wraps = {}
|
26
27
|
@@wrapped = Set.new
|
27
28
|
end
|
28
29
|
|
@@ -42,7 +43,7 @@ module Minstrel; class Instrument
|
|
42
43
|
# * this - the object instance in scope (use 'this.class' for the class)
|
43
44
|
# * method - the method (symbol) being called
|
44
45
|
# * *args - the arguments (array) passed to this method.
|
45
|
-
def wrap(klass, &block)
|
46
|
+
def wrap(klass, method_to_wrap=nil, &block)
|
46
47
|
return true if @@wrapped.include?(klass)
|
47
48
|
instrumenter = self # save 'self' for scoping below
|
48
49
|
@@wrapped << klass
|
@@ -55,6 +56,8 @@ module Minstrel; class Instrument
|
|
55
56
|
|
56
57
|
# Wrap class instance methods (like File#read)
|
57
58
|
klass.instance_methods.each do |method|
|
59
|
+
next if !method_to_wrap.nil? and method != method_to_wrap
|
60
|
+
|
58
61
|
method = method.to_sym
|
59
62
|
|
60
63
|
# If we shouldn't wrap a certain class method, skip it.
|
@@ -78,6 +81,7 @@ module Minstrel; class Instrument
|
|
78
81
|
puts "Wrapping #{klass.name}##{method} (method)" if $DEBUG
|
79
82
|
define_method(method) do |*args, &argblock|
|
80
83
|
exception = false
|
84
|
+
puts "#{method}, #{self}"
|
81
85
|
block.call(:enter, self, method, *args)
|
82
86
|
begin
|
83
87
|
# TODO(sissel): Not sure which is better:
|
@@ -104,6 +108,7 @@ module Minstrel; class Instrument
|
|
104
108
|
|
105
109
|
# Wrap class methods (like File.open)
|
106
110
|
klass.methods.each do |method|
|
111
|
+
next if !method_to_wrap.nil? and method != method_to_wrap
|
107
112
|
method = method.to_sym
|
108
113
|
# If we shouldn't wrap a certain class method, skip it.
|
109
114
|
skip = false
|
@@ -169,7 +174,7 @@ module Minstrel; class Instrument
|
|
169
174
|
def wrap_classname(klassname, &block)
|
170
175
|
begin
|
171
176
|
klass = eval(klassname)
|
172
|
-
|
177
|
+
wrap(klass, &block)
|
173
178
|
return true
|
174
179
|
rescue NameError => e
|
175
180
|
@@deferred_wraps[klassname] = block
|
@@ -177,6 +182,19 @@ module Minstrel; class Instrument
|
|
177
182
|
return false
|
178
183
|
end
|
179
184
|
|
185
|
+
def wrap_method(fullname, &block)
|
186
|
+
puts "Want to wrap #{fullname}" if $DEBUG
|
187
|
+
begin
|
188
|
+
klassname, method = fullname.split(/[#.]/, 2)
|
189
|
+
klass = eval(klassname)
|
190
|
+
wrap(klass, method, &block)
|
191
|
+
return true
|
192
|
+
rescue NameError => e
|
193
|
+
@@deferred_method_wraps[fullname] = block
|
194
|
+
return false
|
195
|
+
end
|
196
|
+
end # def wrap_method
|
197
|
+
|
180
198
|
def wrap_all(&block)
|
181
199
|
@@deferred_wraps[:all] = block
|
182
200
|
ObjectSpace.each_object do |obj|
|
@@ -222,6 +240,16 @@ module Minstrel; class Instrument
|
|
222
240
|
@@deferred_wraps.delete(klassname) if !all
|
223
241
|
end
|
224
242
|
end
|
243
|
+
|
244
|
+
klassmethods = @@deferred_method_wraps.keys
|
245
|
+
klassmethods.each do |fullname|
|
246
|
+
block = @@deferred_method_wraps[fullname]
|
247
|
+
instrument = Minstrel::Instrument.new
|
248
|
+
if instrument.wrap_method(fullname, &block)
|
249
|
+
$stderr.puts "Wrap of #{fullname} successful"
|
250
|
+
@@deferred_method_wraps.delete(fullname)
|
251
|
+
end
|
252
|
+
end
|
225
253
|
end
|
226
254
|
return ret
|
227
255
|
end
|
@@ -236,15 +264,20 @@ if ENV["RUBY_INSTRUMENT"]
|
|
236
264
|
klasses = ENV["RUBY_INSTRUMENT"].split(",")
|
237
265
|
|
238
266
|
callback = proc do |point, this, method, *args|
|
239
|
-
puts "#{point} #{this.to_s}##{method}(#{args.inspect}) (thread=#{Thread.current}, self=#{this.inspect})"
|
267
|
+
puts "#{point} #{this.class.to_s}##{method}(#{args.inspect}) (thread=#{Thread.current}, self=#{this.inspect})"
|
240
268
|
end
|
269
|
+
instrument = Minstrel::Instrument.new
|
241
270
|
if klasses.include?(":all:")
|
242
|
-
instrument
|
243
|
-
instrument.wrap_all &callback
|
271
|
+
instrument.wrap_all(&callback)
|
244
272
|
else
|
245
273
|
klasses.each do |klassname|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
274
|
+
if klassname =~ /[#.]/ # Someone's asking for a specific method to wrap
|
275
|
+
# This will wrap one method as indicated by: ClassName#method
|
276
|
+
# TODO(sissel): Maybe also allow ModuleName::method
|
277
|
+
instrument.wrap_method(klassname, &callback)
|
278
|
+
else
|
279
|
+
instrument.wrap_classname(klassname, &callback)
|
280
|
+
end
|
281
|
+
end # klasses.each
|
282
|
+
end
|
283
|
+
end # if ENV["RUBY_INSTRUMENT"]
|
metadata
CHANGED
@@ -1,32 +1,37 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minstrel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
4
|
+
hash: 40220856247505
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 20110428123747
|
10
|
+
version: 0.2.20110428123747
|
6
11
|
platform: ruby
|
7
12
|
authors:
|
8
|
-
|
13
|
+
- Jordan Sissel
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
17
|
|
13
|
-
date: 2011-04-
|
18
|
+
date: 2011-04-28 00:00:00 -07:00
|
14
19
|
default_executable:
|
15
20
|
dependencies: []
|
16
21
|
|
17
22
|
description: Instrument class methods
|
18
23
|
email: jls@semicomplete.com
|
19
24
|
executables:
|
20
|
-
|
25
|
+
- minstrel
|
21
26
|
extensions: []
|
22
27
|
|
23
28
|
extra_rdoc_files: []
|
24
29
|
|
25
30
|
files:
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
31
|
+
- ./lib/minstrel.rb
|
32
|
+
- ./README.textile
|
33
|
+
- ./minstrel.gemspec
|
34
|
+
- bin/minstrel
|
30
35
|
has_rdoc: true
|
31
36
|
homepage: https://github.com/jordansissel/ruby-minstrel
|
32
37
|
licenses: []
|
@@ -35,24 +40,30 @@ post_install_message:
|
|
35
40
|
rdoc_options: []
|
36
41
|
|
37
42
|
require_paths:
|
38
|
-
|
39
|
-
|
43
|
+
- lib
|
44
|
+
- lib
|
40
45
|
required_ruby_version: !ruby/object:Gem::Requirement
|
41
46
|
none: false
|
42
47
|
requirements:
|
43
|
-
|
44
|
-
|
45
|
-
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
hash: 3
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
46
54
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
55
|
none: false
|
48
56
|
requirements:
|
49
|
-
|
50
|
-
|
51
|
-
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
52
63
|
requirements: []
|
53
64
|
|
54
65
|
rubyforge_project:
|
55
|
-
rubygems_version: 1.
|
66
|
+
rubygems_version: 1.3.7
|
56
67
|
signing_key:
|
57
68
|
specification_version: 3
|
58
69
|
summary: minstrel - a ruby instrumentation tool
|