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 0E15A45BE5; Mon, 28 Oct 2024 03:22:15 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 193E740A77; Mon, 28 Oct 2024 03:21:56 +0100 (CET) Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by mails.dpdk.org (Postfix) with ESMTP id B2D264066F for ; Mon, 28 Oct 2024 03:21:45 +0100 (CET) Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-20c7edf2872so34863515ad.1 for ; Sun, 27 Oct 2024 19:21:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1730082105; x=1730686905; darn=dpdk.org; 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=14sNidZTnXXCRl98/mnIV8Ul+x0NwGeK36XwOtLl1Go=; b=Lxsek+VMn8og5hyAR9WcfBvXLz97Kl6rieT8ny2XNZ4RTmaz47NiBboqL/QS1RrPV2 +h8FfT3h98apxpSjrtyE8K6JYyc/Qvryyo6YXix2AyASEQQHuWYExgmlmbBX5Qdbnhvw UzLzdcBhUs2r7Jp0koXBTtXIKZNFPvOOGXyZZOLJp6oN3qantr6jMD3c5U5DaEAG7nbb aSUUgyhldFnfZMAQWmAAhwMW9JCmm5/yXmsXlw4aXEU76ZUAxzelef6RgjgvMMkbbuep eNImpji+ki5fDA2fJCvbXhYxsPeLcGmJL/ztxplkp4f3IxDdCqsOeI6fXudUeIBTfacJ eIog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730082105; x=1730686905; 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=14sNidZTnXXCRl98/mnIV8Ul+x0NwGeK36XwOtLl1Go=; b=TQdKJWcuBgqH0GlkJa6cJ+xvOlQXEjhyC/ZYt98uCC/i3zpOdiVLHiv1RzMvOhcfbz qdnjpXDBbzb5LHcRn1DfdX+mpMiEsWiz9sjNGfA76febPPG3bg8luGGrK8zzkNmOx8dx DGC7hH2zTyst3iaFdcJI5HskqiiFLJd0qNwSIacjaIwEcHqQTf+mgfswySu5f3PZP+Ni RrHX1FW990dqPNu8WwsUby5Jj9WABKubU28qRgg/2DhJ5OHhWl4BewhuLaaaGBvqEKGz tDcwdiJXtqn7KRGiK9dstI8rXqWsMjHOmkdVyWqRzeXhAfCQX80eAqqsWG9oMdN/8TWI k6QQ== X-Gm-Message-State: AOJu0YzmraaMtogP2D4SHN33eT6JDXMwnvoGz6mwC4EP7ukOMYK5uKfy +hgEEw685HDmH1xIHhAMC/6b648qR6Y96OB82rwzlqjkxyEI0w1hNjIyJ3xe5bsKelgfkCHZ2Bl 1YE0= X-Google-Smtp-Source: AGHT+IHlLMtX40Z+Xtrm9btm9OmM3q3odEwfUs5XrDF6O1bSNLNWNN3/jiyj3Aa4H3RAr/JEL7fcBA== X-Received: by 2002:a17:902:d4c4:b0:20c:b6cf:f450 with SMTP id d9443c01a7336-20fb8ab9eecmr194141875ad.29.1730082104832; Sun, 27 Oct 2024 19:21:44 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-210bc04b8bbsm41095615ad.244.2024.10.27.19.21.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Oct 2024 19:21:44 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Aman Singh Subject: [PATCH v10 5/8] test-pmd: add option to redirect packet log Date: Sun, 27 Oct 2024 19:19:31 -0700 Message-ID: <20241028022131.142609-6-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241028022131.142609-1-stephen@networkplumber.org> References: <20240312220129.70667-1-stephen@networkplumber.org> <20241028022131.142609-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 When running tests in interactive mode, it is useful to be able to redirect the packet decode (verbose output) into a file. Signed-off-by: Stephen Hemminger --- app/test-pmd/cmdline.c | 41 +++++++++++++++++++++ app/test-pmd/config.c | 23 ++++++++++++ app/test-pmd/testpmd.c | 3 ++ app/test-pmd/testpmd.h | 3 ++ app/test-pmd/util.c | 11 +++++- doc/guides/testpmd_app_ug/testpmd_funcs.rst | 7 ++++ 6 files changed, 86 insertions(+), 2 deletions(-) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 7e0666e9f6..a6dfa116c7 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -315,6 +315,9 @@ static void cmd_help_long_parsed(void *parsed_result, "set verbose (level)\n" " Set the debug verbosity level X.\n\n" + "set output (filename)\n" + " Set the packet debug log file\n\n" + "set log global|(type) (level)\n" " Set the log level.\n\n" @@ -4110,6 +4113,43 @@ static cmdline_parse_inst_t cmd_set_numbers = { }, }; + +/* *** SET OUTPUT FILENAME *** */ +struct cmd_set_output_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t output; + cmdline_fixed_string_t filename; +}; + +static void +cmd_set_output_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_set_output_result *res = parsed_result; + + set_output_file(res->filename); +} + +static cmdline_parse_token_string_t cmd_set_output_set = + TOKEN_STRING_INITIALIZER(struct cmd_set_output_result, set, "set"); +static cmdline_parse_token_string_t cmd_set_output_output = + TOKEN_STRING_INITIALIZER(struct cmd_set_output_result, output, "output"); +static cmdline_parse_token_string_t cmd_set_output_name = + TOKEN_STRING_INITIALIZER(struct cmd_set_output_result, filename, NULL); + +static cmdline_parse_inst_t cmd_set_output = { + .f = cmd_set_output_parsed, + .data = NULL, + .help_str = "set output ", + .tokens = { + (void *)&cmd_set_output_set, + (void *)&cmd_set_output_output, + (void *)&cmd_set_output_name, + NULL, + }, +}; + /* *** SET LOG LEVEL CONFIGURATION *** */ struct cmd_set_log_result { @@ -13650,6 +13690,7 @@ static cmdline_parse_ctx_t builtin_ctx[] = { &cmd_set_xstats_hide_zero, &cmd_set_record_core_cycles, &cmd_set_record_burst_stats, + &cmd_set_output, &cmd_operate_port, &cmd_operate_specific_port, &cmd_operate_attach_port, diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index 88770b4dfc..d806cea3d3 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -6340,6 +6340,29 @@ set_verbose_level(uint16_t vb_level) configure_rxtx_dump_callbacks(verbose_level); } +void +set_output_file(const char *filename) +{ + FILE *outf, *oldf; + + if (!strcmp(filename, "-")) { + outf = stdout; + } else { + outf = fopen(filename, "a"); + if (outf == NULL) { + perror(filename); + return; + } + } + + oldf = rte_atomic_exchange_explicit(&output_file, outf, rte_memory_order_seq_cst); + if (oldf != NULL && oldf != stdout) { + /* make sure other threads are not mid print */ + rte_delay_us_sleep(US_PER_S/10); + fclose(oldf); + } +} + void vlan_extend_set(portid_t port_id, int on) { diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index b1401136e4..7790ba6ce0 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -99,6 +99,7 @@ #define EXTBUF_ZONE_SIZE (RTE_PGSIZE_2M - 4 * RTE_CACHE_LINE_SIZE) uint16_t verbose_level = 0; /**< Silent by default. */ +RTE_ATOMIC(FILE *) output_file; /**< log to console by default. */ int testpmd_logtype; /**< Log type for testpmd logs */ /* use main core for command line ? */ @@ -4543,6 +4544,8 @@ main(int argc, char** argv) rte_exit(EXIT_FAILURE, "Cannot register log type"); rte_log_set_level(testpmd_logtype, RTE_LOG_DEBUG); + output_file = stdout; + diag = rte_eal_init(argc, argv); if (diag < 0) rte_exit(EXIT_FAILURE, "Cannot init EAL: %s\n", diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index 131ea53f84..e5affd44a2 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -493,6 +494,7 @@ extern uint8_t xstats_hide_zero; /**< Hide zero values for xstats display */ extern uint8_t record_core_cycles; /**< Enables measurement of CPU cycles */ extern uint8_t record_burst_stats; /**< Enables display of RX and TX bursts */ extern uint16_t verbose_level; /**< Drives messages being displayed, if any. */ +extern RTE_ATOMIC(FILE *) output_file; /**< Where packet data is written */ extern int testpmd_logtype; /**< Log type for testpmd logs */ extern uint8_t interactive; extern uint8_t auto_start; @@ -1105,6 +1107,7 @@ void set_xstats_hide_zero(uint8_t on_off); void set_record_core_cycles(uint8_t on_off); void set_record_burst_stats(uint8_t on_off); void set_verbose_level(uint16_t vb_level); +void set_output_file(const char *filename); void set_rx_pkt_segments(unsigned int *seg_lengths, unsigned int nb_segs); void set_rx_pkt_hdrs(unsigned int *seg_protos, unsigned int nb_segs); void show_rx_pkt_hdrs(void); diff --git a/app/test-pmd/util.c b/app/test-pmd/util.c index bf9b639d95..2446687090 100644 --- a/app/test-pmd/util.c +++ b/app/test-pmd/util.c @@ -89,9 +89,15 @@ dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[], size_t buf_size = MAX_STRING_LEN; size_t cur_len = 0; uint64_t restore_info_dynflag; + FILE *outf; if (!nb_pkts) return; + + outf = rte_atomic_load_explicit(&output_file, rte_memory_order_relaxed); + if (!outf) + return; + restore_info_dynflag = rte_flow_restore_info_dynflag(); MKDUMPSTR(print_buf, buf_size, cur_len, "port %u/queue %u: %s %u packets\n", port_id, queue, @@ -292,11 +298,12 @@ dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[], MKDUMPSTR(print_buf, buf_size, cur_len, "INVALID mbuf: %s\n", reason); if (cur_len >= buf_size) - printf("%s ...\n", print_buf); + fprintf(outf, "%s ...\n", print_buf); else - printf("%s", print_buf); + fprintf(outf, "%s", print_buf); cur_len = 0; } + fflush(outf); } uint16_t diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst index eeef49500f..6aef74ff45 100644 --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst @@ -684,6 +684,13 @@ Reset forwarding to the default configuration:: testpmd> set default +set output +~~~~~~~~~~ + +Redirect the debug log:: + + testpmd> set output /tmp/packet.log + set verbose ~~~~~~~~~~~ -- 2.45.2