10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/method_profiling.rb', line 10
def profile_method(method_name, profile_name, store_args=false, store_return=false, profile=false)
begin
version = RbConfig::CONFIG['ruby_version']
file = ''
line = ''
if version and (version.match(/^1.9/) or version.match(/^2.0/))
info = self.instance_method(method_name).source_location
if !info.nil?
file = info[0].to_s
line = info[1].to_s
end
else
info = Kernel.caller[0].split(':')
file = info.first.to_s
line = info.last.to_s
end
file = file.gsub /[\'\"]/, ''
line = line.gsub /[\'\"]/, ''
code = "def _oboe_profiled_#{method_name}(*args, &block)
entry_kvs = {}
entry_kvs['Language'] = 'ruby'
entry_kvs['ProfileName'] = '#{profile_name}'
entry_kvs['FunctionName'] = '#{method_name}'
entry_kvs['File'] = '#{file}'
entry_kvs['LineNumber'] = '#{line}'
entry_kvs['Args'] = Oboe::API.pps(*args) if #{store_args}
entry_kvs.merge!(::Oboe::API.get_class_name(self))
Oboe::Context.log(nil, 'profile_entry', entry_kvs)
ret = _oboe_orig_#{method_name}(*args, &block)
exit_kvs = {}
exit_kvs['Language'] = 'ruby'
exit_kvs['ProfileName'] = '#{profile_name}'
exit_kvs['ReturnValue'] = Oboe::API.pps(ret) if #{store_return}
Oboe::Context.log(nil, 'profile_exit', exit_kvs)
ret
end"
rescue Exception => e
Oboe.logger.warn "[oboe/warn] profile_method: #{e.inspect}"
end
begin
class_eval code, __FILE__, __LINE__
alias_method "_oboe_orig_#{method_name}", method_name
alias_method method_name, "_oboe_profiled_#{method_name}"
rescue Exception => e
Oboe.logger.warn "[oboe/warn] Fatal error profiling method (#{method_name}): #{e.inspect}" if Oboe::Config[:verbose]
end
end
|