dev: strip debig log function name prefix during compilation 23/39823/2
authorDamjan Marion <damarion@cisco.com>
Thu, 2 Nov 2023 18:40:32 +0000 (18:40 +0000)
committerOle Tr�an <otroan@employees.org>
Fri, 3 Nov 2023 09:26:47 +0000 (09:26 +0000)
Type: improvement
Change-Id: I9b9bb37a0895366b412f042b0e2da5bbdd477325
Signed-off-by: Damjan Marion <damarion@cisco.com>
src/plugins/dev_iavf/format.c
src/plugins/dev_iavf/iavf.h
src/vnet/dev/dev.h
src/vnet/dev/format.c
src/vnet/dev/log.h
src/vppinfra/string.h

index bc84cc3..9a3dde4 100644 (file)
@@ -110,24 +110,3 @@ format_iavf_port_status (u8 *s, va_list *args)
     s = format (s, "disabled");
   return s;
 }
-
-u8 *
-format_iavf_log (u8 *s, va_list *args)
-{
-  vnet_dev_t *dev = va_arg (*args, vnet_dev_t *);
-  char *func = va_arg (*args, char *);
-
-  if (dev)
-    s = format (s, "%U", format_vnet_dev_addr, dev);
-  if (dev && func)
-    vec_add1 (s, ' ');
-  if (func)
-    {
-      if (strncmp (func, "iavf_", 5) == 0)
-       func += 5;
-      s = format (s, "%s", func);
-    }
-  vec_add1 (s, ':');
-  vec_add1 (s, ' ');
-  return s;
-}
index 7576fa9..958a8dc 100644 (file)
@@ -105,7 +105,6 @@ format_function_t format_virtchnl_status;
 format_function_t format_iavf_vf_cap_flags;
 format_function_t format_iavf_rx_trace;
 format_function_t format_iavf_port_status;
-format_function_t format_iavf_log;
 
 /* port.c */
 vnet_dev_rv_t iavf_port_init (vlib_main_t *, vnet_dev_port_t *);
@@ -157,8 +156,9 @@ iavf_reg_flush (iavf_device_t *ad)
 }
 
 #define log_debug(dev, f, ...)                                                \
-  vlib_log (VLIB_LOG_LEVEL_DEBUG, iavf_log.class, "%U" f, format_iavf_log,    \
-           (dev), __func__, ##__VA_ARGS__)
+  vlib_log (VLIB_LOG_LEVEL_DEBUG, iavf_log.class, "%U" f,                     \
+           format_vnet_dev_log, (dev),                                       \
+           clib_string_skip_prefix (__func__, "iavf_"), ##__VA_ARGS__)
 #define log_info(dev, f, ...)                                                 \
   vlib_log (VLIB_LOG_LEVEL_INFO, iavf_log.class, "%U: " f,                    \
            format_vnet_dev_addr, (dev), ##__VA_ARGS__)
index 5c80b98..9b54e73 100644 (file)
@@ -613,6 +613,7 @@ format_function_t format_vnet_dev_rx_queue_info;
 format_function_t format_vnet_dev_tx_queue_info;
 format_function_t format_vnet_dev_flags;
 format_function_t format_vnet_dev_port_flags;
+format_function_t format_vnet_dev_log;
 unformat_function_t unformat_vnet_dev_flags;
 unformat_function_t unformat_vnet_dev_port_flags;
 
index 4e1ece6..b8b7dbd 100644 (file)
@@ -394,11 +394,7 @@ format_vnet_dev_log (u8 *s, va_list *args)
   if (dev && func)
     vec_add1 (s, ' ');
   if (func)
-    {
-      if (strncmp (func, "vnet_dev_", 9) == 0)
-       func += 9;
-      s = format (s, "%s", func);
-    }
+    s = format (s, "%s", func);
   vec_add1 (s, ':');
   vec_add1 (s, ' ');
   return s;
index 432e7b8..5ca7b66 100644 (file)
@@ -5,11 +5,10 @@
 #ifndef _VNET_DEV_LOG_H_
 #define _VNET_DEV_LOG_H_
 
-format_function_t format_vnet_dev_log;
-
 #define log_debug(dev, f, ...)                                                \
   vlib_log (VLIB_LOG_LEVEL_DEBUG, dev_log.class, "%U" f, format_vnet_dev_log, \
-           dev, __func__, ##__VA_ARGS__)
+           dev, clib_string_skip_prefix (__func__, "vnet_dev_"),             \
+           ##__VA_ARGS__)
 #define log_notice(dev, f, ...)                                               \
   vlib_log (VLIB_LOG_LEVEL_NOTICE, dev_log.class, "%U" f,                     \
            format_vnet_dev_log, dev, 0, ##__VA_ARGS__)
index 38d3bab..b1ef0e4 100644 (file)
@@ -1161,6 +1161,13 @@ strstr_s_inline (char *s1, rsize_t s1max, const char *s2, rsize_t s2max,
   return EOK;
 }
 
+static_always_inline const char *
+clib_string_skip_prefix (const char *s, const char *prefix)
+{
+  uword len = __builtin_strlen (prefix);
+  return s + (__builtin_strncmp (s, prefix, len) ? 0 : len);
+}
+
 #endif /* included_clib_string_h */
 
 /*