diff mbox series

[FFmpeg-devel,2/4] lavc/pthread_frame: set worker thread names

Message ID 20221018165307.28242-2-anton@khirnov.net
State New
Headers show
Series [FFmpeg-devel,1/4] lavu/thread: add an internal function for setting thread name | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov Oct. 18, 2022, 4:53 p.m. UTC
---
 libavcodec/pthread_frame.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Henrik Gramner Oct. 18, 2022, 8:59 p.m. UTC | #1
On Tue, Oct 18, 2022 at 6:54 PM Anton Khirnov <anton@khirnov.net> wrote:
> +static void thread_set_name(PerThreadContext *p)
> +{
> +    AVCodecContext *avctx = p->avctx;
> +    int idx = p - p->parent->threads;
> +    char name[16];
> +
> +    snprintf(name, sizeof(name), "d:%.7s:ft%d", avctx->codec->name, idx);
> +
> +    ff_thread_setname(name);
> +}

How about having some kind of prefix to indicate that those are
libavcodec threads?

Could be helpful in a scenario where a process has threads spawned by
35 different libraries.
Rémi Denis-Courmont Oct. 19, 2022, 4:51 a.m. UTC | #2
Le 18 octobre 2022 23:59:21 GMT+03:00, Henrik Gramner <henrik@gramner.com> a écrit :
>On Tue, Oct 18, 2022 at 6:54 PM Anton Khirnov <anton@khirnov.net> wrote:
>> +static void thread_set_name(PerThreadContext *p)
>> +{
>> +    AVCodecContext *avctx = p->avctx;
>> +    int idx = p - p->parent->threads;
>> +    char name[16];
>> +
>> +    snprintf(name, sizeof(name), "d:%.7s:ft%d", avctx->codec->name, idx);
>> +
>> +    ff_thread_setname(name);
>> +}
>
>How about having some kind of prefix to indicate that those are
>libavcodec threads?
>
>Could be helpful in a scenario where a process has threads spawned by
>35 different libraries.
>_______________________________________________
>ffmpeg-devel mailing list
>ffmpeg-devel@ffmpeg.org
>https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>To unsubscribe, visit link above, or email
>ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>

There's only 15 characters maximum, so not much for a prefix . I guess that's why it's just d:...
diff mbox series

Patch

diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c
index f8fddc5e4d..7cd352160e 100644
--- a/libavcodec/pthread_frame.c
+++ b/libavcodec/pthread_frame.c
@@ -179,6 +179,17 @@  static void async_unlock(FrameThreadContext *fctx)
     pthread_mutex_unlock(&fctx->async_mutex);
 }
 
+static void thread_set_name(PerThreadContext *p)
+{
+    AVCodecContext *avctx = p->avctx;
+    int idx = p - p->parent->threads;
+    char name[16];
+
+    snprintf(name, sizeof(name), "d:%.7s:ft%d", avctx->codec->name, idx);
+
+    ff_thread_setname(name);
+}
+
 /**
  * Codec worker thread.
  *
@@ -192,6 +203,8 @@  static attribute_align_arg void *frame_worker_thread(void *arg)
     AVCodecContext *avctx = p->avctx;
     const FFCodec *codec = ffcodec(avctx->codec);
 
+    thread_set_name(p);
+
     pthread_mutex_lock(&p->mutex);
     while (1) {
         while (atomic_load(&p->state) == STATE_INPUT_READY && !p->die)