@@ -170,6 +170,38 @@ int
rte_tel_data_add_array_container(struct rte_tel_data *d,
struct rte_tel_data *val, int keep);
+/**
+ * Convert a uint32_t to hexadecimal encoded strings and add this string
+ * to an array.
+ * The array must have been started by rte_tel_data_start_array() with
+ * RTE_TEL_STRING_VAL as the type parameter.
+ *
+ * @param d
+ * The data structure passed to the callback
+ * @param x
+ * The number to be returned in the array as a hexadecimal encoded strings
+ * @return
+ * 0 on success, negative errno on error
+ */
+__rte_experimental
+int rte_tel_data_add_array_hex_u32_str(struct rte_tel_data *d, uint32_t x);
+
+/**
+ * Convert a uint64_t to hexadecimal encoded strings and add this string
+ * to an array.
+ * The array must have been started by rte_tel_data_start_array() with
+ * RTE_TEL_STRING_VAL as the type parameter.
+ *
+ * @param d
+ * The data structure passed to the callback
+ * @param x
+ * The number to be returned in the array as a hexadecimal encoded strings
+ * @return
+ * 0 on success, negative errno on error
+ */
+__rte_experimental
+int rte_tel_data_add_array_hex_u64_str(struct rte_tel_data *d, uint64_t x);
+
/**
* Add a string value to a dictionary.
* The dict must have been started by rte_tel_data_start_dict().
@@ -266,6 +298,46 @@ int
rte_tel_data_add_dict_container(struct rte_tel_data *d, const char *name,
struct rte_tel_data *val, int keep);
+/**
+ * Convert a uint32_t to hexadecimal encoded strings and add this string
+ * to a dictionary.
+ * The dict must have been started by rte_tel_data_start_dict().
+ *
+ * @param d
+ * The data structure passed to the callback
+ * @param name
+ * The name the value is to be stored under in the dict
+ * Must contain only alphanumeric characters or the symbols: '_' or '/'
+ * @param val
+ * The number to be stored in the dict as a hexadecimal encoded strings
+ * @return
+ * 0 on success, negative errno on error, E2BIG on string truncation of
+ * either name or value.
+ */
+__rte_experimental
+int rte_tel_data_add_dict_hex_u32_str(struct rte_tel_data *d,
+ const char *name, uint32_t val);
+
+/**
+ * Convert a uint64_t to hexadecimal encoded strings and add this string
+ * to a dictionary.
+ * The dict must have been started by rte_tel_data_start_dict().
+ *
+ * @param d
+ * The data structure passed to the callback
+ * @param name
+ * The name the value is to be stored under in the dict
+ * Must contain only alphanumeric characters or the symbols: '_' or '/'
+ * @param val
+ * The number to be stored in the dict as a hexadecimal encoded strings
+ * @return
+ * 0 on success, negative errno on error, E2BIG on string truncation of
+ * either name or value.
+ */
+__rte_experimental
+int rte_tel_data_add_dict_hex_u64_str(struct rte_tel_data *d,
+ const char *name, uint64_t val);
+
/**
* This telemetry callback is used when registering a telemetry command.
* It handles getting and formatting information to be returned to telemetry
@@ -4,6 +4,7 @@
#include <errno.h>
#include <stdlib.h>
+#include <inttypes.h>
#undef RTE_USE_LIBBSD
#include <stdbool.h>
@@ -12,6 +13,9 @@
#include "telemetry_data.h"
+/* The string length is equal to (sizeof(uint64_t) * 2 + 3) */
+#define RTE_TEL_HEX_UINT_MAX_STRING_LEN 19
+
int
rte_tel_data_start_array(struct rte_tel_data *d, enum rte_tel_value_type type)
{
@@ -126,6 +130,26 @@ rte_tel_data_add_array_container(struct rte_tel_data *d,
return 0;
}
+int
+rte_tel_data_add_array_hex_u32_str(struct rte_tel_data *d, uint32_t x)
+{
+ char hex_str[RTE_TEL_HEX_UINT_MAX_STRING_LEN];
+
+ snprintf(hex_str, RTE_TEL_HEX_UINT_MAX_STRING_LEN, "0x%x", x);
+
+ return rte_tel_data_add_array_string(d, hex_str);
+}
+
+int
+rte_tel_data_add_array_hex_u64_str(struct rte_tel_data *d, uint64_t x)
+{
+ char hex_str[RTE_TEL_HEX_UINT_MAX_STRING_LEN];
+
+ snprintf(hex_str, RTE_TEL_HEX_UINT_MAX_STRING_LEN, "0x%"PRIx64"", x);
+
+ return rte_tel_data_add_array_string(d, hex_str);
+}
+
static bool
valid_name(const char *name)
{
@@ -254,6 +278,28 @@ rte_tel_data_add_dict_container(struct rte_tel_data *d, const char *name,
return bytes < RTE_TEL_MAX_STRING_LEN ? 0 : E2BIG;
}
+int
+rte_tel_data_add_dict_hex_u32_str(struct rte_tel_data *d, const char *name,
+ uint32_t val)
+{
+ char hex_str[RTE_TEL_HEX_UINT_MAX_STRING_LEN];
+
+ snprintf(hex_str, RTE_TEL_HEX_UINT_MAX_STRING_LEN, "0x%x", val);
+
+ return rte_tel_data_add_dict_string(d, name, hex_str);
+}
+
+int
+rte_tel_data_add_dict_hex_u64_str(struct rte_tel_data *d, const char *name,
+ uint64_t val)
+{
+ char hex_str[RTE_TEL_HEX_UINT_MAX_STRING_LEN];
+
+ snprintf(hex_str, RTE_TEL_HEX_UINT_MAX_STRING_LEN, "0x%"PRIx64"", val);
+
+ return rte_tel_data_add_dict_string(d, name, hex_str);
+}
+
struct rte_tel_data *
rte_tel_data_alloc(void)
{
@@ -3,6 +3,11 @@ EXPERIMENTAL {
rte_tel_data_add_array_u32;
rte_tel_data_add_dict_u32;
+ rte_tel_data_add_array_hex_u32_str;
+ rte_tel_data_add_array_hex_u64_str;
+ rte_tel_data_add_dict_hex_u32_str;
+ rte_tel_data_add_dict_hex_u64_str;
+
local: *;
};