5
6
7
8
9
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
|
# File 'lib/fast_stack.rb', line 5
def self.profile(millisecs=1, mode=:ruby, &blk)
return profile_native(millisecs, &blk) if mode == :c
stacks = []
thread = Thread.current
new_api = thread.respond_to?(:backtrace_locations)
handler do
FastStack.stop
stack = (new_api ? thread.backtrace_locations : thread.backtrace)
if thread == Thread.current
stack = stack[2..-1]
end
stacks << stack
FastStack.start(millisecs*1000)
end
begin
FastStack.start(millisecs*1000)
blk.call
ensure
FastStack.stop
end
stacks
end
|