stack_trace 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a44fbab04e5a7a787dd995fbee5ea3e503080172df937a91e122728eb4884744
4
- data.tar.gz: c004c70f42efc53e0776520d9e39a902346015eca012614913dd9a04e9822344
3
+ metadata.gz: 4cc75d5b0a32aff0307977f6f1acdeac454f9a082d09c4ccfb61423ed3539ebb
4
+ data.tar.gz: '0806e5e196396576aeeeb5c4c11f7cb4f20aac5064c765a59c8b8b5e07a4a13a'
5
5
  SHA512:
6
- metadata.gz: aab482726e6436266555c91fbd51a0b44d8b5d0b6b0f3e72cd11448eaac96ea0d49582df77ab828cbbd38be93d177214cddb50a606ad8e899bb541179c43ed0f
7
- data.tar.gz: 4e57a54efcb00a4a2701a5169130642be00fcd1aff13c4d508b0ac663f933fa5443eceffc78d74199d0fcf2ced21054559eabe85675ec2190b2f8ec768a02dc3
6
+ metadata.gz: a818593e2040840020a056673fb37a512c707ac9491334b776b9c1c8eea918136233d151982e0dbbd53f76b3ddf2141109c81fc693286ecd68654a33f7376ae7
7
+ data.tar.gz: 74116cca420c09db1fbf5c92c42e9536d32d64d22b42e1976e6c5ecff2f86ee562a797f81f7fa608eb44388c051496319c62a1a0dd084de4ceb9b1476bd3d910
data/Dockerfile ADDED
@@ -0,0 +1,17 @@
1
+ FROM ruby:3.0.6-alpine
2
+
3
+ RUN apk update
4
+ RUN apk add build-base git --virtual build-dependencies
5
+
6
+ RUN mkdir /stack_trace
7
+ WORKDIR /stack_trace
8
+
9
+ ENV BUNDLE_PATH=/bundle \
10
+ BUNDLE_BIN=/bundle/bin \
11
+ GEM_HOME=/bundle
12
+ ENV PATH="${BUNDLE_BIN}:${PATH}"
13
+
14
+ COPY . ./
15
+
16
+ RUN gem install bundler
17
+ RUN bundle install --jobs 20 --retry 5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stack_trace (0.6.0)
4
+ stack_trace (0.8.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -25,6 +25,7 @@ GEM
25
25
  rspec-support (3.12.0)
26
26
 
27
27
  PLATFORMS
28
+ aarch64-linux-musl
28
29
  arm64-darwin-21
29
30
 
30
31
  DEPENDENCIES
data/Makefile ADDED
@@ -0,0 +1,12 @@
1
+ usage:
2
+ @echo "Available targets:"
3
+ @echo " * build - Builds image"
4
+ @echo " * dev - Opens an ash session in the container"
5
+
6
+ .PHONY: build
7
+ build:
8
+ docker build . -t stack_trace
9
+
10
+ .PHONY: dev
11
+ dev:
12
+ docker run -it --rm -v $(PWD):/stack_trace stack_trace sh
data/README.md CHANGED
@@ -31,8 +31,13 @@ StackTrace.configure do |config|
31
31
  config.inspect_return_values = true # Default `false` for performance reasons
32
32
  config.inspect_arguments = true # Default `false` for performance reasons
33
33
 
34
- config.check_proc = -> (klass_name, method_name) do # If you want to limit the tracing for a set of classes
35
- klass_name == "Bar"
34
+ config.check_proc = -> (self_klass_name, defined_klass_name, method_name) do # If you want to limit the tracing for a set of classes
35
+ self_klass_name == "Bar"
36
+
37
+ # If you use autoload and resolve the constant by klass names
38
+ # it's really likelly that you get a segfault: https://bugs.ruby-lang.org/issues/18120.
39
+ # Preload all the constants before running the `StackTrace.trace` if you want to
40
+ # constantize klass names.
36
41
  end
37
42
  end
38
43
  ```
@@ -4,7 +4,7 @@ void free_arguments(Argument *arguments, int count) {
4
4
  int i;
5
5
 
6
6
  for(i = 0; i < count; i++) {
7
- free(arguments[i].value);
7
+ if(arguments[i].value != NULL) free(arguments[i].value);
8
8
  }
9
9
 
10
10
  free(arguments);
@@ -22,6 +22,14 @@ VALUE rb_create_trace(VALUE _self) {
22
22
  Span *span = malloc(sizeof(Span));
23
23
  span->children_count = 0;
24
24
  span->caller = NULL;
25
+ span->receiver = NULL;
26
+ span->klass = NULL;
27
+ span->self_klass = NULL;
28
+ span->return_value = NULL;
29
+ span->arguments = NULL;
30
+ span->arguments_count = 0;
31
+ span->exception = NULL;
32
+ span->children_count = 0;
25
33
 
26
34
  current_trace = malloc(sizeof(Trace));
27
35
  current_trace->finished = false;
@@ -14,16 +14,23 @@ struct MemoS {
14
14
  };
15
15
 
16
16
  static void copy_str(char **target, VALUE string) {
17
- *target = malloc(sizeof(char) * RSTRING_LEN(string) + 1);
17
+ const char *cstr = StringValueCStr(string);
18
+ size_t len = strlen(cstr);
18
19
 
19
- memcpy(*target, RSTRING_PTR(string), RSTRING_LEN(string));
20
+ *target = malloc(sizeof(char) * (len + 1));
21
+
22
+ memcpy(*target, cstr, (len + 1));
20
23
  }
21
24
 
22
25
  static int extract_kv(VALUE key, VALUE value, VALUE data) {
23
26
  struct MemoS *memo = (struct MemoS *)data;
24
27
 
25
28
  memo->arguments[memo->i].key = key;
26
- copy_str(&memo->arguments[memo->i].value, value);
29
+
30
+ VALUE value_klass = rb_obj_class(value);
31
+ VALUE value_st_name = st_name(value, value_klass);
32
+
33
+ if(value_st_name != Qundef) copy_str(&memo->arguments[memo->i].value, value_st_name);
27
34
 
28
35
  memo->i++;
29
36
 
@@ -107,9 +114,10 @@ void create_event(VALUE tp_val, void *_data) {
107
114
  if(RTEST(get_inspect_return_values()) &&
108
115
  (event.event == RUBY_EVENT_RETURN || event.event == RUBY_EVENT_C_RETURN || event.event == RUBY_EVENT_B_RETURN)) {
109
116
  VALUE return_value = rb_tracearg_return_value(trace_arg);
110
- VALUE return_value_st_name = rb_funcall(return_value, rb_intern("st_name"), 0);
117
+ VALUE return_value_class = rb_obj_class(return_value);
118
+ VALUE return_value_st_name = st_name(return_value, return_value_class);
111
119
 
112
- copy_str(&event.return_value, return_value_st_name);
120
+ if(return_value_st_name != Qundef) copy_str(&event.return_value, return_value_st_name);
113
121
  }
114
122
 
115
123
  produce_event(event);
@@ -38,8 +38,6 @@ static void wait_free_space() {
38
38
 
39
39
  static int wait_event() {
40
40
  if(free_space == SIZE) {
41
- rb_thread_check_ints(); // Otherwise the GC stucks!
42
-
43
41
  struct timespec ts;
44
42
  clock_gettime(CLOCK_REALTIME, &ts);
45
43
  ts.tv_nsec += TEN_MILLISECONDS;
@@ -80,7 +78,6 @@ static void event_consumed() {
80
78
  pthread_cond_signal(&has_space);
81
79
  }
82
80
 
83
- // Takes a callback function which populates the event information.
84
81
  void produce_event(Event event) {
85
82
  pthread_mutex_lock(&lock);
86
83
 
@@ -93,14 +90,15 @@ void produce_event(Event event) {
93
90
  pthread_mutex_unlock(&lock);
94
91
  }
95
92
 
96
- // Takes a callback function which consumes the event.
97
- void consume_event(void(*processor_func)(Event *event)) {
93
+ void get_event(Event *target, int *status) {
98
94
  pthread_mutex_lock(&lock);
95
+ *status = 1;
99
96
 
100
97
  Event *event = pull_event();
101
98
 
102
99
  if(event != NULL) {
103
- processor_func(event);
100
+ *status = 0;
101
+ memcpy(target, event, sizeof(Event));
104
102
 
105
103
  event_consumed();
106
104
  }
@@ -2,4 +2,4 @@
2
2
 
3
3
  void Init_event_store();
4
4
  void produce_event(Event event);
5
- void consume_event(void(*func)(Event *event));
5
+ void get_event(Event *target, int *status);
@@ -4,15 +4,22 @@
4
4
 
5
5
  #include "event_store.h"
6
6
  #include "trace.h"
7
+ #include "types/event.h"
7
8
 
8
9
  static bool running = false;
9
10
  static VALUE ractor;
10
11
 
11
12
  static VALUE listen_events(VALUE data, VALUE m, int _argc, const VALUE *_argv, VALUE _) {
12
13
  running = true;
14
+ Event event;
15
+ int status;
13
16
 
14
17
  while(running) {
15
- consume_event(&process_event);
18
+ get_event(&event, &status);
19
+
20
+ if(status == 0) process_event(&event);
21
+
22
+ rb_thread_check_ints();
16
23
  }
17
24
 
18
25
  return Qtrue;
@@ -92,7 +92,8 @@ VALUE serialize_arguments(Argument *arguments, int count) {
92
92
  int i;
93
93
 
94
94
  for(i = 0; i < count; i++) {
95
- rb_hash_aset(hash, arguments[i].key, rb_str_new_cstr(arguments[i].value));
95
+ if(arguments[i].value != NULL)
96
+ rb_hash_aset(hash, arguments[i].key, rb_str_new_cstr(arguments[i].value));
96
97
  }
97
98
 
98
99
  return hash;
@@ -32,7 +32,7 @@ void set_check_proc(VALUE proc) {
32
32
  static VALUE call_proc(VALUE val) {
33
33
  Event *event = (Event *)val;
34
34
 
35
- return rb_funcall(check_proc, rb_intern("call"), 2, rb_str_new_cstr(event->self_klass), event->method);
35
+ return rb_funcall(check_proc, rb_intern("call"), 3, rb_str_new_cstr(event->self_klass), rb_str_new_cstr(event->klass), event->method);
36
36
  }
37
37
 
38
38
  static bool is_tracked_event(Event *event) {
@@ -1,4 +1,7 @@
1
+ #define _POSIX_C_SOURCE 199309L
2
+
1
3
  #include <sys/time.h>
4
+ #include <time.h>
2
5
 
3
6
  long int get_monotonic_m_secs() {
4
7
  struct timespec at;
@@ -7,7 +7,7 @@ module StackTrace
7
7
  trace_point.parameters
8
8
  .map(&:last)
9
9
  .each_with_object({}) do |parameter, memo|
10
- memo[parameter] = extract_argument(trace_point, parameter).st_name
10
+ memo[parameter] = extract_argument(trace_point, parameter)
11
11
  end
12
12
  end
13
13
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StackTrace
4
- VERSION = "0.6.0"
4
+ VERSION = "0.8.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stack_trace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mehmet Emin INAC
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-09 00:00:00.000000000 Z
11
+ date: 2023-04-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: StackTrace
14
14
  email:
@@ -21,9 +21,11 @@ files:
21
21
  - ".rspec"
22
22
  - ".tool-versions"
23
23
  - CODE_OF_CONDUCT.md
24
+ - Dockerfile
24
25
  - Gemfile
25
26
  - Gemfile.lock
26
27
  - LICENSE.txt
28
+ - Makefile
27
29
  - README.md
28
30
  - Rakefile
29
31
  - ext/stack_trace/argument.c