@@ -859,6 +859,7 @@ class Thread {
859
859
markers->record (Marker::Type::MARKER_GVL_THREAD_EXITED);
860
860
861
861
stopped_at = now;
862
+ capture_name ();
862
863
863
864
break ;
864
865
}
@@ -871,6 +872,13 @@ class Thread {
871
872
return state != State::STOPPED;
872
873
}
873
874
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
+
874
882
void mark () {
875
883
}
876
884
};
@@ -937,12 +945,8 @@ class ThreadTable {
937
945
thread.set_state (new_state);
938
946
939
947
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);
943
948
thread.pthread_id = pthread_self ();
944
949
thread.native_tid = get_native_thread_id ();
945
- thread.name = StringValueCStr (thread_str);
946
950
} else {
947
951
thread.pthread_id = 0 ;
948
952
thread.native_tid = 0 ;
@@ -1492,6 +1496,13 @@ class TimeCollector : public BaseCollector {
1492
1496
rb_remove_event_hook (internal_gc_event_cb);
1493
1497
rb_remove_event_hook (internal_thread_event_cb);
1494
1498
1499
+ // capture thread names
1500
+ for (auto & thread: this ->threads .list ) {
1501
+ if (thread.running ()) {
1502
+ thread.capture_name ();
1503
+ }
1504
+ }
1505
+
1495
1506
frame_list.finalize ();
1496
1507
1497
1508
VALUE result = build_collector_result ();
0 commit comments