DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH 3/3] dumpcap: add support statistics mode
Date: Thu, 26 Jan 2023 10:23:44 -0800	[thread overview]
Message-ID: <20230126182344.90635-4-stephen@networkplumber.org> (raw)
In-Reply-To: <20230126182344.90635-1-stephen@networkplumber.org>

This add new -S option which does the same thing as wireshark's
dumpcap -S option.

It loops over all interfaces and prints the number of received
and dropped packets. In this mode, actual packet capture is
not done.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 app/dumpcap/main.c | 55 +++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 49 insertions(+), 6 deletions(-)

diff --git a/app/dumpcap/main.c b/app/dumpcap/main.c
index 02bb8b2b2b4f..d1c70f769be5 100644
--- a/app/dumpcap/main.c
+++ b/app/dumpcap/main.c
@@ -66,6 +66,7 @@ static const char *file_prefix;
 static uint32_t snaplen = RTE_MBUF_DEFAULT_BUF_SIZE;
 static bool dump_bpf;
 static bool show_interfaces;
+static bool print_stats;
 static bool select_interfaces;
 const char *interface_arg;
 
@@ -113,6 +114,7 @@ static void usage(void)
 	       "                           don't capture in promiscuous mode\n"
 	       "  -D, --list-interfaces    print list of interfaces and exit\n"
 	       "  -d                       print generated BPF code for capture filter\n"
+	       "  -S                       print statistics for each interface once per second\n"
 	       "\n"
 	       "Stop conditions:\n"
 	       "  -c <packet count>        stop after n packets (def: infinite)\n"
@@ -337,7 +339,7 @@ static void parse_opts(int argc, char **argv)
 	int option_index, c;
 
 	for (;;) {
-		c = getopt_long(argc, argv, "a:b:c:dDf:ghi:nN:pPqs:vw:",
+		c = getopt_long(argc, argv, "a:b:c:dDf:ghi:nN:pPqSs:vw:",
 				long_options, &option_index);
 		if (c == -1)
 			break;
@@ -406,6 +408,9 @@ static void parse_opts(int argc, char **argv)
 		case 's':
 			snaplen = get_uint(optarg, "snap_len", 0);
 			break;
+		case 'S':
+			print_stats = true;
+			break;
 		case 'w':
 			output_name = optarg;
 			break;
@@ -427,6 +432,39 @@ signal_handler(int sig_num __rte_unused)
 	__atomic_store_n(&quit_signal, true, __ATOMIC_RELAXED);
 }
 
+
+/* Instead of capturing, it tracks interface statistics */
+static void statistics_loop(void)
+{
+	struct rte_eth_stats stats;
+	char name[RTE_ETH_NAME_MAX_LEN];
+	uint16_t p;
+	int r;
+
+	printf("%-15s  %10s  %10s\n",
+	       "Interface", "Received", "Dropped");
+
+	while (!__atomic_load_n(&quit_signal, __ATOMIC_RELAXED)) {
+		RTE_ETH_FOREACH_DEV(p) {
+			if (rte_eth_dev_get_name_by_port(p, name) < 0)
+				continue;
+
+			r = rte_eth_stats_get(p, &stats);
+			if (r < 0) {
+				fprintf(stderr,
+					"stats_get for port %u failed: %d (%s)\n",
+					p, r, strerror(r));
+				return;
+			}
+
+			printf("%-15s  %10"PRIu64"  %10"PRIu64"\n",
+			       name, stats.ipackets,
+			       stats.imissed + stats.ierrors + stats.rx_nombuf);
+		}
+		sleep(1);
+	}
+}
+
 /* Return the time since 1/1/1970 in nanoseconds */
 static uint64_t create_timestamp(void)
 {
@@ -834,6 +872,16 @@ int main(int argc, char **argv)
 	if (TAILQ_EMPTY(&interfaces))
 		set_default_interface();
 
+	signal(SIGINT, signal_handler);
+	signal(SIGPIPE, SIG_IGN);
+
+	enable_primary_monitor();
+
+	if (print_stats) {
+		statistics_loop();
+		exit(0);
+	}
+
 	r = create_ring();
 	mp = create_mempool();
 	out = create_output();
@@ -841,11 +889,6 @@ int main(int argc, char **argv)
 	start_time = create_timestamp();
 	enable_pdump(r, mp);
 
-	signal(SIGINT, signal_handler);
-	signal(SIGPIPE, SIG_IGN);
-
-	enable_primary_monitor();
-
 	if (!quiet) {
 		fprintf(stderr, "Packets captured: ");
 		show_count(0);
-- 
2.39.0


  parent reply	other threads:[~2023-01-26 18:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-26 18:23 [PATCH 0/3] dumpcap: small enhancements Stephen Hemminger
2023-01-26 18:23 ` [PATCH 1/3] dumpcap: add --interface to help Stephen Hemminger
2023-01-26 18:23 ` [PATCH 2/3] dumpcap: support temp-dir option Stephen Hemminger
2023-01-26 18:23 ` Stephen Hemminger [this message]
2023-02-06  9:46 ` [PATCH 0/3] dumpcap: small enhancements Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230126182344.90635-4-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).