From: Chengwen Feng <fengchengwen@huawei.com>
To: <thomas@monjalon.net>
Cc: <dev@dpdk.org>, <liuyonglong@huawei.com>
Subject: [PATCH 4/9] app/dma-perf: refactor output csv
Date: Mon, 11 Aug 2025 18:54:25 +0800 [thread overview]
Message-ID: <20250811105430.55791-5-fengchengwen@huawei.com> (raw)
In-Reply-To: <20250811105430.55791-1-fengchengwen@huawei.com>
The original implement involved many functions and global variables,
This commit refactor it.
Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
app/test-dma-perf/benchmark.c | 7 ++-
app/test-dma-perf/main.c | 87 +++++++++++++----------------------
app/test-dma-perf/main.h | 4 +-
3 files changed, 35 insertions(+), 63 deletions(-)
diff --git a/app/test-dma-perf/benchmark.c b/app/test-dma-perf/benchmark.c
index 6d617ea200..b798199dc1 100644
--- a/app/test-dma-perf/benchmark.c
+++ b/app/test-dma-perf/benchmark.c
@@ -119,11 +119,11 @@ output_result(struct test_configure *cfg, struct lcore_params *para,
printf("Average Bandwidth: %.3lf Gbps, MOps: %.3lf\n", bandwidth, mops);
if (cfg->is_dma)
- snprintf(output_str[lcore_id], MAX_OUTPUT_STR_LEN, CSV_LINE_DMA_FMT,
+ output_csv(CSV_LINE_DMA_FMT,
scenario_id, lcore_id, dma_name, ring_size, kick_batch, buf_size,
nr_buf, memory, ave_cycle, bandwidth, mops);
else
- snprintf(output_str[lcore_id], MAX_OUTPUT_STR_LEN, CSV_LINE_CPU_FMT,
+ output_csv(CSV_LINE_CPU_FMT,
scenario_id, lcore_id, buf_size,
nr_buf, memory, ave_cycle, bandwidth, mops);
}
@@ -863,8 +863,7 @@ mem_copy_benchmark(struct test_configure *cfg)
}
printf("\nAverage Cycles/op per worker: %.1lf, Total Bandwidth: %.3lf Gbps, Total MOps: %.3lf\n",
(avg_cycles_total * (float) 1.0) / nb_workers, bandwidth_total, mops_total);
- snprintf(output_str[MAX_WORKER_NB], MAX_OUTPUT_STR_LEN, CSV_TOTAL_LINE_FMT,
- cfg->scenario_id, nr_buf, memory * nb_workers,
+ output_csv(CSV_TOTAL_LINE_FMT, cfg->scenario_id, nr_buf, memory * nb_workers,
(avg_cycles_total * (float) 1.0) / nb_workers, bandwidth_total, mops_total);
out:
diff --git a/app/test-dma-perf/main.c b/app/test-dma-perf/main.c
index ed582b609f..9b0b3a4103 100644
--- a/app/test-dma-perf/main.c
+++ b/app/test-dma-perf/main.c
@@ -49,60 +49,49 @@ static struct global_configure global_cfg;
static char *config_path;
static char *result_path;
-char output_str[MAX_WORKER_NB + 1][MAX_OUTPUT_STR_LEN];
-
-static FILE *fd;
-
-static void
-output_csv(bool need_blankline)
+void
+output_csv(const char *fmt, ...)
{
- uint32_t i;
+#define MAX_OUTPUT_STR_LEN 512
+ char str[MAX_OUTPUT_STR_LEN] = {0};
+ va_list ap;
+ FILE *fd;
- if (need_blankline) {
- fprintf(fd, ",,,,,,,,\n");
- fprintf(fd, ",,,,,,,,\n");
+ fd = fopen(result_path, "a");
+ if (fd == NULL) {
+ printf("Open output CSV file error.\n");
+ return;
}
- for (i = 0; i < RTE_DIM(output_str); i++) {
- if (output_str[i][0]) {
- fprintf(fd, "%s", output_str[i]);
- output_str[i][0] = '\0';
- }
- }
+ va_start(ap, fmt);
+ vsnprintf(str, MAX_OUTPUT_STR_LEN - 1, fmt, ap);
+ fprintf(fd, "%s", str);
fflush(fd);
+ fclose(fd);
}
static void
-output_env_info(void)
+output_blanklines(int lines)
{
- snprintf(output_str[0], MAX_OUTPUT_STR_LEN, "Test Environment:\n");
- snprintf(output_str[1], MAX_OUTPUT_STR_LEN, "CPU frequency,%.3lf Ghz",
- rte_get_timer_hz() / 1000000000.0);
-
- output_csv(true);
+ int i;
+ for (i = 0; i < lines; i++)
+ output_csv("%s\n", ",,,,,,,,");
}
static void
-output_header(uint32_t case_id, struct test_configure *case_cfg)
+output_env_info(void)
{
- snprintf(output_str[0], MAX_OUTPUT_STR_LEN,
- CSV_HDR_FMT, case_id, case_cfg->test_type_str);
-
- output_csv(true);
+ output_blanklines(2);
+ output_csv("Test Environment:\n"
+ "CPU frequency,%.3lf Ghz\n", rte_get_timer_hz() / 1000000000.0);
+ output_blanklines(1);
}
-static int
-open_output_csv(const char *rst_path_ptr)
+static void
+output_header(uint32_t case_id, struct test_configure *case_cfg)
{
- fd = fopen(rst_path_ptr, "a");
- if (!fd) {
- printf("Open output CSV file error.\n");
- return 1;
- }
- output_csv(true);
- fclose(fd);
- return 0;
+ output_csv(CSV_HDR_FMT, case_id, case_cfg->test_type_str);
}
static int
@@ -126,7 +115,6 @@ run_test_case(struct test_configure *case_cfg)
static void
run_test(uint32_t case_id, struct test_configure *case_cfg)
{
- uint32_t i;
uint32_t nb_lcores = rte_lcore_count();
struct test_configure_entry *mem_size = &case_cfg->mem_size;
struct test_configure_entry *buf_size = &case_cfg->buf_size;
@@ -135,9 +123,6 @@ run_test(uint32_t case_id, struct test_configure *case_cfg)
struct test_configure_entry dummy = { 0 };
struct test_configure_entry *var_entry = &dummy;
- for (i = 0; i < RTE_DIM(output_str); i++)
- memset(output_str[i], 0, MAX_OUTPUT_STR_LEN);
-
if (nb_lcores <= case_cfg->num_worker) {
printf("Case %u: Not enough lcores.\n", case_id);
return;
@@ -550,6 +535,7 @@ parse_args(int argc, char **argv)
},
};
char rst_path[PATH_MAX + 16] = {0};
+ FILE *fd;
int ret;
ret = rte_argparse_parse(&obj, argc, argv);
@@ -602,18 +588,15 @@ main(int argc, char *argv[])
for (i = 0; i < case_nb; i++) {
if (test_cases[i].is_skip) {
printf("Test case %d configured to be skipped.\n\n", i + 1);
- snprintf(output_str[0], MAX_OUTPUT_STR_LEN, "Skip the test-case %d\n",
- i + 1);
- if (open_output_csv(result_path))
- return 0;
+ output_blanklines(2);
+ output_csv("Skip the test-case %d\n", i + 1);
continue;
}
if (!test_cases[i].is_valid) {
printf("Invalid test case %d.\n\n", i + 1);
- snprintf(output_str[0], MAX_OUTPUT_STR_LEN, "Invalid case %d\n", i + 1);
- if (open_output_csv(result_path))
- return 0;
+ output_blanklines(2);
+ output_csv("Invalid case %d\n", i + 1);
continue;
}
@@ -634,12 +617,6 @@ main(int argc, char *argv[])
rte_exit(EXIT_FAILURE,
"There should be at least 2 worker lcores.\n");
- fd = fopen(result_path, "a");
- if (!fd) {
- printf("Open output CSV file error.\n");
- return 0;
- }
-
output_env_info();
run_test(i + 1, &test_cases[i]);
@@ -647,8 +624,6 @@ main(int argc, char *argv[])
/* clean up the EAL */
rte_eal_cleanup();
- fclose(fd);
-
printf("\nCase %u completed.\n\n", i + 1);
exit(EXIT_SUCCESS);
diff --git a/app/test-dma-perf/main.h b/app/test-dma-perf/main.h
index fa3a8ebf2e..54dc1c4c2a 100644
--- a/app/test-dma-perf/main.h
+++ b/app/test-dma-perf/main.h
@@ -11,12 +11,9 @@
#include <rte_dev.h>
#define MAX_WORKER_NB 128
-#define MAX_OUTPUT_STR_LEN 512
#define MAX_DMA_NB 128
-extern char output_str[MAX_WORKER_NB + 1][MAX_OUTPUT_STR_LEN];
-
typedef enum {
OP_NONE = 0,
OP_ADD,
@@ -79,6 +76,7 @@ struct global_configure {
int eal_argc;
};
+void output_csv(const char *fmt, ...);
int mem_copy_benchmark(struct test_configure *cfg);
#endif /* MAIN_H */
--
2.17.1
next prev parent reply other threads:[~2025-08-11 10:54 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-11 10:54 [PATCH 0/9] bugfix and refactor of dma-perf Chengwen Feng
2025-08-11 10:54 ` [PATCH 1/9] app/dma-perf: fix use-after-free Chengwen Feng
2025-08-11 10:54 ` [PATCH 2/9] app/dma-perf: add global section for config file Chengwen Feng
2025-08-11 10:54 ` [PATCH 3/9] app/dma-perf: use argparse lib to parse argument Chengwen Feng
2025-08-11 10:54 ` Chengwen Feng [this message]
2025-08-11 10:54 ` [PATCH 5/9] app/dma-perf: support list DMA devices Chengwen Feng
2025-08-11 10:54 ` [PATCH 6/9] app/dma-perf: add more global config Chengwen Feng
2025-08-11 10:54 ` [PATCH 7/9] app/dma-perf: remove invalid or redundant field Chengwen Feng
2025-08-11 10:54 ` [PATCH 8/9] app/dma-perf: refactor load config function Chengwen Feng
2025-08-11 10:54 ` [PATCH 9/9] app/dma-perf: refactor benchmark function Chengwen Feng
2025-08-12 2:06 ` [PATCH 00/10] bugfix and refactor of dma-perf Chengwen Feng
2025-08-12 2:06 ` [PATCH 01/10] app/dma-perf: fix use-after-free Chengwen Feng
2025-08-12 2:07 ` [PATCH 02/10] app/dma-perf: add global section for config file Chengwen Feng
2025-08-12 2:07 ` [PATCH 03/10] app/dma-perf: use argparse lib to parse argument Chengwen Feng
2025-08-12 2:07 ` [PATCH 04/10] app/dma-perf: refactor output csv Chengwen Feng
2025-08-12 2:07 ` [PATCH 05/10] app/dma-perf: support list DMA devices Chengwen Feng
2025-08-12 2:07 ` [PATCH 06/10] app/dma-perf: add more global config Chengwen Feng
2025-08-12 2:07 ` [PATCH 07/10] app/dma-perf: remove invalid or redundant field Chengwen Feng
2025-08-12 2:07 ` [PATCH 08/10] app/dma-perf: refactor load config function Chengwen Feng
2025-08-12 2:07 ` [PATCH 09/10] app/dma-perf: refactor benchmark function Chengwen Feng
2025-08-12 2:07 ` [PATCH 10/10] app/dma-perf: support specific error info Chengwen Feng
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=20250811105430.55791-5-fengchengwen@huawei.com \
--to=fengchengwen@huawei.com \
--cc=dev@dpdk.org \
--cc=liuyonglong@huawei.com \
--cc=thomas@monjalon.net \
/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).