diff options
author | Marek Olšák <[email protected]> | 2018-07-03 14:48:16 -0400 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2018-07-04 21:54:39 -0400 |
commit | b238e33bc9d48b814370da4a9e49c431981053cc (patch) | |
tree | a1d83d2b9499114e57e31b230ba10dad1caf490b /src | |
parent | 7149bffe669a5067bc332d017e8a501474333a7f (diff) |
kutil/queue: add a process name into a thread name
v2: simplifications
Reviewed-by: Timothy Arceri <[email protected]> (v1)
Reviewed-by: Eric Engestrom <[email protected]> (v1)
Diffstat (limited to 'src')
-rw-r--r-- | src/util/u_queue.c | 32 | ||||
-rw-r--r-- | src/util/u_queue.h | 2 |
2 files changed, 31 insertions, 3 deletions
diff --git a/src/util/u_queue.c b/src/util/u_queue.c index da513fd9cc5..72ce1fc00a6 100644 --- a/src/util/u_queue.c +++ b/src/util/u_queue.c @@ -31,6 +31,7 @@ #include "util/os_time.h" #include "util/u_string.h" #include "util/u_thread.h" +#include "process.h" static void util_queue_killall_and_wait(struct util_queue *queue); @@ -240,7 +241,8 @@ util_queue_thread_func(void *input) if (queue->name) { char name[16]; - util_snprintf(name, sizeof(name), "%s:%i", queue->name, thread_index); + util_snprintf(name, sizeof(name), "%s%i", queue->name, thread_index); + puts(name); u_thread_setname(name); } @@ -299,8 +301,34 @@ util_queue_init(struct util_queue *queue, { unsigned i; + /* Form the thread name from process_name and name, limited to 13 + * characters. Characters 14-15 are reserved for the thread number. + * Character 16 should be 0. Final form: "process:name12" + * + * If name is too long, it's truncated. If any space is left, the process + * name fills it. + */ + const char *process_name = util_get_process_name(); + int process_len = process_name ? strlen(process_name) : 0; + int name_len = strlen(name); + const int max_chars = sizeof(queue->name) - 1; + + name_len = MIN2(name_len, max_chars); + + /* See if there is any space left for the process name, reserve 1 for + * the colon. */ + process_len = MIN2(process_len, max_chars - name_len - 1); + process_len = MAX2(process_len, 0); + memset(queue, 0, sizeof(*queue)); - queue->name = name; + + if (process_len) { + snprintf(queue->name, sizeof(queue->name), "%.*s:%s", + process_len, process_name, name); + } else { + snprintf(queue->name, sizeof(queue->name), "%s", name); + } + queue->flags = flags; queue->num_threads = num_threads; queue->max_jobs = max_jobs; diff --git a/src/util/u_queue.h b/src/util/u_queue.h index d702c4bce8d..714d9243f00 100644 --- a/src/util/u_queue.h +++ b/src/util/u_queue.h @@ -199,7 +199,7 @@ struct util_queue_job { /* Put this into your context. */ struct util_queue { - const char *name; + char name[14]; /* 13 characters = the thread name without the index */ mtx_t finish_lock; /* only for util_queue_finish */ mtx_t lock; cnd_t has_queued_cond; |