gvl-tracing 1.5.1 → 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/gvl_tracing_native_extension/gvl_tracing.c +22 -9
- data/lib/gvl_tracing/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f2845379f02ef9e8cd317a293b0c24c92dbd9aebad15ccb9b378ea1c41cf894
|
4
|
+
data.tar.gz: ce639fb1bffb10262e1dee5f5bf7a80f4425d9db7b690a494b6cefedae507265
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 <
|
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
|
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
|
-
|
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
|
-
|
354
|
+
all_seen_threads_mutex_lock();
|
342
355
|
rb_ary_push(all_seen_threads, thread);
|
343
|
-
|
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
|
-
|
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
|
-
|
414
|
+
all_seen_threads_mutex_unlock();
|
402
415
|
return Qtrue;
|
403
416
|
}
|
data/lib/gvl_tracing/version.rb
CHANGED
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.
|
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-
|
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.
|
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
|