From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D65ABA0C54; Fri, 3 Sep 2021 13:03:27 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4FD7940E2D; Fri, 3 Sep 2021 13:03:27 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mails.dpdk.org (Postfix) with ESMTP id EAD5540E25 for ; Fri, 3 Sep 2021 13:03:25 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10095"; a="219452269" X-IronPort-AV: E=Sophos;i="5.85,265,1624345200"; d="scan'208";a="219452269" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Sep 2021 04:03:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,265,1624345200"; d="scan'208";a="500305802" Received: from silpixa00400884.ir.intel.com ([10.243.22.82]) by fmsmga008.fm.intel.com with ESMTP; 03 Sep 2021 04:03:23 -0700 From: Radu Nicolau To: Ciara Power Cc: dev@dpdk.org, Radu Nicolau , Declan Doherty Date: Fri, 3 Sep 2021 11:57:25 +0100 Message-Id: <20210903105725.243477-1-radu.nicolau@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH] telemetry: add support for dicts of dicts X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add support for dicts of dicts to telemetry library. Signed-off-by: Declan Doherty Signed-off-by: Radu Nicolau --- lib/telemetry/telemetry.c | 43 +++++++++++++++++++++++++++++++--- lib/telemetry/telemetry_data.c | 2 +- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/lib/telemetry/telemetry.c b/lib/telemetry/telemetry.c index 8665db8d03..3f83476112 100644 --- a/lib/telemetry/telemetry.c +++ b/lib/telemetry/telemetry.c @@ -24,7 +24,7 @@ #include "telemetry_internal.h" #define MAX_CMD_LEN 56 -#define MAX_HELP_LEN 64 +#define MAX_HELP_LEN 128 #define MAX_OUTPUT_LEN (1024 * 16) #define MAX_CONNECTIONS 10 @@ -157,8 +157,8 @@ container_to_json(const struct rte_tel_data *d, char *out_buf, size_t buf_len) size_t used = 0; unsigned int i; - if (d->type != RTE_TEL_ARRAY_U64 && d->type != RTE_TEL_ARRAY_INT - && d->type != RTE_TEL_ARRAY_STRING) + if (d->type != RTE_TEL_DICT && d->type != RTE_TEL_ARRAY_U64 && + d->type != RTE_TEL_ARRAY_INT && d->type != RTE_TEL_ARRAY_STRING) return snprintf(out_buf, buf_len, "null"); used = rte_tel_json_empty_array(out_buf, buf_len, 0); @@ -177,6 +177,43 @@ container_to_json(const struct rte_tel_data *d, char *out_buf, size_t buf_len) used = rte_tel_json_add_array_string(out_buf, buf_len, used, d->data.array[i].sval); + if (d->type == RTE_TEL_DICT) + for (i = 0; i < d->data_len; i++) { + const struct tel_dict_entry *v = &d->data.dict[i]; + switch (v->type) { + case RTE_TEL_STRING_VAL: + used = rte_tel_json_add_obj_str(out_buf, + buf_len, used, + v->name, v->value.sval); + break; + case RTE_TEL_INT_VAL: + used = rte_tel_json_add_obj_int(out_buf, + buf_len, used, + v->name, v->value.ival); + break; + case RTE_TEL_U64_VAL: + used = rte_tel_json_add_obj_u64(out_buf, + buf_len, used, + v->name, v->value.u64val); + break; + case RTE_TEL_CONTAINER: + { + char temp[buf_len]; + const struct container *cont = + &v->value.container; + if (container_to_json(cont->data, + temp, buf_len) != 0) + used = rte_tel_json_add_obj_json( + out_buf, + buf_len, used, + v->name, temp); + if (!cont->keep) + rte_tel_data_free(cont->data); + break; + } + } + } + return used; } diff --git a/lib/telemetry/telemetry_data.c b/lib/telemetry/telemetry_data.c index 77b0fe09a5..54a7c79fff 100644 --- a/lib/telemetry/telemetry_data.c +++ b/lib/telemetry/telemetry_data.c @@ -153,7 +153,7 @@ rte_tel_data_add_dict_container(struct rte_tel_data *d, const char *name, { struct tel_dict_entry *e = &d->data.dict[d->data_len]; - if (d->type != RTE_TEL_DICT || (val->type != RTE_TEL_ARRAY_U64 + if ((d->type != RTE_TEL_DICT && val->type != RTE_TEL_ARRAY_U64 && val->type != RTE_TEL_ARRAY_INT && val->type != RTE_TEL_ARRAY_STRING)) return -EINVAL; -- 2.25.1