From 95e8bdaa25c9bf840c41995aac3fb141468a72b3 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sun, 12 Jul 2020 09:42:08 -0700 Subject: threads: introduce and use rmdThreadsSetName() Now users can easily differentiate which rmd subtasks are busy by using top-like tools in show-threads mode. Also aids in troubleshooting... --- src/rmd_cache_audio.c | 3 +++ src/rmd_cache_frame.c | 3 +++ src/rmd_encode_image_buffer.c | 3 +++ src/rmd_encode_sound_buffer.c | 3 +++ src/rmd_flush_to_ogg.c | 3 +++ src/rmd_get_frame.c | 3 +++ src/rmd_load_cache.c | 3 +++ src/rmd_threads.c | 5 +++++ src/rmd_threads.h | 1 + 9 files changed, 27 insertions(+) diff --git a/src/rmd_cache_audio.c b/src/rmd_cache_audio.c index fabcb39..8becef4 100644 --- a/src/rmd_cache_audio.c +++ b/src/rmd_cache_audio.c @@ -28,6 +28,7 @@ #include "rmd_cache_audio.h" #include "rmd_jack.h" +#include "rmd_threads.h" #include "rmd_types.h" #include @@ -50,6 +51,8 @@ void *rmdCacheSoundBuffer(ProgData *pdata) { } #endif + rmdThreadsSetName("rmdCacheSounds"); + //We are simply going to throw sound on the disk. //It's sound is tiny compared to that of image, so //compressing would reducethe overall size by only an diff --git a/src/rmd_cache_frame.c b/src/rmd_cache_frame.c index 7b8a2f3..c2e37bf 100644 --- a/src/rmd_cache_frame.c +++ b/src/rmd_cache_frame.c @@ -29,6 +29,7 @@ #include "rmd_yuv_utils.h" #include "rmd_cache.h" +#include "rmd_threads.h" #include "rmd_types.h" #include @@ -106,6 +107,8 @@ void *rmdCacheImageBuffer(ProgData *pdata) { unsigned long long int total_received_bytes = 0; unsigned int capture_frameno = 0; + rmdThreadsSetName("rmdCacheImages"); + if (!pdata->args.zerocompression) { fp = pdata->cache_data->ifp; diff --git a/src/rmd_encode_image_buffer.c b/src/rmd_encode_image_buffer.c index c234aa4..f5e8b36 100644 --- a/src/rmd_encode_image_buffer.c +++ b/src/rmd_encode_image_buffer.c @@ -27,6 +27,7 @@ #include "config.h" #include "rmd_encode_image_buffer.h" +#include "rmd_threads.h" #include "rmd_types.h" #include @@ -35,6 +36,8 @@ void *rmdEncodeImageBuffer(ProgData *pdata) { unsigned int encode_frameno = 0; + rmdThreadsSetName("rmdEncodeImages"); + pdata->th_encoding_clean = 0; while (pdata->running) { diff --git a/src/rmd_encode_sound_buffer.c b/src/rmd_encode_sound_buffer.c index 5fa1dc6..b3f8781 100644 --- a/src/rmd_encode_sound_buffer.c +++ b/src/rmd_encode_sound_buffer.c @@ -28,6 +28,7 @@ #include "rmd_encode_sound_buffer.h" #include "rmd_jack.h" +#include "rmd_threads.h" #include "rmd_types.h" #include @@ -45,6 +46,8 @@ void *rmdEncodeSoundBuffer(ProgData *pdata) { jackbuf = malloc(pdata->sound_framesize * pdata->jdata->buffersize); #endif + rmdThreadsSetName("rmdEncodeSounds"); + pdata->v_encoding_clean = 0; while (pdata->running) { float **vorbis_buffer; diff --git a/src/rmd_flush_to_ogg.c b/src/rmd_flush_to_ogg.c index 87308a6..d2e7f44 100644 --- a/src/rmd_flush_to_ogg.c +++ b/src/rmd_flush_to_ogg.c @@ -29,6 +29,7 @@ #include "rmd_encode_image_buffer.h" #include "rmd_encode_sound_buffer.h" +#include "rmd_threads.h" #include "rmd_types.h" #include @@ -75,6 +76,8 @@ void *rmdFlushToOgg(ProgData *pdata) { int th_st_fin = 0, v_st_fin = (pdata->args.nosound); + rmdThreadsSetName("rmdFlushToOgg"); + while (!(th_st_fin && v_st_fin)) { int audio_or_video = 0; diff --git a/src/rmd_get_frame.c b/src/rmd_get_frame.c index a9e4daa..8d8b8d8 100644 --- a/src/rmd_get_frame.c +++ b/src/rmd_get_frame.c @@ -32,6 +32,7 @@ #include "rmd_getzpixmap.h" #include "rmd_poll_events.h" #include "rmd_rectinsert.h" +#include "rmd_threads.h" #include "rmd_update_image.h" #include "rmd_yuv_utils.h" #include "rmd_types.h" @@ -268,6 +269,8 @@ void *rmdGetFrame(ProgData *pdata) { //the current full screenshot int init_img1 = 0, init_img2 = 0, img_sel, d_buff; + rmdThreadsSetName("rmdGetFrame"); + img_sel = d_buff = pdata->args.full_shots; if ((init_img1 = rmdFirstFrame(pdata, &image) != 0)) { diff --git a/src/rmd_load_cache.c b/src/rmd_load_cache.c index 8ca37f6..417b3dc 100644 --- a/src/rmd_load_cache.c +++ b/src/rmd_load_cache.c @@ -31,6 +31,7 @@ #include "rmd_encode_image_buffer.h" #include "rmd_encode_sound_buffer.h" #include "rmd_macro.h" +#include "rmd_threads.h" #include "rmd_types.h" #include @@ -184,6 +185,8 @@ void *rmdLoadCache(ProgData *pdata) { UBlocks[(yuv->uv_width * yuv->uv_height) / UV_UNIT_BYTES], VBlocks[(yuv->uv_width * yuv->uv_height) / UV_UNIT_BYTES]; + rmdThreadsSetName("rmdEncodeCache"); + // We allocate the frame that we will use frame.header = &fheader; frame.YBlocks = YBlocks; diff --git a/src/rmd_threads.c b/src/rmd_threads.c index cb81f84..69b98bf 100644 --- a/src/rmd_threads.c +++ b/src/rmd_threads.c @@ -43,6 +43,7 @@ #include #include +#include #include void rmdThreads(ProgData *pdata) { @@ -167,3 +168,7 @@ void rmdThreads(ProgData *pdata) { pdata->timer_alive = 0; pthread_join(timer_t,NULL); } + +void rmdThreadsSetName(const char *name) { + prctl(PR_SET_NAME, (unsigned long)name, 0, 0, 0); +} diff --git a/src/rmd_threads.h b/src/rmd_threads.h index e2c103a..6ca2dbd 100644 --- a/src/rmd_threads.h +++ b/src/rmd_threads.h @@ -38,6 +38,7 @@ * \param pdata ProgData struct containing all program data */ void rmdThreads(ProgData *pdata); +void rmdThreadsSetName(const char *name); #endif -- cgit v1.2.1