From: Damjan Marion Date: Mon, 23 Nov 2020 15:50:24 +0000 (+0100) Subject: vlib: add format_vlib_thread_name X-Git-Tag: v21.06-rc0~137 X-Git-Url: https://gerrit.fd.io/r/gitweb?a=commitdiff_plain;h=2cdb301678b3ba26331a9bc63ca1ab7af131e281;p=vpp.git vlib: add format_vlib_thread_name Type: improvement Change-Id: I2231f8e32964868ff6ef154b8ef431d99643c6a5 Signed-off-by: Damjan Marion --- diff --git a/src/vlib/format.c b/src/vlib/format.c index ee730bd1c28..7de6417be69 100644 --- a/src/vlib/format.c +++ b/src/vlib/format.c @@ -210,6 +210,27 @@ unformat_vlib_tmpfile (unformat_input_t * input, va_list * args) return 1; } +u8 * +format_vlib_thread_name (u8 * s, va_list * args) +{ + u32 thread_index = va_arg (*args, u32); + + if (thread_index == 0) + return format (s, "main"); + + if (thread_index < vec_len (vlib_worker_threads)) + return format (s, "%s", vlib_worker_threads[thread_index].name); + return s; +} + +u8 * +format_vlib_thread_name_and_index (u8 * s, va_list * args) +{ + u32 thread_index = va_arg (*args, u32); + + return format (s, "%U (%u)", format_vlib_thread_name, thread_index, + thread_index); +} /* * fd.io coding-style-patch-verification: ON diff --git a/src/vlib/format_funcs.h b/src/vlib/format_funcs.h index 30e919d7e96..4e22625c9a9 100644 --- a/src/vlib/format_funcs.h +++ b/src/vlib/format_funcs.h @@ -47,6 +47,12 @@ u8 *format_vlib_read_write (u8 * s, va_list * args); /* Formats buffer data as printable ascii or as hex. */ u8 *format_vlib_buffer_data (u8 * s, va_list * args); +/* Formats thread name */ +u8 *format_vlib_thread_name (u8 * s, va_list * args); + +/* Formats thread name and thread index */ +u8 *format_vlib_thread_name_and_index (u8 * s, va_list * args); + /* Enable/on => 1; disable/off => 0. */ uword unformat_vlib_enable_disable (unformat_input_t * input, va_list * args);