Skip to content

Commit

Permalink
Introduce --file-prefix to secondary process tools
Browse files Browse the repository at this point in the history
  • Loading branch information
PlagueCZ committed Jan 21, 2025
1 parent ed1457f commit 618d50c
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 12 deletions.
1 change: 1 addition & 0 deletions docs/deployment/help_dpservice-dump.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
|--------|----------|-------------|---------|
| -h, --help | None | display this help and exit | |
| -v, --version | None | display version and exit | |
| --file-prefix | PREFIX | prefix for hugepage filenames | |
| --drops | None | show dropped packets | |
| --nodes | REGEX | show graph node traversal, limit to REGEX-matched nodes (empty string for all) | |
| --filter | FILTER | show only packets matching a pcap-style FILTER | |
Expand Down
1 change: 1 addition & 0 deletions docs/deployment/help_dpservice-inspect.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
|--------|----------|-------------|---------|
| -h, --help | None | display this help and exit | |
| -v, --version | None | display version and exit | |
| --file-prefix | PREFIX | prefix for hugepage filenames | |
| -o, --output-format | FORMAT | format of the output | 'human' (default), 'table', 'csv' or 'json' |
| -t, --table | NAME | hash table to choose | 'list' (default), 'conntrack', 'dnat', 'iface', 'lb', 'lb_id', 'portmap', 'portoverload', 'snat', 'vnf', 'vnf_rev' or 'vni' |
| -s, --socket | NUMBER | NUMA socket to use | |
Expand Down
15 changes: 13 additions & 2 deletions tools/common/dp_secondary_eal.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ static const char *eal_arg_strings[] = {
"--log-level=6", // hide DPDK's informational messages (level 7)
};

static char *eal_args_mem[RTE_DIM(eal_arg_strings)];
static char *eal_args_mem[RTE_DIM(eal_arg_strings) + 1]; // +1 for optional --file-prefix
static char *eal_args[RTE_DIM(eal_args_mem)];

int dp_secondary_eal_init(void)

int dp_secondary_eal_init(const char *file_prefix)
{
char eal_file_prefix[64] = {};

// Required arguments
for (size_t i = 0; i < RTE_DIM(eal_arg_strings); ++i) {
eal_args[i] = eal_args_mem[i] = strdup(eal_arg_strings[i]);
if (!eal_args[i]) {
Expand All @@ -32,9 +36,16 @@ int dp_secondary_eal_init(void)
return DP_ERROR;
}
}

// Optional arguments
if (file_prefix && *file_prefix)
snprintf(eal_file_prefix, sizeof(eal_file_prefix), "--file-prefix=%s", file_prefix); // can get cut off, but file_prefix length is limited by argparse
eal_args[RTE_DIM(eal_arg_strings)] = eal_args_mem[RTE_DIM(eal_arg_strings)] = strdup(eal_file_prefix);

return rte_eal_init(RTE_DIM(eal_args), eal_args);
}


void dp_secondary_eal_cleanup(void)
{
rte_eal_cleanup();
Expand Down
4 changes: 3 additions & 1 deletion tools/common/dp_secondary_eal.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
extern "C" {
#endif

int dp_secondary_eal_init(void);
#define DP_SECONDARY_FILE_PREFIX_DEFAULT ""

int dp_secondary_eal_init(const char *file_prefix);

void dp_secondary_eal_cleanup(void);

Expand Down
8 changes: 8 additions & 0 deletions tools/dump/dp_conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
"source": "opts.c",
"markdown": "../../docs/deployment/help_dpservice-dump.md",
"options": [
{
"lgopt": "file-prefix",
"arg": "PREFIX",
"help": "prefix for hugepage filenames",
"var": "eal_file_prefix",
"type": "char",
"array_size": 32
},
{
"lgopt": "drops",
"help": "show dropped packets",
Expand Down
2 changes: 1 addition & 1 deletion tools/dump/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ int main(int argc, char **argv)
break;
}

ret = dp_secondary_eal_init();
ret = dp_secondary_eal_init(dp_conf_get_eal_file_prefix());
if (DP_FAILED(ret)) {
fprintf(stderr, "Cannot init EAL %s\n", dp_strerror_verbose(ret));
return EXIT_FAILURE;
Expand Down
1 change: 1 addition & 0 deletions tools/dump/meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
dpservice_dump_sources = [
'main.c',
'../common/dp_secondary_eal.c',
'../../src/dp_argparse.c',
'../../src/dp_error.c',
'../../src/monitoring/dp_graphtrace_shared.c',
'../../src/monitoring/dp_pcap.c',
Expand Down
25 changes: 18 additions & 7 deletions tools/dump/opts.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ enum {
OPT_HELP = 'h',
OPT_VERSION = 'v',
_OPT_SHOPT_MAX = 255,
OPT_FILE_PREFIX,
OPT_DROPS,
OPT_NODES,
OPT_FILTER,
Expand All @@ -30,6 +31,7 @@ _OPT_SHOPT_MAX = 255,
static const struct option dp_conf_longopts[] = {
{ "help", 0, 0, OPT_HELP },
{ "version", 0, 0, OPT_VERSION },
{ "file-prefix", 1, 0, OPT_FILE_PREFIX },
{ "drops", 0, 0, OPT_DROPS },
{ "nodes", 1, 0, OPT_NODES },
{ "filter", 1, 0, OPT_FILTER },
Expand All @@ -38,9 +40,15 @@ static const struct option dp_conf_longopts[] = {
{ NULL, 0, 0, 0 }
};

static char eal_file_prefix[32];
static bool showing_drops = false;
static bool stop_mode = false;

const char *dp_conf_get_eal_file_prefix(void)
{
return eal_file_prefix;
}

bool dp_conf_is_showing_drops(void)
{
return showing_drops;
Expand All @@ -63,20 +71,23 @@ static int dp_argparse_opt_pcap(const char *arg);
static inline void dp_argparse_help(const char *progname, FILE *outfile)
{
fprintf(outfile, "Usage: %s [options]\n"
" -h, --help display this help and exit\n"
" -v, --version display version and exit\n"
" --drops show dropped packets\n"
" --nodes=REGEX show graph node traversal, limit to REGEX-matched nodes (empty string for all)\n"
" --filter=FILTER show only packets matching a pcap-style FILTER\n"
" --pcap=FILE write packets into a PCAP file\n"
" --stop do nothing, only make sure tracing is disabled in dp-service\n"
" -h, --help display this help and exit\n"
" -v, --version display version and exit\n"
" --file-prefix=PREFIX prefix for hugepage filenames\n"
" --drops show dropped packets\n"
" --nodes=REGEX show graph node traversal, limit to REGEX-matched nodes (empty string for all)\n"
" --filter=FILTER show only packets matching a pcap-style FILTER\n"
" --pcap=FILE write packets into a PCAP file\n"
" --stop do nothing, only make sure tracing is disabled in dp-service\n"
, progname);
}

static int dp_conf_parse_arg(int opt, const char *arg)
{
(void)arg; // if no option uses an argument, this would be unused
switch (opt) {
case OPT_FILE_PREFIX:
return dp_argparse_string(arg, eal_file_prefix, ARRAY_SIZE(eal_file_prefix));
case OPT_DROPS:
return dp_argparse_store_true(&showing_drops);
case OPT_NODES:
Expand Down
1 change: 1 addition & 0 deletions tools/dump/opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/* Please edit dp_conf.json and re-run the script to update this file. */
/***********************************************************************/

const char *dp_conf_get_eal_file_prefix(void);
bool dp_conf_is_showing_drops(void);
bool dp_conf_is_stop_mode(void);

Expand Down
8 changes: 8 additions & 0 deletions tools/inspect/dp_conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
"source": "opts.c",
"markdown": "../../docs/deployment/help_dpservice-inspect.md",
"options": [
{
"lgopt": "file-prefix",
"arg": "PREFIX",
"help": "prefix for hugepage filenames",
"var": "eal_file_prefix",
"type": "char",
"array_size": 32
},
{
"shopt": "o",
"lgopt": "output-format",
Expand Down
2 changes: 1 addition & 1 deletion tools/inspect/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ int main(int argc, char **argv)
break;
}

ret = dp_secondary_eal_init();
ret = dp_secondary_eal_init(dp_conf_get_eal_file_prefix());
if (DP_FAILED(ret)) {
fprintf(stderr, "Cannot init EAL %s\n", dp_strerror_verbose(ret));
return EXIT_FAILURE;
Expand Down
11 changes: 11 additions & 0 deletions tools/inspect/opts.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum {
OPT_TABLE = 't',
OPT_SOCKET = 's',
_OPT_SHOPT_MAX = 255,
OPT_FILE_PREFIX,
OPT_DUMP,
};

Expand All @@ -32,6 +33,7 @@ _OPT_SHOPT_MAX = 255,
static const struct option dp_conf_longopts[] = {
{ "help", 0, 0, OPT_HELP },
{ "version", 0, 0, OPT_VERSION },
{ "file-prefix", 1, 0, OPT_FILE_PREFIX },
{ "output-format", 1, 0, OPT_OUTPUT_FORMAT },
{ "table", 1, 0, OPT_TABLE },
{ "socket", 1, 0, OPT_SOCKET },
Expand Down Expand Up @@ -61,11 +63,17 @@ static const char *table_choices[] = {
"vni",
};

static char eal_file_prefix[32];
static enum dp_conf_output_format output_format = DP_CONF_OUTPUT_FORMAT_HUMAN;
static enum dp_conf_table table = DP_CONF_TABLE_LIST;
static int numa_socket = -1;
static bool dump = false;

const char *dp_conf_get_eal_file_prefix(void)
{
return eal_file_prefix;
}

enum dp_conf_output_format dp_conf_get_output_format(void)
{
return output_format;
Expand Down Expand Up @@ -97,6 +105,7 @@ static inline void dp_argparse_help(const char *progname, FILE *outfile)
fprintf(outfile, "Usage: %s [options]\n"
" -h, --help display this help and exit\n"
" -v, --version display version and exit\n"
" --file-prefix=PREFIX prefix for hugepage filenames\n"
" -o, --output-format=FORMAT format of the output: 'human' (default), 'table', 'csv' or 'json'\n"
" -t, --table=NAME hash table to choose: 'list' (default), 'conntrack', 'dnat', 'iface', 'lb', 'lb_id', 'portmap', 'portoverload', 'snat', 'vnf', 'vnf_rev' or 'vni'\n"
" -s, --socket=NUMBER NUMA socket to use\n"
Expand All @@ -108,6 +117,8 @@ static int dp_conf_parse_arg(int opt, const char *arg)
{
(void)arg; // if no option uses an argument, this would be unused
switch (opt) {
case OPT_FILE_PREFIX:
return dp_argparse_string(arg, eal_file_prefix, ARRAY_SIZE(eal_file_prefix));
case OPT_OUTPUT_FORMAT:
return dp_argparse_enum(arg, (int *)&output_format, output_format_choices, ARRAY_SIZE(output_format_choices));
case OPT_TABLE:
Expand Down
1 change: 1 addition & 0 deletions tools/inspect/opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enum dp_conf_table {
DP_CONF_TABLE_VNI,
};

const char *dp_conf_get_eal_file_prefix(void);
enum dp_conf_output_format dp_conf_get_output_format(void);
enum dp_conf_table dp_conf_get_table(void);
int dp_conf_get_numa_socket(void);
Expand Down

0 comments on commit 618d50c

Please sign in to comment.