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 16157A0540; Tue, 13 Dec 2022 19:28:23 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 28A9F42D0D; Tue, 13 Dec 2022 19:27:59 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mails.dpdk.org (Postfix) with ESMTP id 72F0D42D1A for ; Tue, 13 Dec 2022 19:27:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1670956076; x=1702492076; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=e2RCpjZsgGM9gwmK1pqdksHY+tqQ59ObxdOiMS/LAEc=; b=Az4b+WDzEERwMdtgqgvp7RtEfhT0musyhtAYR9ILFxOJyZg4E/NC7+Ox T5LRNkQ64aBAEim4qDC0HCuUIWFLRE/Dwq/MdGOEQex1Qj10MlPOPJYoD +l6YZ9ZahZIfPck9fmiM76LUBB5DQ+IRX8zEWQ1Pefvp8jsRjF5UjqFE3 x8VTkJaTLQXH0akh1Wj8IEet0jng9BVj2HwkN9lRGYZDIXewPBULBr9mI Ucujb9zqjw3UWwqPBuxFgnZlVFW2NG6ual8dfzZ2U8lBEnm0gz0px4nBo 9PjskbYCQiYmGFT53U+2qfLFWZCiFO4bu3HuVrQD2RP//9BGgjA+1Knb4 A==; X-IronPort-AV: E=McAfee;i="6500,9779,10560"; a="382506993" X-IronPort-AV: E=Sophos;i="5.96,242,1665471600"; d="scan'208";a="382506993" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Dec 2022 10:27:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10560"; a="626445226" X-IronPort-AV: E=Sophos;i="5.96,242,1665471600"; d="scan'208";a="626445226" Received: from silpixa00401459.ir.intel.com (HELO silpixa00401459.ger.corp.intel.com) ([10.237.223.55]) by orsmga006.jf.intel.com with ESMTP; 13 Dec 2022 10:27:54 -0800 From: Bruce Richardson To: dev@dpdk.org Cc: Bruce Richardson , =?UTF-8?q?Morten=20Br=C3=B8rup?= Subject: [RFC PATCH 5/7] telemetry: update json functions to use int/uint in names Date: Tue, 13 Dec 2022 18:27:28 +0000 Message-Id: <20221213182730.97065-6-bruce.richardson@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221213182730.97065-1-bruce.richardson@intel.com> References: <20221213182730.97065-1-bruce.richardson@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Since we are standardizing on using uint in place of u64, and expanding the int values to 64-bit, we can update the internal json functions to use the new names and expanded signed type. Suggested-by: Morten Brørup Signed-off-by: Bruce Richardson --- app/test/test_telemetry_json.c | 9 ++++----- lib/telemetry/telemetry.c | 8 ++++---- lib/telemetry/telemetry_json.h | 16 ++++++++-------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/app/test/test_telemetry_json.c b/app/test/test_telemetry_json.c index 184c3ba9f1..e81e3a8a98 100644 --- a/app/test/test_telemetry_json.c +++ b/app/test/test_telemetry_json.c @@ -37,9 +37,9 @@ test_basic_obj(void) char buf[1024]; int used = 0; - used = rte_tel_json_add_obj_u64(buf, sizeof(buf), used, + used = rte_tel_json_add_obj_uint(buf, sizeof(buf), used, "weddings", 4); - used = rte_tel_json_add_obj_u64(buf, sizeof(buf), used, + used = rte_tel_json_add_obj_uint(buf, sizeof(buf), used, "funerals", 1); printf("%s: buf = '%s', expected = '%s'\n", __func__, buf, expected); @@ -80,8 +80,7 @@ test_overflow_obj(void) int i, used = 0; for (i = 0; i < (int)RTE_DIM(names); i++) - used = rte_tel_json_add_obj_u64(buf, sizeof(buf), used, - names[i], vals[i]); + used = rte_tel_json_add_obj_uint(buf, sizeof(buf), used, names[i], vals[i]); printf("%s: buf = '%s', expected = '%s'\n", __func__, buf, expected); if (buf[used - 1] != '}') @@ -117,7 +116,7 @@ test_large_obj_element(void) char buf[sizeof(str) - 5] = "XYZ"; int used = 0; - used = rte_tel_json_add_obj_u64(buf, sizeof(buf), used, str, 0); + used = rte_tel_json_add_obj_uint(buf, sizeof(buf), used, str, 0); printf("%s: buf = '%s', expected = '%s'\n", __func__, buf, expected); if (used != 0) return -1; diff --git a/lib/telemetry/telemetry.c b/lib/telemetry/telemetry.c index 89bdde8422..655191bcf1 100644 --- a/lib/telemetry/telemetry.c +++ b/lib/telemetry/telemetry.c @@ -174,7 +174,7 @@ container_to_json(const struct rte_tel_data *d, char *out_buf, size_t buf_len) used = rte_tel_json_empty_array(out_buf, buf_len, 0); if (d->type == TEL_ARRAY_UINT) for (i = 0; i < d->data_len; i++) - used = rte_tel_json_add_array_u64(out_buf, + used = rte_tel_json_add_array_uint(out_buf, buf_len, used, d->data.array[i].uval); if (d->type == TEL_ARRAY_INT) @@ -202,7 +202,7 @@ container_to_json(const struct rte_tel_data *d, char *out_buf, size_t buf_len) v->name, v->value.ival); break; case RTE_TEL_UINT_VAL: - used = rte_tel_json_add_obj_u64(out_buf, + used = rte_tel_json_add_obj_uint(out_buf, buf_len, used, v->name, v->value.uval); break; @@ -269,7 +269,7 @@ output_json(const char *cmd, const struct rte_tel_data *d, int s) v->name, v->value.ival); break; case RTE_TEL_UINT_VAL: - used = rte_tel_json_add_obj_u64(cb_data_buf, + used = rte_tel_json_add_obj_uint(cb_data_buf, buf_len, used, v->name, v->value.uval); break; @@ -307,7 +307,7 @@ output_json(const char *cmd, const struct rte_tel_data *d, int s) buf_len, used, d->data.array[i].ival); else if (d->type == TEL_ARRAY_UINT) - used = rte_tel_json_add_array_u64(cb_data_buf, + used = rte_tel_json_add_array_uint(cb_data_buf, buf_len, used, d->data.array[i].uval); else if (d->type == TEL_ARRAY_CONTAINER) { diff --git a/lib/telemetry/telemetry_json.h b/lib/telemetry/telemetry_json.h index e3fae7c30d..744bbfe053 100644 --- a/lib/telemetry/telemetry_json.h +++ b/lib/telemetry/telemetry_json.h @@ -136,19 +136,19 @@ rte_tel_json_add_array_string(char *buf, const int len, const int used, /* Appends an integer into the JSON array in the provided buffer. */ static inline int -rte_tel_json_add_array_int(char *buf, const int len, const int used, int val) +rte_tel_json_add_array_int(char *buf, const int len, const int used, int64_t val) { int ret, end = used - 1; /* strip off final delimiter */ if (used <= 2) /* assume empty, since minimum is '[]' */ - return __json_snprintf(buf, len, "[%d]", val); + return __json_snprintf(buf, len, "[%"PRId64"]", val); - ret = __json_snprintf(buf + end, len - end, ",%d]", val); + ret = __json_snprintf(buf + end, len - end, ",%"PRId64"]", val); return ret == 0 ? used : end + ret; } /* Appends a uint64_t into the JSON array in the provided buffer. */ static inline int -rte_tel_json_add_array_u64(char *buf, const int len, const int used, +rte_tel_json_add_array_uint(char *buf, const int len, const int used, uint64_t val) { int ret, end = used - 1; /* strip off final delimiter */ @@ -180,7 +180,7 @@ rte_tel_json_add_array_json(char *buf, const int len, const int used, * provided buffer. */ static inline int -rte_tel_json_add_obj_u64(char *buf, const int len, const int used, +rte_tel_json_add_obj_uint(char *buf, const int len, const int used, const char *name, uint64_t val) { int ret, end = used - 1; @@ -199,14 +199,14 @@ rte_tel_json_add_obj_u64(char *buf, const int len, const int used, */ static inline int rte_tel_json_add_obj_int(char *buf, const int len, const int used, - const char *name, int val) + const char *name, int64_t val) { int ret, end = used - 1; if (used <= 2) /* assume empty, since minimum is '{}' */ - return __json_snprintf(buf, len, "{\"%s\":%d}", name, + return __json_snprintf(buf, len, "{\"%s\":%"PRId64"}", name, val); - ret = __json_snprintf(buf + end, len - end, ",\"%s\":%d}", + ret = __json_snprintf(buf + end, len - end, ",\"%s\":%"PRId64"}", name, val); return ret == 0 ? used : end + ret; } -- 2.34.1