Skip to content

Commit 8d58a16

Browse files
committed
Don't attempt to inspect thread from native code
1 parent 2d72492 commit 8d58a16

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

ext/vernier/vernier.cc

+15-4
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,7 @@ class Thread {
859859
markers->record(Marker::Type::MARKER_GVL_THREAD_EXITED);
860860

861861
stopped_at = now;
862+
capture_name();
862863

863864
break;
864865
}
@@ -871,6 +872,13 @@ class Thread {
871872
return state != State::STOPPED;
872873
}
873874

875+
void capture_name() {
876+
//char buf[128];
877+
//int rc = pthread_getname_np(pthread_id, buf, sizeof(buf));
878+
//if (rc == 0)
879+
// name = std::string(buf);
880+
}
881+
874882
void mark() {
875883
}
876884
};
@@ -937,12 +945,8 @@ class ThreadTable {
937945
thread.set_state(new_state);
938946

939947
if (thread.state == Thread::State::RUNNING) {
940-
// rb_inspect should be safe here, as RUNNING should correspond to RESUMED hook from internal_thread_event_cb
941-
// which is called with GVL per https://github.com/ruby/ruby/blob/v3_3_0/include/ruby/thread.h#L247-L248
942-
VALUE thread_str = rb_inspect(th);
943948
thread.pthread_id = pthread_self();
944949
thread.native_tid = get_native_thread_id();
945-
thread.name = StringValueCStr(thread_str);
946950
} else {
947951
thread.pthread_id = 0;
948952
thread.native_tid = 0;
@@ -1492,6 +1496,13 @@ class TimeCollector : public BaseCollector {
14921496
rb_remove_event_hook(internal_gc_event_cb);
14931497
rb_remove_event_hook(internal_thread_event_cb);
14941498

1499+
// capture thread names
1500+
for (auto& thread: this->threads.list) {
1501+
if (thread.running()) {
1502+
thread.capture_name();
1503+
}
1504+
}
1505+
14951506
frame_list.finalize();
14961507

14971508
VALUE result = build_collector_result();

0 commit comments

Comments
 (0)