1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/profiler.rb: support calling singleton methods of

an instance of BasicObject.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35076 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ktsj 2012-03-18 01:03:35 +00:00
parent 30c0db4a85
commit 42c18fe764
2 changed files with 16 additions and 3 deletions

View file

@ -1,3 +1,8 @@
Sun Mar 18 10:01:02 2012 Kazuki Tsujimoto <kazuki@callcc.net>
* lib/profiler.rb: support calling singleton methods of
an instance of BasicObject.
Sat Mar 17 06:56:58 2012 Eric Hodel <drbrain@segment7.net> Sat Mar 17 06:56:58 2012 Eric Hodel <drbrain@segment7.net>
* object.c: Fix indentation of Class#inherited example. * object.c: Fix indentation of Class#inherited example.

View file

@ -59,7 +59,7 @@
module Profiler__ module Profiler__
# internal values # internal values
@@start = @@stack = @@map = nil @@start = @@stack = @@map = @@array = nil
PROFILE_PROC = proc{|event, file, line, id, binding, klass| PROFILE_PROC = proc{|event, file, line, id, binding, klass|
case event case event
when "call", "c-call" when "call", "c-call"
@ -69,7 +69,11 @@ module Profiler__
now = Process.times[0] now = Process.times[0]
key = [klass, id] key = [klass, id]
if tick = @@stack.pop if tick = @@stack.pop
data = (@@map[key] ||= [0, 0.0, 0.0, key]) data = begin
@@map[key] ||= [0, 0.0, 0.0, key]
rescue NoMethodError
@@array.find{|i| i[3] == key} || (@@array << [0, 0.0, 0.0, key])[-1]
end
data[0] += 1 data[0] += 1
cost = now - tick[0] cost = now - tick[0]
data[1] += cost data[1] += cost
@ -83,6 +87,7 @@ module_function
@@start = Process.times[0] @@start = Process.times[0]
@@stack = [] @@stack = []
@@map = {} @@map = {}
@@array = []
set_trace_func PROFILE_PROC set_trace_func PROFILE_PROC
end end
def stop_profile def stop_profile
@ -92,7 +97,7 @@ module_function
stop_profile stop_profile
total = Process.times[0] - @@start total = Process.times[0] - @@start
if total == 0 then total = 0.01 end if total == 0 then total = 0.01 end
data = @@map.values data = @@map.values + @@array
data = data.sort_by{|x| -x[2]} data = data.sort_by{|x| -x[2]}
sum = 0 sum = 0
f.printf " %% cumulative self self total\n" f.printf " %% cumulative self self total\n"
@ -113,6 +118,9 @@ module_function
name += "." name += "."
end end
name + id.id2name name + id.id2name
rescue NoMethodError => e
name = e.message.slice(/#<.*?:0x[0-9a-f]+>/) || ""
name + "." + id.id2name
end end
private :get_name private :get_name
end end