fast_stack 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/fast_stack/fast_stack.c +3 -2
- data/lib/fast_stack.rb +10 -38
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a98a5bc1eccd73f374b7ed882f44d79aaab1cf65
|
4
|
+
data.tar.gz: 5ea09b23cae084b138af88b10e038add9fd9746a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94de99fd759ed77a9b0b5c02fd05ea5cb65efd0afa3cbf0ce89ac9d6ba6ec566bd370d32b1bc4f5c752931c8a3210ebd9f19a8db65622f241f9549f2dd85b726
|
7
|
+
data.tar.gz: c2fec3c6ffa3bef3573c98d348f165bf8c19f4eb0836e15b25fc2bcd557c7fd3d5abc8ef4c3b126c0932dc8947cd37829860c149185a711a96b51f301971cf02
|
data/ext/fast_stack/fast_stack.c
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#include <stdio.h>
|
2
|
+
#include <sys/time.h>
|
2
3
|
#include <ruby.h>
|
3
4
|
#include <ruby/encoding.h>
|
4
5
|
|
@@ -7,9 +8,9 @@ profiler_start(VALUE module, VALUE usec)
|
|
7
8
|
{
|
8
9
|
struct itimerval timer;
|
9
10
|
timer.it_interval.tv_sec = 0;
|
10
|
-
timer.it_interval.tv_usec = NUM2LONG(usec);
|
11
|
+
timer.it_interval.tv_usec = (suseconds_t)NUM2LONG(usec);
|
11
12
|
timer.it_value = timer.it_interval;
|
12
|
-
setitimer(
|
13
|
+
setitimer(ITIMER_REAL, &timer, 0);
|
13
14
|
|
14
15
|
return Qnil;
|
15
16
|
}
|
data/lib/fast_stack.rb
CHANGED
@@ -1,54 +1,26 @@
|
|
1
1
|
require 'fast_stack/fast_stack'
|
2
2
|
module FastStack
|
3
3
|
def self.profile(millisecs=1, &blk)
|
4
|
-
done = false
|
5
4
|
stacks = []
|
6
5
|
thread = Thread.current
|
7
|
-
delta = millisecs / 1000.0
|
8
6
|
last_time = Time.new
|
9
7
|
|
10
8
|
new_api = thread.respond_to?(:backtrace_locations)
|
11
9
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
10
|
+
trap('ALRM') do
|
11
|
+
stack = (new_api ? thread.backtrace_locations : thread.backtrace)
|
12
|
+
# I am not sure if this is ensured to run in the thread
|
13
|
+
# though in my samples it does
|
14
|
+
if thread == Thread.current
|
15
|
+
stack = stack[2..-1]
|
16
|
+
# since we are in the same thread, might as well remove
|
17
|
+
# our overhead
|
19
18
|
start = Time.new
|
20
|
-
if last_time < start - delta
|
21
|
-
last_time = start
|
22
|
-
stacks << (new_api ? thread.backtrace_locations : thread.backtrace)
|
23
|
-
end
|
24
|
-
|
25
|
-
sleep(delta)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
trap('PROF') do
|
30
|
-
start = Time.new
|
31
|
-
if last_time < start - delta
|
32
|
-
last_time = start
|
33
|
-
stack = (new_api ? thread.backtrace_locations : thread.backtrace)
|
34
|
-
# I am not sure if this is ensured to run in the thread
|
35
|
-
# though in my samples it does
|
36
|
-
if thread == Thread.current
|
37
|
-
stack = stack[2..-1]
|
38
|
-
# since we are in the same thread, might as well remove
|
39
|
-
# our overhead
|
40
|
-
start = Time.new
|
41
|
-
end
|
42
|
-
stacks << stack
|
43
19
|
end
|
20
|
+
stacks << stack
|
44
21
|
end
|
45
22
|
|
46
|
-
|
47
|
-
profile_block(millisecs * 1000, &blk)
|
48
|
-
ensure
|
49
|
-
done = true
|
50
|
-
profile_thread.join
|
51
|
-
end
|
23
|
+
profile_block(millisecs * 1000, &blk)
|
52
24
|
|
53
25
|
stacks
|
54
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fast_stack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|