stack_frames 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7eb6415831cb725f642009b7e3faffaa31cc12e53986a50cc6c66afb22a40858
4
+ data.tar.gz: 785cae19b0d65246275c483009711bf7adfbd99b2cee6c146f13711e1e87bf74
5
+ SHA512:
6
+ metadata.gz: b31829453fe42d5852a08f272a9604a0a8011faabb1e099c301311167b6b03db7c5eade3239d3b6a495c4164348af8d645a84315d3f4c4bc5a0c1352636cb194
7
+ data.tar.gz: c06d4ad28aad9e559c4bb9702f12b69af603cbce2617fa4fbf8929fa2054c1b101587ea32776c398b12594ac361e21d8d97f3c1a1e917786c15a285c855a76f9
@@ -0,0 +1,3 @@
1
+ # .github/probots.yml
2
+ enabled:
3
+ - cla
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /Gemfile.lock
10
+ *.bundle
11
+ *.o
12
+ *.so
13
+ /ext/*/Makefile
14
+ *.gem
@@ -0,0 +1,8 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.4.9 # minimum supported
7
+ - 2.7.0 # latest released
8
+ before_install: gem install bundler -v 1.17.3
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at opensource@shopify.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
@@ -0,0 +1,29 @@
1
+ # Contributing
2
+
3
+ Types of contributions we welcome:
4
+
5
+ * Reporting issues with existing features
6
+ * Bug fixes
7
+ * Performance improvements
8
+ * Documentation and/or clearer interfaces
9
+ * Exposing more of the MRI's profile frames API
10
+
11
+ ## Proposing Features
12
+
13
+ This libraries primary purpose is to be an optimization over using
14
+ `source_location` to get backtrace information, so ease of use in this
15
+ case means ease of writing fast code.
16
+
17
+ When in doubt about whether we will be interested in including a
18
+ new feature in this project, please open an issue to propose the
19
+ feature so we can confirm the feature should be in scope for the
20
+ project before it is implemented.
21
+
22
+ ## How To Contribute
23
+
24
+ 1. Fork the [repository in github](https://github.com/Shopify/stack_frames)
25
+ 2. Create your feature branch (`git checkout -b fix-feature`)
26
+ 3. Commit your changes (`git commit -am 'fix: Summarize change'`)
27
+ 3. Make sure all tests pass (`bundle exec rake`)
28
+ 4. Push to the branch (`git push origin fix-feature`)
29
+ 5. [Create new pull request](https://github.com/Shopify/stack_frames/pulls)
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in stack_frames.gemspec
6
+ gemspec
7
+
8
+ gem 'benchmark-ips'
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019-present, Shopify Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,70 @@
1
+ # StackFrames
2
+
3
+ This library allows backtraces to be captured and accessed without
4
+ object allocations by leveraging MRI's profile frames API.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'stack_frames'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install stack_frames
21
+
22
+ ## Usage
23
+
24
+ Pre-allocate a buffer to use for capturing stack frames, then re-use that buffer
25
+ to capture the backtrace multiple times.
26
+
27
+ ```ruby
28
+ # example.rb
29
+ require 'stack_frames'
30
+
31
+ STACK_FRAMES_BUFFER = StackFrames::Buffer.new(2)
32
+ CAPTURE_CALLER = -> { STACK_FRAMES_BUFFER.capture }
33
+
34
+ def foo(&block)
35
+ yield
36
+ end
37
+
38
+ foo(&CAPTURE_CALLER)
39
+ caller_frame = STACK_FRAMES_BUFFER[1]
40
+ p caller_frame.path # => "example.rb"
41
+ p caller_frame.lineno # => 14
42
+ p caller_frame.method_name # => "foo"
43
+ puts
44
+
45
+ CAPTURE_CALLER.call
46
+ p caller_frame.path # => "example.rb"
47
+ p caller_frame.lineno # => 18
48
+ p caller_frame.method_name # => nil
49
+
50
+ # You can also search through the captured stack frames:
51
+ STACK_FRAMES_BUFFER.find { |frame| frame.path == "example.rb" } # => [the matching stack frame object]
52
+ ```
53
+
54
+ If stack frames need to be captured in multiple threads, then access
55
+ to the buffer can either be synchronized using a Mutex or a per-thread
56
+ buffer could be created and stored in a thread-local variable.
57
+
58
+ ## Development
59
+
60
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
61
+
62
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
63
+
64
+ ## Contributing
65
+
66
+ See our [contributing guidelines](CONTRIBUTING.md) for more information.
67
+
68
+ ## License
69
+
70
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,17 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+ require 'rake/extensiontask'
4
+
5
+ ENV['STACK_FRAMES_DEV'] = '1'
6
+
7
+ Rake::ExtensionTask.new("stack_frames") do |ext|
8
+ ext.lib_dir = 'lib/stack_frames'
9
+ end
10
+
11
+ Rake::TestTask.new(test: :compile) do |t|
12
+ t.libs << "test"
13
+ t.libs << "lib"
14
+ t.test_files = FileList["test/**/*_test.rb"]
15
+ end
16
+
17
+ task :default => :test
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
4
+ require 'benchmark/ips'
5
+ require 'stack_frames'
6
+
7
+ STACK_FRAMES_CALLER_BUFFER = StackFrames::Buffer.new(2)
8
+ STACK_FRAMES_BUFFER = StackFrames::Buffer.new(2048)
9
+ LOCK = Mutex.new
10
+ Thread.current.thread_variable_set(:stack_frames_buffer, STACK_FRAMES_BUFFER)
11
+
12
+ Benchmark.ips do |bench|
13
+ bench.report("caller(1, 1)") do
14
+ caller(1, 1).first
15
+ end
16
+ bench.report("caller_locations(1, 1)") do
17
+ caller_locations(1, 1).first.path
18
+ end
19
+ bench.report("stack_frames caller frame") do
20
+ buffer = STACK_FRAMES_CALLER_BUFFER
21
+ buffer.capture
22
+ buffer[1].path
23
+ end
24
+ bench.report("caller") do
25
+ caller.first
26
+ end
27
+ bench.report("caller_locations") do
28
+ caller_locations.first.path
29
+ end
30
+ bench.report("stack_frames capture stack") do
31
+ buffer = STACK_FRAMES_BUFFER
32
+ buffer.capture
33
+ buffer[1].path
34
+ end
35
+ bench.report("stack_frames synchronized capture") do
36
+ LOCK.synchronize do
37
+ buffer = STACK_FRAMES_BUFFER
38
+ buffer.capture
39
+ buffer[1].path
40
+ end
41
+ end
42
+ bench.report("stack_frames thread-local capture") do
43
+ buffer = Thread.current.thread_variable_get(:stack_frames_buffer)
44
+ buffer.capture
45
+ buffer[1].path
46
+ end
47
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "stack_frames"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,21 @@
1
+ # example.rb
2
+ require 'stack_frames'
3
+
4
+ STACK_FRAMES_BUFFER = StackFrames::Buffer.new(2)
5
+ CAPTURE_CALLER = -> { STACK_FRAMES_BUFFER.capture }
6
+
7
+ def foo(&block)
8
+ yield
9
+ end
10
+
11
+ foo(&CAPTURE_CALLER)
12
+ caller_frame = STACK_FRAMES_BUFFER[1]
13
+ p caller_frame.path # => "example.rb"
14
+ p caller_frame.lineno # => 14
15
+ p caller_frame.method_name # => "foo"
16
+ puts
17
+
18
+ CAPTURE_CALLER.call
19
+ p caller_frame.path # => "example.rb"
20
+ p caller_frame.lineno # => 18
21
+ p caller_frame.method_name # => nil
@@ -0,0 +1,148 @@
1
+ #include "buffer.h"
2
+ #include "frame.h"
3
+
4
+ typedef struct {
5
+ VALUE *profile_frames;
6
+ VALUE *frames;
7
+ int *lines;
8
+ int length, capacity;
9
+ } buffer_t;
10
+
11
+ static void buffer_mark(void *ptr)
12
+ {
13
+ buffer_t *buffer = ptr;
14
+
15
+ for (int i = 0; i < buffer->length; i++) {
16
+ rb_gc_mark(buffer->profile_frames[i]);
17
+ }
18
+ for (int i = 0; i < buffer->capacity; i++) {
19
+ rb_gc_mark(buffer->frames[i]);
20
+ }
21
+ }
22
+
23
+ static void buffer_free(void *ptr)
24
+ {
25
+ buffer_t *buffer = ptr;
26
+ ruby_xfree(buffer->profile_frames);
27
+ ruby_xfree(buffer->frames);
28
+ ruby_xfree(buffer->lines);
29
+ }
30
+
31
+ static size_t buffer_memsize(const void *ptr)
32
+ {
33
+ return sizeof(buffer_t);
34
+ }
35
+
36
+ const rb_data_type_t buffer_data_type = {
37
+ "stack_frames_buffer",
38
+ { buffer_mark, buffer_free, buffer_memsize, },
39
+ NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
40
+ };
41
+
42
+ static VALUE buffer_allocate(VALUE klass) {
43
+ VALUE obj;
44
+ buffer_t *buffer;
45
+
46
+ obj = TypedData_Make_Struct(klass, buffer_t, &buffer_data_type, buffer);
47
+ return obj;
48
+ }
49
+
50
+ static VALUE buffer_initialize(VALUE self, VALUE size) {
51
+ int capacity = NUM2INT(size);
52
+ buffer_t *buffer;
53
+
54
+ if (capacity <= 0) {
55
+ rb_raise(rb_eArgError, "non-positive buffer capacity");
56
+ }
57
+
58
+ TypedData_Get_Struct(self, buffer_t, &buffer_data_type, buffer);
59
+ buffer->profile_frames = ALLOC_N(VALUE, capacity);
60
+ buffer->lines = ALLOC_N(int, capacity);
61
+ buffer->capacity = capacity;
62
+ buffer->frames = ALLOC_N(VALUE, capacity);
63
+
64
+ for (int i = 0; i < capacity; i++) {
65
+ buffer->frames[i] = stack_frame_new(self, i);
66
+ }
67
+ return Qnil;
68
+ }
69
+
70
+ static VALUE buffer_capture(VALUE self) {
71
+ buffer_t *buffer;
72
+
73
+ TypedData_Get_Struct(self, buffer_t, &buffer_data_type, buffer);
74
+ buffer->length = rb_profile_frames(0, buffer->capacity, buffer->profile_frames, buffer->lines);
75
+ return INT2NUM(buffer->length);
76
+ }
77
+
78
+ static VALUE buffer_length(VALUE self) {
79
+ buffer_t *buffer;
80
+
81
+ TypedData_Get_Struct(self, buffer_t, &buffer_data_type, buffer);
82
+ return INT2NUM(buffer->length);
83
+ }
84
+
85
+ static VALUE buffer_capacity(VALUE self) {
86
+ buffer_t *buffer;
87
+
88
+ TypedData_Get_Struct(self, buffer_t, &buffer_data_type, buffer);
89
+ return INT2NUM(buffer->capacity);
90
+ }
91
+
92
+ static VALUE buffer_aref(VALUE self, VALUE ruby_index) {
93
+ buffer_t *buffer;
94
+ int index = NUM2INT(ruby_index);
95
+
96
+ TypedData_Get_Struct(self, buffer_t, &buffer_data_type, buffer);
97
+ if (index >= 0 && index < buffer->length) {
98
+ return buffer->frames[index];
99
+ }
100
+ return Qnil;
101
+ }
102
+
103
+ static VALUE buffer_each(VALUE self) {
104
+ buffer_t *buffer;
105
+
106
+ TypedData_Get_Struct(self, buffer_t, &buffer_data_type, buffer);
107
+ for (int i = 0; i < buffer->length; i++) {
108
+ rb_yield(buffer->frames[i]);
109
+ }
110
+ return Qnil;
111
+ }
112
+
113
+ static VALUE buffer_find(VALUE self) {
114
+ buffer_t *buffer;
115
+
116
+ TypedData_Get_Struct(self, buffer_t, &buffer_data_type, buffer);
117
+ for (int i = 0; i < buffer->length; i++) {
118
+ VALUE frame = buffer->frames[i];
119
+ if (RTEST(rb_yield(frame))) {
120
+ return frame;
121
+ }
122
+ }
123
+ return Qnil;
124
+ }
125
+
126
+ VALUE stack_buffer_profile_frame(VALUE buffer_obj, int index) {
127
+ buffer_t *buffer;
128
+ TypedData_Get_Struct(buffer_obj, buffer_t, &buffer_data_type, buffer);
129
+ return buffer->profile_frames[index];
130
+ }
131
+
132
+ int stack_buffer_frame_lineno(VALUE buffer_obj, int index) {
133
+ buffer_t *buffer;
134
+ TypedData_Get_Struct(buffer_obj, buffer_t, &buffer_data_type, buffer);
135
+ return buffer->lines[index];
136
+ }
137
+
138
+ void stack_buffer_define(VALUE mStackFrames) {
139
+ VALUE cBuffer = rb_define_class_under(mStackFrames, "Buffer", rb_cObject);
140
+ rb_define_alloc_func(cBuffer, buffer_allocate);
141
+ rb_define_method(cBuffer, "initialize", buffer_initialize, 1);
142
+ rb_define_method(cBuffer, "length", buffer_length, 0);
143
+ rb_define_method(cBuffer, "capacity", buffer_capacity, 0);
144
+ rb_define_method(cBuffer, "capture", buffer_capture, 0);
145
+ rb_define_method(cBuffer, "[]", buffer_aref, 1);
146
+ rb_define_method(cBuffer, "each", buffer_each, 0);
147
+ rb_define_method(cBuffer, "find", buffer_find, 0);
148
+ }
@@ -0,0 +1,5 @@
1
+ #include "deps.h"
2
+
3
+ VALUE stack_buffer_profile_frame(VALUE buffer, int index);
4
+ int stack_buffer_frame_lineno(VALUE buffer, int index);
5
+ void stack_buffer_define(VALUE mStackFrames);
@@ -0,0 +1,2 @@
1
+ #include "ruby.h"
2
+ #include "ruby/debug.h"
@@ -0,0 +1,4 @@
1
+ require 'mkmf'
2
+ $CFLAGS << ' -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers'
3
+ $CFLAGS << ' -Werror' if ENV['STACK_FRAMES_DEV']
4
+ create_makefile("stack_frames/stack_frames")
@@ -0,0 +1,87 @@
1
+ #include "frame.h"
2
+ #include "buffer.h"
3
+
4
+ typedef struct {
5
+ VALUE buffer;
6
+ int index;
7
+ } frame_t;
8
+
9
+ VALUE cFrame;
10
+
11
+ static void frame_mark(void *ptr)
12
+ {
13
+ frame_t *frame = ptr;
14
+ rb_gc_mark(frame->buffer);
15
+ }
16
+
17
+ static void frame_free(void *ptr)
18
+ {
19
+ }
20
+
21
+ static size_t frame_memsize(const void *ptr)
22
+ {
23
+ return sizeof(frame_t);
24
+ }
25
+
26
+ const rb_data_type_t frame_data_type = {
27
+ "stack_frames_frame",
28
+ { frame_mark, frame_free, frame_memsize, },
29
+ NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
30
+ };
31
+
32
+ VALUE stack_frame_new(VALUE frame_buffer, int index) {
33
+ frame_t *frame;
34
+ VALUE obj = TypedData_Make_Struct(cFrame, frame_t, &frame_data_type, frame);
35
+ frame->buffer = frame_buffer;
36
+ frame->index = index;
37
+ return obj;
38
+ }
39
+
40
+ static VALUE frame_allocate(VALUE klass) {
41
+ rb_raise(rb_eRuntimeError, "frames cannot be allocated manually");
42
+ return Qnil;
43
+ }
44
+
45
+ static VALUE frame_profile_frame(VALUE self) {
46
+ frame_t *frame;
47
+ TypedData_Get_Struct(self, frame_t, &frame_data_type, frame);
48
+ return stack_buffer_profile_frame(frame->buffer, frame->index);
49
+ }
50
+
51
+ static VALUE frame_lineno(VALUE self) {
52
+ frame_t *frame;
53
+ TypedData_Get_Struct(self, frame_t, &frame_data_type, frame);
54
+ return INT2NUM(stack_buffer_frame_lineno(frame->buffer, frame->index));
55
+ }
56
+
57
+ #define DEFINE_FRAME_ACCESSOR(func_name) \
58
+ static VALUE frame_##func_name(VALUE self) { \
59
+ return rb_profile_frame_##func_name(frame_profile_frame(self)); \
60
+ }
61
+
62
+ DEFINE_FRAME_ACCESSOR(path)
63
+ DEFINE_FRAME_ACCESSOR(absolute_path)
64
+ DEFINE_FRAME_ACCESSOR(label)
65
+ DEFINE_FRAME_ACCESSOR(base_label)
66
+ DEFINE_FRAME_ACCESSOR(full_label)
67
+ DEFINE_FRAME_ACCESSOR(first_lineno)
68
+ DEFINE_FRAME_ACCESSOR(classpath)
69
+ DEFINE_FRAME_ACCESSOR(singleton_method_p)
70
+ DEFINE_FRAME_ACCESSOR(method_name)
71
+ DEFINE_FRAME_ACCESSOR(qualified_method_name)
72
+
73
+ void stack_frame_define(VALUE mStackFrames) {
74
+ cFrame = rb_define_class_under(mStackFrames, "Frame", rb_cObject);
75
+ rb_define_alloc_func(cFrame, frame_allocate);
76
+ rb_define_method(cFrame, "lineno", frame_lineno, 0);
77
+ rb_define_method(cFrame, "path", frame_path, 0);
78
+ rb_define_method(cFrame, "absolute_path", frame_absolute_path, 0);
79
+ rb_define_method(cFrame, "label", frame_label, 0);
80
+ rb_define_method(cFrame, "base_label", frame_base_label, 0);
81
+ rb_define_method(cFrame, "full_label", frame_full_label, 0);
82
+ rb_define_method(cFrame, "first_lineno", frame_first_lineno, 0);
83
+ rb_define_method(cFrame, "classpath", frame_classpath, 0);
84
+ rb_define_method(cFrame, "singleton_method?", frame_singleton_method_p, 0);
85
+ rb_define_method(cFrame, "method_name", frame_method_name, 0);
86
+ rb_define_method(cFrame, "qualified_method_name", frame_qualified_method_name, 0);
87
+ }
@@ -0,0 +1,4 @@
1
+ #include "deps.h"
2
+
3
+ VALUE stack_frame_new(VALUE frame_buffer, int index);
4
+ void stack_frame_define(VALUE mStackFrames);
@@ -0,0 +1,11 @@
1
+ #include "deps.h"
2
+ #include "frame.h"
3
+ #include "buffer.h"
4
+
5
+ VALUE mStackFrames;
6
+
7
+ void Init_stack_frames() {
8
+ mStackFrames = rb_define_module("StackFrames");
9
+ stack_buffer_define(mStackFrames);
10
+ stack_frame_define(mStackFrames);
11
+ }
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'stack_frames/version'
4
+ require 'stack_frames/stack_frames'
5
+
6
+ StackFrames::Frame.singleton_class.class_eval do
7
+ private(:new)
8
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StackFrames
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("../lib", __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "stack_frames/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "stack_frames"
9
+ spec.version = StackFrames::VERSION
10
+ spec.authors = ["Dylan Thacker-Smith"]
11
+ spec.email = ["gems@shopify.com"]
12
+
13
+ spec.summary = "Zero allocation backtraces using MRI's profile frames API"
14
+ spec.homepage = "https://github.com/Shopify/stack_frames"
15
+ spec.license = "MIT"
16
+
17
+ spec.extensions = ['ext/stack_frames/extconf.rb']
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(__dir__) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^test/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_development_dependency "bundler"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency 'rake-compiler', '~> 1.0'
30
+ spec.add_development_dependency "minitest", "~> 5.0"
31
+ spec.add_development_dependency "stackprof", "~> 0.2.13"
32
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stack_frames
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dylan Thacker-Smith
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-02-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
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
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake-compiler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: stackprof
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.2.13
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.2.13
83
+ description:
84
+ email:
85
+ - gems@shopify.com
86
+ executables: []
87
+ extensions:
88
+ - ext/stack_frames/extconf.rb
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".github/probots.yml"
92
+ - ".gitignore"
93
+ - ".travis.yml"
94
+ - CODE_OF_CONDUCT.md
95
+ - CONTRIBUTING.md
96
+ - Gemfile
97
+ - LICENSE.txt
98
+ - README.md
99
+ - Rakefile
100
+ - benchmark.rb
101
+ - bin/console
102
+ - bin/setup
103
+ - example.rb
104
+ - ext/stack_frames/buffer.c
105
+ - ext/stack_frames/buffer.h
106
+ - ext/stack_frames/deps.h
107
+ - ext/stack_frames/extconf.rb
108
+ - ext/stack_frames/frame.c
109
+ - ext/stack_frames/frame.h
110
+ - ext/stack_frames/stack_frames.c
111
+ - lib/stack_frames.rb
112
+ - lib/stack_frames/version.rb
113
+ - stack_frames.gemspec
114
+ homepage: https://github.com/Shopify/stack_frames
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubygems_version: 3.0.3
134
+ signing_key:
135
+ specification_version: 4
136
+ summary: Zero allocation backtraces using MRI's profile frames API
137
+ test_files: []