Skip to content

Commit c239f1a

Browse files
committed
Add --maxcount to dpservice-dump
1 parent 7d90b13 commit c239f1a

File tree

5 files changed

+36
-1
lines changed

5 files changed

+36
-1
lines changed

docs/deployment/help_dpservice-dump.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
| --nodes | REGEX | show graph node traversal, limit to REGEX-matched nodes (empty string for all) | |
1010
| --filter | FILTER | show only packets matching a pcap-style FILTER | |
1111
| --pcap | FILE | write packets into a PCAP file | |
12+
| -c, --maxcount | COUNT | exit after receiving COUNT packets | |
1213
| --stop | None | do nothing, only make sure tracing is disabled in dp-service | |
1314

1415
> This file has been generated by dp_conf_generate.py. As such it should fully reflect the output of `--help`.

tools/dump/dp_conf.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@
3333
"help": "write packets into a PCAP file",
3434
"arg": "FILE"
3535
},
36+
{
37+
"shopt": "c",
38+
"lgopt": "maxcount",
39+
"help": "exit after receiving COUNT packets",
40+
"arg": "COUNT",
41+
"var": "count",
42+
"type": "int",
43+
"min": 0,
44+
"default": 0
45+
},
3646
{
3747
"lgopt": "stop",
3848
"help": "do nothing, only make sure tracing is disabled in dp-service",

tools/dump/main.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <fcntl.h>
55
#include <getopt.h>
6+
#include <limits.h>
67
#include <regex.h>
78
#include <signal.h>
89
#include <stdio.h>
@@ -47,6 +48,8 @@ static char packet_filter[DP_GRAPHTRACE_FILTER_MAXLEN] = "";
4748
static bool interrupt = false;
4849
static bool primary_alive = false;
4950

51+
static unsigned int packet_limit = UINT_MAX;
52+
5053
// optimization to prevent 'if (pcap) pcap_dump(); else print_packet();' in a loop
5154
static void print_packet(struct dp_pcap *dp_pcap, struct rte_mbuf *m, struct timeval *timestamp);
5255
static void (*dump_func)(struct dp_pcap *dp_pcap, struct rte_mbuf *m, struct timeval *timestamp) = print_packet;
@@ -128,9 +131,14 @@ static int dp_graphtrace_dump(struct dp_graphtrace *graphtrace)
128131
// TODO timestamp should be sent by dpservice
129132
// ignoring failure for speed
130133
gettimeofday(&timestamp, NULL);
131-
for (unsigned int i = 0; i < received; ++i)
134+
for (unsigned int i = 0; i < received; ++i) {
132135
dump_func(&dp_pcap, (struct rte_mbuf *)objs[i], &timestamp);
136+
if (--packet_limit == 0)
137+
break;
138+
}
133139
rte_mempool_put_bulk(graphtrace->mempool, objs, received);
140+
if (packet_limit == 0)
141+
break;
134142
}
135143
if (available == 0)
136144
usleep(WAIT_INTERVAL);
@@ -293,6 +301,9 @@ static int do_graphtrace(void)
293301
}
294302
}
295303

304+
if (dp_conf_get_count() > 0)
305+
packet_limit = dp_conf_get_count();
306+
296307
ret = dp_graphtrace_main();
297308

298309
if (pcap_path)

tools/dump/opts.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
enum {
1818
OPT_HELP = 'h',
1919
OPT_VERSION = 'v',
20+
OPT_MAXCOUNT = 'c',
2021
_OPT_SHOPT_MAX = 255,
2122
OPT_FILE_PREFIX,
2223
OPT_DROPS,
@@ -27,6 +28,7 @@ _OPT_SHOPT_MAX = 255,
2728
};
2829

2930
#define OPTSTRING ":hv" \
31+
"c:" \
3032

3133
static const struct option dp_conf_longopts[] = {
3234
{ "help", 0, 0, OPT_HELP },
@@ -36,12 +38,14 @@ static const struct option dp_conf_longopts[] = {
3638
{ "nodes", 1, 0, OPT_NODES },
3739
{ "filter", 1, 0, OPT_FILTER },
3840
{ "pcap", 1, 0, OPT_PCAP },
41+
{ "maxcount", 1, 0, OPT_MAXCOUNT },
3942
{ "stop", 0, 0, OPT_STOP },
4043
{ NULL, 0, 0, 0 }
4144
};
4245

4346
static char eal_file_prefix[32];
4447
static bool showing_drops = false;
48+
static int count = 0;
4549
static bool stop_mode = false;
4650

4751
const char *dp_conf_get_eal_file_prefix(void)
@@ -54,6 +58,11 @@ bool dp_conf_is_showing_drops(void)
5458
return showing_drops;
5559
}
5660

61+
int dp_conf_get_count(void)
62+
{
63+
return count;
64+
}
65+
5766
bool dp_conf_is_stop_mode(void)
5867
{
5968
return stop_mode;
@@ -78,6 +87,7 @@ static inline void dp_argparse_help(const char *progname, FILE *outfile)
7887
" --nodes=REGEX show graph node traversal, limit to REGEX-matched nodes (empty string for all)\n"
7988
" --filter=FILTER show only packets matching a pcap-style FILTER\n"
8089
" --pcap=FILE write packets into a PCAP file\n"
90+
" -c, --maxcount=COUNT exit after receiving COUNT packets\n"
8191
" --stop do nothing, only make sure tracing is disabled in dp-service\n"
8292
, progname);
8393
}
@@ -96,6 +106,8 @@ static int dp_conf_parse_arg(int opt, const char *arg)
96106
return dp_argparse_opt_filter(arg);
97107
case OPT_PCAP:
98108
return dp_argparse_opt_pcap(arg);
109+
case OPT_MAXCOUNT:
110+
return dp_argparse_int(arg, &count, 0, INT_MAX);
99111
case OPT_STOP:
100112
return dp_argparse_store_true(&stop_mode);
101113
default:

tools/dump/opts.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
const char *dp_conf_get_eal_file_prefix(void);
1212
bool dp_conf_is_showing_drops(void);
13+
int dp_conf_get_count(void);
1314
bool dp_conf_is_stop_mode(void);
1415

1516
enum dp_conf_runmode {

0 commit comments

Comments
 (0)