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 D145842495; Thu, 26 Jan 2023 19:24:05 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 741DC42D72; Thu, 26 Jan 2023 19:23:53 +0100 (CET) Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) by mails.dpdk.org (Postfix) with ESMTP id 5BA9042B7E for ; Thu, 26 Jan 2023 19:23:49 +0100 (CET) Received: by mail-pg1-f171.google.com with SMTP id 141so1661549pgc.0 for ; Thu, 26 Jan 2023 10:23:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bpYpb4mVA++bpS0ADf93MZieHiFXUCIeNVaqvqtxg1k=; b=LgJ94zF8bqD9bnghAqHFuxi2maH+U5omKllNkCXBfyvwfAXCQ+8UR+hjMOF919lJip z1rtzdYVFWPb6ftkyxz77G3wzedno5aArlkyB/KXexarpdebHFp54GMe+8nrcPVvYuXd +GW9GWP428AI90pHy8Kc+yc7e67umtMkP1F8UUIk9Y3dKjrxBXM3X7Pjc1XzDS1+csa7 9sjzp6WTNTc/8KUpnoRW1oMD2EysmSn5JiUT4ZylbFXzlCb0/W6ajtOMecMGWJbtNxKB x1ceQJMWzN1AVJd0sdTAOQ+moJIFWm6aZuPeq8ngSUZgjwGeIHaL3UAKHSYM4jRMIGCq oJrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bpYpb4mVA++bpS0ADf93MZieHiFXUCIeNVaqvqtxg1k=; b=nkJnUJD89wpHQtgx5Q7YxnL398ciRA+CqaqJPvZFxKpIf2s1BgGJRTPUxAClmDhIfd Y8wpMRpcaEUUP/l8wftLOIIr7gnIq3QHyRYn+T6SRzjfd5lbWbKD+jIGEFy7d6kueU8F ax0VJaKtEFguZd3RccUM22jpJV7AelyPlb9dUNuOhXjaJgDStRJD5Od56e9rwtdBT4U5 kdCvcKaNd5H8v0FvG70R6yIOAsO3EnpGeOI650IMgI7DFpWodH0r0fsBoPlPXFckBM7S ek+uHxh7FlWPlzvBQ/Z2EqOwx9yeZ99kCBEz6g8jX0b9XLkUjGhYwpeF4o2qT17kZOmq D+iQ== X-Gm-Message-State: AO0yUKWgzdiQJ/tk6bsymlm+ILJvPsseRcKoUU4tvCLmc/snvk3UN8BC 8d0NIONxwfd9W11y1A/NRMO52pYDk9RPnzPu478= X-Google-Smtp-Source: AK7set/pnY9UJgxJtKwnJ8ARZKhpPFG4f2w9MCjx0HuDvYyPHB0SvhfdieH/qVy1xyg/ap8CIFneSw== X-Received: by 2002:a62:cd83:0:b0:58d:d7b9:fda4 with SMTP id o125-20020a62cd83000000b0058dd7b9fda4mr2606845pfg.27.1674757428293; Thu, 26 Jan 2023 10:23:48 -0800 (PST) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id r30-20020aa79ede000000b00582388bd80csm1139852pfq.83.2023.01.26.10.23.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 10:23:47 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH 3/3] dumpcap: add support statistics mode Date: Thu, 26 Jan 2023 10:23:44 -0800 Message-Id: <20230126182344.90635-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230126182344.90635-1-stephen@networkplumber.org> References: <20230126182344.90635-1-stephen@networkplumber.org> MIME-Version: 1.0 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 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 --- 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 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