Skip to content

Commit

Permalink
Call pthread_setname_np if available
Browse files Browse the repository at this point in the history
  • Loading branch information
jhawthorn committed Dec 9, 2023
1 parent 312072d commit 8fcaa80
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ext/vernier/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@

have_func("rb_profile_thread_frames", "ruby/debug.h")

have_func("pthread_setname_np")

create_makefile("vernier/vernier")
7 changes: 7 additions & 0 deletions ext/vernier/vernier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<TimeCollector *>(arg);
collector->sample_thread_run();
return NULL;
Expand Down

0 comments on commit 8fcaa80

Please sign in to comment.