fast_stack 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +21 -0
- data/README.md +11 -0
- data/ext/fast_stack/extconf.rb +4 -0
- data/ext/fast_stack/fast_stack.c +43 -0
- data/lib/fast_stack.rb +15 -0
- data/spec/fast_stack_spec.rb +30 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f5d6bf89b44f458eee3423d52a00738e01775dbb
|
4
|
+
data.tar.gz: e5a1f5edd19dd540976f792f8a12f4c03cc6ed7e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ceab9df8d2414a03f97ae9b7fd08f4c4970a52f32782603b391aa22cbd2c1347610dbd3e0c3b46f5a3ed5e213541e573ba2fffdf8b8232e89a6e944074deaa46
|
7
|
+
data.tar.gz: f42ea3067770e197cfe00adcff3f0c7ec96507021db7f9690d24b4ebd741e2a70d2b8e5864b610abb256bc53d72be75fdef6968b15649664448318f815999c60
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2006-2009 Steve Sloan
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
#include <stdio.h>
|
2
|
+
#include <ruby.h>
|
3
|
+
#include <ruby/encoding.h>
|
4
|
+
|
5
|
+
static VALUE
|
6
|
+
profiler_start(VALUE module, VALUE usec)
|
7
|
+
{
|
8
|
+
struct itimerval timer;
|
9
|
+
timer.it_interval.tv_sec = 0;
|
10
|
+
timer.it_interval.tv_usec = NUM2LONG(usec);
|
11
|
+
timer.it_value = timer.it_interval;
|
12
|
+
setitimer(ITIMER_PROF, &timer, 0);
|
13
|
+
|
14
|
+
return Qnil;
|
15
|
+
}
|
16
|
+
|
17
|
+
static VALUE
|
18
|
+
profiler_stop(VALUE module)
|
19
|
+
{
|
20
|
+
struct itimerval timer;
|
21
|
+
memset(&timer, 0, sizeof(timer));
|
22
|
+
setitimer(ITIMER_PROF, &timer, 0);
|
23
|
+
|
24
|
+
return Qnil;
|
25
|
+
}
|
26
|
+
|
27
|
+
static VALUE
|
28
|
+
rb_profile_block(VALUE module, VALUE usec)
|
29
|
+
{
|
30
|
+
rb_need_block();
|
31
|
+
|
32
|
+
profiler_start(module, usec);
|
33
|
+
rb_yield(Qundef);
|
34
|
+
profiler_stop(module);
|
35
|
+
|
36
|
+
return Qnil;
|
37
|
+
}
|
38
|
+
|
39
|
+
void Init_fast_stack( void )
|
40
|
+
{
|
41
|
+
VALUE rb_mFastStack = rb_define_module("FastStack");
|
42
|
+
rb_define_module_function(rb_mFastStack, "profile_block", rb_profile_block, 1);
|
43
|
+
}
|
data/lib/fast_stack.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'fast_stack/fast_stack'
|
2
|
+
module FastStack
|
3
|
+
def self.profile(millisecs=1, &blk)
|
4
|
+
stacks = []
|
5
|
+
thread = Thread.current
|
6
|
+
|
7
|
+
trap('PROF') do
|
8
|
+
stacks << thread.backtrace_locations
|
9
|
+
end
|
10
|
+
|
11
|
+
profile_block(millisecs * 1000, &blk)
|
12
|
+
|
13
|
+
stacks
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'fast_stack'
|
2
|
+
|
3
|
+
|
4
|
+
describe String do
|
5
|
+
it "works" do
|
6
|
+
s = FastStack.profile do
|
7
|
+
t = Time.new
|
8
|
+
while (Time.new - t) < 0.1 do
|
9
|
+
"nothing"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
expect(s.count).to be > 2
|
14
|
+
end
|
15
|
+
|
16
|
+
def fib( n )
|
17
|
+
return n if ( 0..1 ).include? n
|
18
|
+
( fib( n - 1 ) + fib( n - 2 ) )
|
19
|
+
end
|
20
|
+
|
21
|
+
it "fibos" do
|
22
|
+
s = FastStack.profile do
|
23
|
+
fib(30)
|
24
|
+
end
|
25
|
+
|
26
|
+
p s.count
|
27
|
+
|
28
|
+
expect(s.count).to be > 10
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fast_stack
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sam Saffron
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake-compiler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Fast method for collecting stack traces in Ruby 2.0
|
56
|
+
email: sam.saffron@gmail.com
|
57
|
+
executables: []
|
58
|
+
extensions:
|
59
|
+
- ext/fast_stack/extconf.rb
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- MIT-LICENSE
|
63
|
+
- README.md
|
64
|
+
- lib/fast_stack.rb
|
65
|
+
- ext/fast_stack/fast_stack.c
|
66
|
+
- ext/fast_stack/extconf.rb
|
67
|
+
- spec/fast_stack_spec.rb
|
68
|
+
homepage: https://github.com/SamSaffron/fast_stack
|
69
|
+
licenses:
|
70
|
+
- MIT
|
71
|
+
metadata: {}
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 2.0.3
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: Fast method for collecting stack traces in Ruby 2.0
|
92
|
+
test_files:
|
93
|
+
- spec/fast_stack_spec.rb
|