From 8fcaa80a91d70e26b749d1220bb1ec6d10c85cd6 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Sat, 9 Dec 2023 02:00:59 -0800 Subject: [PATCH] Call pthread_setname_np if available --- ext/vernier/extconf.rb | 2 ++ ext/vernier/vernier.cc | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/ext/vernier/extconf.rb b/ext/vernier/extconf.rb index 9d32315..0c6b93d 100644 --- a/ext/vernier/extconf.rb +++ b/ext/vernier/extconf.rb @@ -10,4 +10,6 @@ have_func("rb_profile_thread_frames", "ruby/debug.h") +have_func("pthread_setname_np") + create_makefile("vernier/vernier") diff --git a/ext/vernier/vernier.cc b/ext/vernier/vernier.cc index 9a399e2..c386425 100644 --- a/ext/vernier/vernier.cc +++ b/ext/vernier/vernier.cc @@ -1367,6 +1367,13 @@ class TimeCollector : public BaseCollector { } static void *sample_thread_entry(void *arg) { +#if HAVE_PTHREAD_SETNAME_NP +#ifdef __APPLE__ + pthread_setname_np("Vernier profiler"); +#else + pthread_setname_np(pthread_self(), "Vernier profiler"); +#endif +#endif TimeCollector *collector = static_cast(arg); collector->sample_thread_run(); return NULL;