From 1833f747a9008f38e5597622f2e3dbce3340e2cb Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Wed, 25 Jan 2017 19:18:49 +0100 Subject: [PATCH] Give all of our threads meaningful names, to aid with debugging. --- bmusb.cpp | 6 ++++++ bmusb/fake_capture.h | 1 + fake_capture.cpp | 7 ++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/bmusb.cpp b/bmusb.cpp index de895d9..0c3fb55 100644 --- a/bmusb.cpp +++ b/bmusb.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -289,6 +290,10 @@ void dump_audio_block(uint8_t *audio_start, size_t audio_len) void BMUSBCapture::dequeue_thread_func() { + char thread_name[16]; + snprintf(thread_name, sizeof(thread_name), "bmusb_dequeue_%d", card_index); + pthread_setname_np(pthread_self(), thread_name); + if (has_dequeue_callbacks) { dequeue_init_callback(); } @@ -886,6 +891,7 @@ void BMUSBCapture::usb_thread_func() if (sched_setscheduler(0, SCHED_RR, ¶m) == -1) { printf("couldn't set realtime priority for USB thread: %s\n", strerror(errno)); } + pthread_setname_np(pthread_self(), "bmusb_usb_drv"); while (!should_quit) { timeval sec { 1, 0 }; int rc = libusb_handle_events_timeout(nullptr, &sec); diff --git a/bmusb/fake_capture.h b/bmusb/fake_capture.h index ad432f7..06f7ef2 100644 --- a/bmusb/fake_capture.h +++ b/bmusb/fake_capture.h @@ -82,6 +82,7 @@ private: void make_tone(int32_t *out, unsigned num_stereo_samples, unsigned num_channels); unsigned width, height, fps, audio_sample_frequency; + int card_index; uint8_t y, cb, cr; // sin(2 * pi * f / F) and similar for cos. Used for fast sine generation. diff --git a/fake_capture.cpp b/fake_capture.cpp index fbcfedd..29b06b1 100644 --- a/fake_capture.cpp +++ b/fake_capture.cpp @@ -4,6 +4,7 @@ #include "bmusb/fake_capture.h" #include +#include #include #include #include @@ -89,7 +90,7 @@ void memset4(uint8_t *s, const uint8_t c[4], size_t n) } // namespace FakeCapture::FakeCapture(unsigned width, unsigned height, unsigned fps, unsigned audio_sample_frequency, int card_index, bool has_audio) - : width(width), height(height), fps(fps), audio_sample_frequency(audio_sample_frequency) + : width(width), height(height), fps(fps), audio_sample_frequency(audio_sample_frequency), card_index(card_index) { char buf[256]; snprintf(buf, sizeof(buf), "Fake card %d", card_index + 1); @@ -201,6 +202,10 @@ bool timespec_less_than(const timespec &a, const timespec &b) void FakeCapture::producer_thread_func() { + char thread_name[16]; + snprintf(thread_name, sizeof(thread_name), "FakeCapture_%d", card_index); + pthread_setname_np(pthread_self(), thread_name); + uint16_t timecode = 0; if (has_dequeue_callbacks) { -- 2.39.2