gvl-tracing 1.5.1 → 1.5.2

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: 47df73ea238560430f56d7b1ee2f0484e9e57b8f0784e065209cd5cfbe7b1084
4
- data.tar.gz: 1517522202fd357b31db4a087f769991ccf9f0a0c56b38191f64976827b3e752
3
+ metadata.gz: 4f2845379f02ef9e8cd317a293b0c24c92dbd9aebad15ccb9b378ea1c41cf894
4
+ data.tar.gz: ce639fb1bffb10262e1dee5f5bf7a80f4425d9db7b690a494b6cefedae507265
5
5
  SHA512:
6
- metadata.gz: ed938fa078cb982b23efe5da8a1a0fcb6d367534e7eeb342b2ce4853bf82cb7f0bb7998fd1a0bfa3bc3fd61a9f5d049717e245235dcf3df5a072be0b54eb9c2b
7
- data.tar.gz: c1f2db9dbde2a28321deee3b4186c08eb06f3da1f231f652d1822692e67e479e7be3a7b22daada77bc8130e9d6e016027b8470f9c84eceb827f4e06a17ac6d12
6
+ metadata.gz: '01659c02734923610f4c771afcd1a863de369781a7c21cf42c46e5d956f897c65643f0ae6a5a1eebb7fcb81895556271f57f7e164b3ac3581177509d31381db7'
7
+ data.tar.gz: f0e0894e7d3dcc5c7f00485b8e741be31f832142ef0436524f26e5996da9f901dc17b46080b26f2ecf5bcfc0ca37b6bdaae48b014eaeb00518dfa56b6c892167
@@ -31,7 +31,7 @@
31
31
  #include <inttypes.h>
32
32
  #include <stdbool.h>
33
33
  #include <sys/types.h>
34
- #include <threads.h>
34
+ #include <pthread.h>
35
35
 
36
36
  #include "extconf.h"
37
37
 
@@ -77,7 +77,7 @@ static VALUE gc_tracepoint = Qnil;
77
77
  #pragma GCC diagnostic ignored "-Wunused-variable"
78
78
  static int thread_storage_key = 0;
79
79
  static VALUE all_seen_threads = Qnil;
80
- static mtx_t all_seen_threads_mutex;
80
+ static pthread_mutex_t all_seen_threads_mutex = PTHREAD_MUTEX_INITIALIZER;
81
81
 
82
82
  static VALUE tracing_init_local_storage(VALUE, VALUE);
83
83
  static VALUE tracing_start(VALUE _self, VALUE output_path);
@@ -128,8 +128,6 @@ void Init_gvl_tracing_native_extension(void) {
128
128
 
129
129
  all_seen_threads = rb_ary_new();
130
130
 
131
- if (mtx_init(&all_seen_threads_mutex, mtx_plain) != thrd_success) rb_raise(rb_eRuntimeError, "Failed to initialize GvlTracing mutex");
132
-
133
131
  VALUE gvl_tracing_module = rb_define_module("GvlTracing");
134
132
 
135
133
  rb_define_singleton_method(gvl_tracing_module, "_init_local_storage", tracing_init_local_storage, 1);
@@ -148,7 +146,12 @@ static inline void initialize_thread_local_state(thread_local_state *state) {
148
146
  uint32_t native_thread_id = 0;
149
147
 
150
148
  #ifdef HAVE_PTHREAD_THREADID_NP
151
- pthread_threadid_np(pthread_self(), &native_thread_id);
149
+ uint64_t full_native_thread_id;
150
+ pthread_threadid_np(pthread_self(), &full_native_thread_id);
151
+ // Note: `pthread_threadid_np` is declared as taking in a `uint64_t` but I don't think macOS uses such really
152
+ // high thread ids, and anyway perfetto doesn't like full 64-bit ids for threads so let's go with a simplification
153
+ // for now.
154
+ native_thread_id = (uint32_t) full_native_thread_id;
152
155
  #elif HAVE_GETTID
153
156
  native_thread_id = gettid();
154
157
  #else
@@ -324,6 +327,16 @@ static void thread_local_state_mark(void *data) {
324
327
  rb_gc_mark(state->thread); // Marking thread to make sure it stays pinned
325
328
  }
326
329
 
330
+ static inline void all_seen_threads_mutex_lock(void) {
331
+ int error = pthread_mutex_lock(&all_seen_threads_mutex);
332
+ if (error) rb_syserr_fail(error, "Failed to lock GvlTracing mutex");
333
+ }
334
+
335
+ static inline void all_seen_threads_mutex_unlock(void) {
336
+ int error = pthread_mutex_unlock(&all_seen_threads_mutex);
337
+ if (error) rb_syserr_fail(error, "Failed to unlock GvlTracing mutex");
338
+ }
339
+
327
340
  #ifdef RUBY_3_3_PLUS
328
341
  static inline thread_local_state *GT_LOCAL_STATE(VALUE thread, bool allocate) {
329
342
  thread_local_state *state = rb_internal_thread_specific_get(thread, thread_storage_key);
@@ -338,9 +351,9 @@ static void thread_local_state_mark(void *data) {
338
351
  // Keep thread around, to be able to extract names at the end
339
352
  // We grab a lock here since thread creation can happen in multiple Ractors, and we want to make sure only one
340
353
  // of them is mutating the array at a time. @ivoanjo: I think this is enough to make this safe....?
341
- if (mtx_lock(&all_seen_threads_mutex) != thrd_success) rb_raise(rb_eRuntimeError, "Failed to lock GvlTracing mutex");
354
+ all_seen_threads_mutex_lock();
342
355
  rb_ary_push(all_seen_threads, thread);
343
- if (mtx_unlock(&all_seen_threads_mutex) != thrd_success) rb_raise(rb_eRuntimeError, "Failed to unlock GvlTracing mutex");
356
+ all_seen_threads_mutex_unlock();
344
357
  }
345
358
  return state;
346
359
  }
@@ -385,7 +398,7 @@ static VALUE ruby_thread_id_for(UNUSED_ARG VALUE _self, VALUE thread) {
385
398
 
386
399
  // Can only be called while GvlTracing is not active + while holding the GVL
387
400
  static VALUE trim_all_seen_threads(UNUSED_ARG VALUE _self) {
388
- if (mtx_lock(&all_seen_threads_mutex) != thrd_success) rb_raise(rb_eRuntimeError, "Failed to lock GvlTracing mutex");
401
+ all_seen_threads_mutex_lock();
389
402
 
390
403
  VALUE alive_threads = rb_ary_new();
391
404
 
@@ -398,6 +411,6 @@ static VALUE trim_all_seen_threads(UNUSED_ARG VALUE _self) {
398
411
 
399
412
  rb_ary_replace(all_seen_threads, alive_threads);
400
413
 
401
- if (mtx_unlock(&all_seen_threads_mutex) != thrd_success) rb_raise(rb_eRuntimeError, "Failed to unlock GvlTracing mutex");
414
+ all_seen_threads_mutex_unlock();
402
415
  return Qtrue;
403
416
  }
@@ -26,5 +26,5 @@
26
26
  # frozen_string_literal: true
27
27
 
28
28
  module GvlTracing
29
- VERSION = "1.5.1"
29
+ VERSION = "1.5.2"
30
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gvl-tracing
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivo Anjo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-29 00:00:00.000000000 Z
11
+ date: 2024-04-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -53,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  requirements: []
56
- rubygems_version: 3.4.10
56
+ rubygems_version: 3.5.3
57
57
  signing_key:
58
58
  specification_version: 4
59
59
  summary: Get a timeline view of Global VM Lock usage in your Ruby app