diff options
| author | songyanchao <[email protected]> | 2023-12-05 10:15:48 +0000 |
|---|---|---|
| committer | songyanchao <[email protected]> | 2023-12-05 10:15:48 +0000 |
| commit | ec675d14711232e2ca3ddbc07b2d6f7209ea93c8 (patch) | |
| tree | 8e0e7a9a0de5ee79bb9c01605b11398fbbada525 | |
| parent | bafd3791592b14e635bb8e770d617b5b8fe7a2e0 (diff) | |
🎈 perf: Improve the display format of the 'packet comments' field in pcapng files.
Improve the display format of the 'packet comments' field in pcapng files.
| -rw-r--r-- | tools/tcpdump/pdump.c | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/tools/tcpdump/pdump.c b/tools/tcpdump/pdump.c index bb3a2a5..deeb3be 100644 --- a/tools/tcpdump/pdump.c +++ b/tools/tcpdump/pdump.c @@ -561,8 +561,10 @@ int mr_pcapng_add_opt(struct rte_mbuf * mbuf, uint16_t port_id, uint32_t rx_tx_f /* reserve trailing options and block length */ int len = 0; char str_rx_tx[METADATA_MAX_SIZE]; - char str_sid[METADATA_MAX_SIZE]; + char str_sid_list[METADATA_MAX_SIZE]; char str_dir[METADATA_MAX_SIZE]; + char str_sid_raw[METADATA_MAX_SIZE]; + uint32_t str_maxlen = METADATA_MAX_SIZE - 1; struct mrb_metadata * mrb_metadata = mrbuf_cz_data(mbuf, MR_NODE_CTRLZONE_ID); @@ -581,23 +583,32 @@ int mr_pcapng_add_opt(struct rte_mbuf * mbuf, uint16_t port_id, uint32_t rx_tx_f len += snprintf(str_rx_tx + len, str_maxlen - len, ", hash_usr:%u", mbuf->hash.usr); struct sid_list * sid_list = &mrb_metadata->sid_list; - len = snprintf(str_sid, str_maxlen - len, "head:%u", sid_list->head); - len += snprintf(str_sid + len, str_maxlen - len, ", tail:%u", sid_list->tail); - len += snprintf(str_sid + len, str_maxlen - len, ", capacity:%u", sid_list->capacity); - len += snprintf(str_sid + len, str_maxlen - len, ", cur_sid:%u", mrb_metadata->cur_sid); - len += snprintf(str_sid + len, str_maxlen - len, ", sids:"); + uint16_t sids[RTE_DIM(sid_list->sids)] = {}; + len = snprintf(str_sid_list, str_maxlen, "sid list:"); + sid_list_get(sid_list, sids, RTE_DIM(sid_list->sids)); for (int i = 0; i < RTE_DIM(sid_list->sids); i++) { - len += snprintf(str_sid + len, str_maxlen - len, "[%u],", sid_list->sids[i]); + len += snprintf(str_sid_list + len, str_maxlen - len, "[%u] ", sids[i]); } len = snprintf(str_dir, str_maxlen, "dir:%u", mrb_metadata->dir); len += snprintf(str_dir + len, str_maxlen - len, ", ef_link_id:%u", mrb_metadata->link_id); len += snprintf(str_dir + len, str_maxlen - len, ", ef_peer_id:%u", mrb_metadata->peer_index); + len = snprintf(str_sid_raw, str_maxlen - len, "sid raw head:%u", sid_list->head); + len += snprintf(str_sid_raw + len, str_maxlen - len, ", tail:%u", sid_list->tail); + len += snprintf(str_sid_raw + len, str_maxlen - len, ", capacity:%u", sid_list->capacity); + len += snprintf(str_sid_raw + len, str_maxlen - len, ", cur_sid:%u", mrb_metadata->cur_sid); + len += snprintf(str_sid_raw + len, str_maxlen - len, ", sids:"); + for (int i = 0; i < RTE_DIM(sid_list->sids); i++) + { + len += snprintf(str_sid_raw + len, str_maxlen - len, "[%u] ", sid_list->sids[i]); + } + uint16_t optlen = pcapng_optlen(strlen(str_rx_tx)); - optlen += pcapng_optlen(strlen(str_sid)); + optlen += pcapng_optlen(strlen(str_sid_list)); optlen += pcapng_optlen(strlen(str_dir)); + optlen += pcapng_optlen(strlen(str_sid_raw)); struct pcapng_option * opt = (struct pcapng_option *)rte_pktmbuf_append(mbuf, optlen + sizeof(uint32_t)); if (unlikely(opt == NULL)) { @@ -616,8 +627,9 @@ int mr_pcapng_add_opt(struct rte_mbuf * mbuf, uint16_t port_id, uint32_t rx_tx_f /* set trailer of block length */ struct pcapng_option * opt_new = pcapng_add_option(opt, PCAPNG_OPT_COMMENT, str_rx_tx, strlen(str_rx_tx)); - opt_new = pcapng_add_option(opt_new, PCAPNG_OPT_COMMENT, str_sid, strlen(str_sid)); + opt_new = pcapng_add_option(opt_new, PCAPNG_OPT_COMMENT, str_sid_list, strlen(str_sid_list)); opt_new = pcapng_add_option(opt_new, PCAPNG_OPT_COMMENT, str_dir, strlen(str_dir)); + opt_new = pcapng_add_option(opt_new, PCAPNG_OPT_COMMENT, str_sid_raw, strlen(str_sid_raw)); *(uint32_t *)opt_new = epb->block_length; return RT_SUCCESS; |
