diff options
| author | songyanchao <[email protected]> | 2024-07-05 03:40:02 +0000 |
|---|---|---|
| committer | songyanchao <[email protected]> | 2024-07-05 03:40:02 +0000 |
| commit | 6dac7c36d90a6bfcf60b69a32e27c05686f6c62d (patch) | |
| tree | 41778702d13540c61b9045dd2803d60eab0219f2 | |
| parent | 3417adb5836d703c49b38adbed695ca0aa276159 (diff) | |
🎈 perf(DPISDN-51): Optimize mrpdump arguments.
Optimize mrpdump arguments.
| -rw-r--r-- | tools/tcpdump/pdump.c | 80 |
1 files changed, 44 insertions, 36 deletions
diff --git a/tools/tcpdump/pdump.c b/tools/tcpdump/pdump.c index 5b09360..348417c 100644 --- a/tools/tcpdump/pdump.c +++ b/tools/tcpdump/pdump.c @@ -76,13 +76,12 @@ #define PDUMP_RING_SIZE_ARG "ring-size" #define PDUMP_MSIZE_ARG "mbuf-size" #define PDUMP_NUM_MBUFS_ARG "total-num-mbufs" -#define CMD_LINE_OPT_SER_SOCK_PATH "server-socket-path" -#define CMD_LINE_OPT_CLI_SOCK_PATH "client-socket-path" #define CMD_LINE_OPT_DUMPFILE_PATH "dumpfile-path" #define CMD_LINE_OPT_DUMPFILE_COUNT "dumpfile-count" #define CMD_LINE_OPT_BPF_RULE "bpf-rule" #define CMD_LINE_OPT_OFFSET "offset" #define CMD_LINE_OPT_SNAPSHOT_LENGTH "snapshot-length" +#define CMD_LINE_OPT_HELP "help" #define TX_STREAM_SIZE 64 @@ -184,8 +183,6 @@ struct pcapng_time int num_tuples; volatile uint8_t quit_signal; -static char server_socket_path[PATH_MAX]; -static char client_socket_path[PATH_MAX]; static char dumpfile_path[PATH_MAX] = "dumpfile.pcapng"; static bool dumpfile_count_set = false; static unsigned long long dumpfile_count = 0; @@ -207,24 +204,16 @@ rte_pcapng_t * pcapng = NULL; static void pdump_usage(const char * prgname) { fprintf(stderr, - "usage: %s [EAL options] -- --pdump " + "\nUsage: %s [EAL options] -- --pdump " "'dev_name=<phydev or shmdev name>)," "(queue=<queue_id>)," - "(rx-dev=<iface or pcap file> |" - " tx-dev=<iface or pcap file>," - "[--server-socket-path=<server socket dir>" - "default:/var/run/.dpdk/ (or) ~/.dpdk/]\n" - "[--client-socket-path=<client socket dir>" - "default:/var/run/.dpdk/ (or) ~/.dpdk/]\n" - "[--dumpfile-path=<dumpfile>]" - "default:dumpfile.pcap\n" + "(rx|tx)'\n" + "[--dumpfile-path=<dumpfile>] default:dumpfile.pcap\n" "[--dumpfile-count=]\n" - "[--bpf-rule=<bpf-rule>]" - "default:<None>\n" - "[--offset=>]" - "default:0\n" - "[--snapshot-length=]" - "default:<UINT32_MAX>\n", + "[--bpf-rule=<bpf-rule>] default:<None>\n" + "[--offset=>] default:0\n" + "[--snapshot-length=] default:<UINT32_MAX>\n" + "[--help]\n", prgname); } @@ -417,9 +406,9 @@ static int launch_args_parse(int argc, char ** argv, char * prgname) int opt, ret; int option_index; static struct option long_option[] = { - {"pdump", 1, 0, 0}, {"server-socket-path", 1, 0, 0}, {"client-socket-path", 1, 0, 0}, - {"dumpfile-path", 1, 0, 0}, {"dumpfile-count", 1, 0, 0}, {"bpf-rule", 1, 0, 0},{"offset", 1, 0, 0}, - {"use-ppi-header", 0, 0, 0}, {"snapshot-length", 1, 0, 0}, {NULL, 0, 0, 0}}; + {"pdump", 1, 0, 0}, {"dumpfile-path", 1, 0, 0}, {"dumpfile-count", 1, 0, 0}, + {"bpf-rule", 1, 0, 0}, {"offset", 1, 0, 0}, {"use-ppi-header", 0, 0, 0}, + {"snapshot-length", 1, 0, 0}, {"help", 0, 0, 0}, {NULL, 0, 0, 0}}; if (argc == 1) pdump_usage(prgname); @@ -440,18 +429,6 @@ static int launch_args_parse(int argc, char ** argv, char * prgname) } } - if (!strncmp(long_option[option_index].name, CMD_LINE_OPT_SER_SOCK_PATH, - sizeof(CMD_LINE_OPT_SER_SOCK_PATH))) - { - snprintf(server_socket_path, sizeof(server_socket_path), "%s", optarg); - } - - if (!strncmp(long_option[option_index].name, CMD_LINE_OPT_CLI_SOCK_PATH, - sizeof(CMD_LINE_OPT_CLI_SOCK_PATH))) - { - snprintf(client_socket_path, sizeof(client_socket_path), "%s", optarg); - } - if (!strncmp(long_option[option_index].name, CMD_LINE_OPT_DUMPFILE_PATH, sizeof(CMD_LINE_OPT_DUMPFILE_PATH))) { @@ -482,6 +459,12 @@ static int launch_args_parse(int argc, char ** argv, char * prgname) sscanf(optarg, "%" SCNu32, &snaplen); } + if (!strncmp(long_option[option_index].name, CMD_LINE_OPT_HELP, sizeof(CMD_LINE_OPT_HELP))) + { + pdump_usage(prgname); + return 0; + } + break; default: @@ -786,7 +769,7 @@ static void err_value_dump(int32_t err_value) static void enable_pdump(void) { printf("Enable pdump.\n"); - printf("offset:%u\n",offset); + printf("offset:%u\n", offset); /* Set all device */ for (int i = 0; i < num_tuples; i++) { @@ -839,7 +822,7 @@ static void enable_pdump(void) { /* Phydev use dpdk pdump api */ int ret = rte_pdump_enable_bpf(pt->port_id, pt->queue, RTE_PDUMP_FLAG_RX | RTE_PDUMP_FLAG_PCAPNG, - snaplen ,offset, pt->rx_ring, pt->mp, prm); + snaplen, offset, pt->rx_ring, pt->mp, prm); if (ret < 0) rte_exit(EXIT_FAILURE, "Phydev :%s, rx enable err.\n", pt->dev_symbol); } @@ -994,6 +977,14 @@ static void disable_pdump(void) rte_exit(EXIT_FAILURE, "Device:%s, disable err.\n", pt->dev_symbol); } + /* Free rx ring */ + while (rte_ring_count(pt->rx_ring) > 0) + { + struct rte_mbuf * mbufs[BURST_SIZE]; + const uint16_t nb_rx = rte_ring_dequeue_burst(pt->rx_ring, (void *)mbufs, BURST_SIZE, NULL); + rte_pktmbuf_free_bulk(mbufs, nb_rx); + } + /* Clear pt info */ pt->rx_ring = NULL; pt->mp = NULL; @@ -1041,6 +1032,14 @@ static void disable_pdump(void) rte_exit(EXIT_FAILURE, "Device:%s, disable err.\n", pt->dev_symbol); } + /* Free tx ring */ + while (rte_ring_count(pt->tx_ring) > 0) + { + struct rte_mbuf * mbufs[BURST_SIZE]; + const uint16_t nb_tx = rte_ring_dequeue_burst(pt->tx_ring, (void *)mbufs, BURST_SIZE, NULL); + rte_pktmbuf_free_bulk(mbufs, nb_tx); + } + /* Clear pt info */ pt->tx_ring = NULL; pt->mp = NULL; @@ -1146,6 +1145,13 @@ int main(int argc, char ** argv) signal(SIGTERM, signal_handler); signal(SIGHUP, signal_handler); + /* Check help arg */ + if (argc > 1 && !strcmp(argv[1], "--help")) + { + pdump_usage(argv[0]); + return 0; + } + argp[0] = argv[0]; argp[1] = c_flag; argp[2] = n_flag; @@ -1176,6 +1182,8 @@ int main(int argc, char ** argv) ret = launch_args_parse(argc, argv, argp[0]); if (ret < 0) rte_exit(EXIT_FAILURE, "Invalid argument\n"); + else if (ret == 0) + rte_exit(EXIT_SUCCESS, " "); } /* create dumpfile writer */ |
