summaryrefslogtreecommitdiff
path: root/ifpps.c
diff options
context:
space:
mode:
authorDaniel Borkmann <dborkman@redhat.com>2013-05-30 17:02:23 +0200
committerDaniel Borkmann <dborkman@redhat.com>2013-05-30 17:02:43 +0200
commit11eb8de6fbd8578305c57082139d72c4f46c0864 (patch)
treea1a8e4e79efcee8d55242f0ac131c94e9ad8250c /ifpps.c
parent0239434a6a58ba371ffee9a06b6b7f1e3b9ef72e (diff)
parentc2e6ac191eb0a721570bf4bcb747c08f6487c7aa (diff)
Merge branch 'master' of github.com:borkmann/netsniff-ng
Needed to let Git merge to not run into conflicts with Tobias' set of changes on ifpps resp. ifpps manpage. Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Diffstat (limited to 'ifpps.c')
-rw-r--r--ifpps.c39
1 files changed, 24 insertions, 15 deletions
diff --git a/ifpps.c b/ifpps.c
index 8d4a079..80ec3eb 100644
--- a/ifpps.c
+++ b/ifpps.c
@@ -23,9 +23,6 @@
#include "xio.h"
#include "built_in.h"
-/* Number of top hitter CPUs to display */
-#define TOP_CPUS 10
-
struct wifi_stat {
uint32_t bitrate;
int16_t link_qual, link_qual_max;
@@ -64,10 +61,11 @@ static int stats_loop = 0;
static WINDOW *stats_screen = NULL;
-static const char *short_options = "d:t:vhclp";
+static const char *short_options = "d:t:n:vhclp";
static const struct option long_options[] = {
{"dev", required_argument, NULL, 'd'},
{"interval", required_argument, NULL, 't'},
+ {"num-cpus", required_argument, NULL, 'n'},
{"promisc", no_argument, NULL, 'p'},
{"csv", no_argument, NULL, 'c'},
{"loop", no_argument, NULL, 'l'},
@@ -102,6 +100,8 @@ static void __noreturn help(void)
"Options:\n"
" -d|--dev <netdev> Device to fetch statistics for e.g., eth0\n"
" -t|--interval <time> Refresh time in ms (default 1000 ms)\n"
+ " -n|--num-cpus <num> Number of top hitter CPUs to display\n"
+ " in ncurses mode (default 10)\n"
" -p|--promisc Promiscuous mode\n"
" -c|--csv Output to terminal as Gnuplot-ready data\n"
" -l|--loop Continuous CSV output\n"
@@ -611,7 +611,7 @@ static void screen_init(WINDOW **screen)
}
static void screen_header(WINDOW *screen, const char *ifname, int *voff,
- uint64_t ms_interval)
+ uint64_t ms_interval, unsigned int top_cpus)
{
size_t len = 0;
char buff[64];
@@ -630,9 +630,9 @@ static void screen_header(WINDOW *screen, const char *ifname, int *voff,
link == 0 ? "no" : "yes");
mvwprintw(screen, (*voff)++, 2,
- "Kernel net/sys statistics for %s (%s%s), t=%lums, cpus=%u"
+ "Kernel net/sys statistics for %s (%s%s), t=%lums, cpus=%u/%u"
" ",
- ifname, drvinf.driver, buff, ms_interval, get_number_cpus());
+ ifname, drvinf.driver, buff, ms_interval, top_cpus, get_number_cpus());
}
static void screen_net_dev_rel(WINDOW *screen, const struct ifstat *rel,
@@ -769,20 +769,21 @@ static void screen_wireless(WINDOW *screen, const struct ifstat *rel,
}
static void screen_update(WINDOW *screen, const char *ifname, const struct ifstat *rel,
- const struct ifstat *abs, int *first, uint64_t ms_interval)
+ const struct ifstat *abs, int *first, uint64_t ms_interval,
+ unsigned int top_cpus)
{
int cpus, top, voff = 1, cvoff = 2;
curs_set(0);
cpus = get_number_cpus();
- top = min(cpus, TOP_CPUS);
+ top = min(cpus, top_cpus);
stats_top(rel, abs, cpus);
qsort(cpu_hits, cpus, sizeof(*cpu_hits), cmp_hits);
- screen_header(screen, ifname, &voff, ms_interval);
+ screen_header(screen, ifname, &voff, ms_interval, top_cpus);
voff++;
screen_net_dev_rel(screen, rel, &voff);
@@ -825,7 +826,8 @@ static void screen_end(void)
endwin();
}
-static int screen_main(const char *ifname, uint64_t ms_interval)
+static int screen_main(const char *ifname, uint64_t ms_interval,
+ unsigned int top_cpus)
{
int first = 1, key;
@@ -837,7 +839,7 @@ static int screen_main(const char *ifname, uint64_t ms_interval)
break;
screen_update(stats_screen, ifname, &stats_delta, &stats_new,
- &first, ms_interval);
+ &first, ms_interval, top_cpus);
stats_sample_generic(ifname, ms_interval);
}
@@ -982,7 +984,8 @@ static void term_csv_header(const char *ifname, const struct ifstat *abs,
fflush(stdout);
}
-static int term_main(const char *ifname, uint64_t ms_interval)
+static int term_main(const char *ifname, uint64_t ms_interval,
+ unsigned int top_cpus __maybe_unused)
{
int first = 1;
@@ -1004,9 +1007,11 @@ int main(int argc, char **argv)
{
short ifflags = 0;
int c, opt_index, ret, cpus, promisc = 0;
+ unsigned int top_cpus = 10;
uint64_t interval = 1000;
char *ifname = NULL;
- int (*func_main)(const char *ifname, uint64_t ms_interval) = screen_main;
+ int (*func_main)(const char *ifname, uint64_t ms_interval,
+ unsigned int top_cpus) = screen_main;
setfsuid(getuid());
setfsgid(getgid());
@@ -1026,6 +1031,9 @@ int main(int argc, char **argv)
case 't':
interval = strtoul(optarg, NULL, 10);
break;
+ case 'n':
+ top_cpus = strtoul(optarg, NULL, 10);
+ break;
case 'l':
stats_loop = 1;
break;
@@ -1068,6 +1076,7 @@ int main(int argc, char **argv)
register_signal(SIGHUP, signal_handler);
cpus = get_number_cpus();
+ top_cpus = min(top_cpus, cpus);
stats_alloc(&stats_old, cpus);
stats_alloc(&stats_new, cpus);
@@ -1077,7 +1086,7 @@ int main(int argc, char **argv)
if (promisc)
ifflags = enter_promiscuous_mode(ifname);
- ret = func_main(ifname, interval);
+ ret = func_main(ifname, interval, top_cpus);
if (promisc)
leave_promiscuous_mode(ifname, ifflags);