代码拉取完成,页面将自动刷新
同步操作将从 src-openEuler/dpdk 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
From c89a9af036a9063903537404d615bed04a700e5b Mon Sep 17 00:00:00 2001
From: Bruce Richardson <[email protected]>
Date: Fri, 21 Oct 2022 15:37:04 +0800
Subject: [PATCH 188/189] telemetry: eliminate duplicate code for json output
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
When preparing the json response to a telemetry socket query, the code
for prefixing the command name, and appending the file "}" on the end of
the response was duplicated for multiple reply types. Taking this code
out of the switch statement reduces the duplication and makes the code
more maintainable.
For completeness of testing, add in a test case to validate the "null"
response type - the only leg of the switch statement not already covered
by an existing test case in the telemetry_data tests.
Signed-off-by: Bruce Richardson <[email protected]>
Acked-by: Ciara Power <[email protected]>
Acked-by: Morten Brørup <[email protected]>
Acked-by: Chengwen Feng <[email protected]>
---
lib/telemetry/telemetry.c | 35 ++++++++++++-----------------------
1 file changed, 12 insertions(+), 23 deletions(-)
diff --git a/lib/telemetry/telemetry.c b/lib/telemetry/telemetry.c
index f0be50b2bf..25ab6ed877 100644
--- a/lib/telemetry/telemetry.c
+++ b/lib/telemetry/telemetry.c
@@ -235,27 +235,22 @@ output_json(const char *cmd, const struct rte_tel_data *d, int s)
RTE_BUILD_BUG_ON(sizeof(out_buf) < MAX_CMD_LEN +
RTE_TEL_MAX_SINGLE_STRING_LEN + 10);
+
+ prefix_used = snprintf(out_buf, sizeof(out_buf), "{\"%.*s\":",
+ MAX_CMD_LEN, cmd);
+ cb_data_buf = &out_buf[prefix_used];
+ buf_len = sizeof(out_buf) - prefix_used - 1; /* space for '}' */
+
switch (d->type) {
case RTE_TEL_NULL:
- used = snprintf(out_buf, sizeof(out_buf), "{\"%.*s\":null}",
- MAX_CMD_LEN, cmd ? cmd : "none");
+ used = strlcpy(cb_data_buf, "null", buf_len);
break;
- case RTE_TEL_STRING:
- prefix_used = snprintf(out_buf, sizeof(out_buf), "{\"%.*s\":",
- MAX_CMD_LEN, cmd);
- cb_data_buf = &out_buf[prefix_used];
- buf_len = sizeof(out_buf) - prefix_used - 1; /* space for '}' */
+ case RTE_TEL_STRING:
used = rte_tel_json_str(cb_data_buf, buf_len, 0, d->data.str);
- used += prefix_used;
- used += strlcat(out_buf + used, "}", sizeof(out_buf) - used);
break;
- case RTE_TEL_DICT:
- prefix_used = snprintf(out_buf, sizeof(out_buf), "{\"%.*s\":",
- MAX_CMD_LEN, cmd);
- cb_data_buf = &out_buf[prefix_used];
- buf_len = sizeof(out_buf) - prefix_used - 1; /* space for '}' */
+ case RTE_TEL_DICT:
used = rte_tel_json_empty_obj(cb_data_buf, buf_len, 0);
for (i = 0; i < d->data_len; i++) {
const struct tel_dict_entry *v = &d->data.dict[i];
@@ -291,18 +286,12 @@ output_json(const char *cmd, const struct rte_tel_data *d, int s)
}
}
}
- used += prefix_used;
- used += strlcat(out_buf + used, "}", sizeof(out_buf) - used);
break;
+
case RTE_TEL_ARRAY_STRING:
case RTE_TEL_ARRAY_INT:
case RTE_TEL_ARRAY_U64:
case RTE_TEL_ARRAY_CONTAINER:
- prefix_used = snprintf(out_buf, sizeof(out_buf), "{\"%.*s\":",
- MAX_CMD_LEN, cmd);
- cb_data_buf = &out_buf[prefix_used];
- buf_len = sizeof(out_buf) - prefix_used - 1; /* space for '}' */
-
used = rte_tel_json_empty_array(cb_data_buf, buf_len, 0);
for (i = 0; i < d->data_len; i++)
if (d->type == RTE_TEL_ARRAY_STRING)
@@ -330,10 +319,10 @@ output_json(const char *cmd, const struct rte_tel_data *d, int s)
if (!rec_data->keep)
rte_tel_data_free(rec_data->data);
}
- used += prefix_used;
- used += strlcat(out_buf + used, "}", sizeof(out_buf) - used);
break;
}
+ used += prefix_used;
+ used += strlcat(out_buf + used, "}", sizeof(out_buf) - used);
if (write(s, out_buf, used) < 0)
perror("Error writing to socket");
}
--
2.23.0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。