diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2013-05-30 16:01:16 +0200 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2013-05-30 16:04:01 +0200 |
commit | 8ecf69c3ded4edaa164ed1d645629c1011de44a9 (patch) | |
tree | e3924f39883ac2efb6ff53add3a2c4a34965e6eb /ifpps.c | |
parent | 29517820a0d65345fe906c9ce8780e86e1059198 (diff) |
ifpps: Allocate cpu dependent stats in one place
Avoid code duplication by allocating the stats arrays dependent on the
number of CPUs in main() rather than screen_main() and term_main().
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'ifpps.c')
-rw-r--r-- | ifpps.c | 24 |
1 files changed, 9 insertions, 15 deletions
@@ -828,13 +828,6 @@ static void screen_end(void) static int screen_main(const char *ifname, uint64_t ms_interval) { int first = 1, key; - int cpus = get_number_cpus(); - - stats_alloc(&stats_old, cpus); - stats_alloc(&stats_new, cpus); - stats_alloc(&stats_delta, cpus); - - cpu_hits = xzmalloc(cpus * sizeof(*cpu_hits)); screen_init(&stats_screen); @@ -992,13 +985,6 @@ static void term_csv_header(const char *ifname, const struct ifstat *abs, static int term_main(const char *ifname, uint64_t ms_interval) { int first = 1; - int cpus = get_number_cpus(); - - stats_alloc(&stats_old, cpus); - stats_alloc(&stats_new, cpus); - stats_alloc(&stats_delta, cpus); - - cpu_hits = xzmalloc(cpus * sizeof(*cpu_hits)); do { stats_sample_generic(ifname, ms_interval); @@ -1017,7 +1003,7 @@ static int term_main(const char *ifname, uint64_t ms_interval) int main(int argc, char **argv) { short ifflags = 0; - int c, opt_index, ret, promisc = 0; + int c, opt_index, ret, cpus, promisc = 0; uint64_t interval = 1000; char *ifname = NULL; int (*func_main)(const char *ifname, uint64_t ms_interval) = screen_main; @@ -1081,6 +1067,14 @@ int main(int argc, char **argv) register_signal(SIGINT, signal_handler); register_signal(SIGHUP, signal_handler); + cpus = get_number_cpus(); + + stats_alloc(&stats_old, cpus); + stats_alloc(&stats_new, cpus); + stats_alloc(&stats_delta, cpus); + + cpu_hits = xzmalloc(cpus * sizeof(*cpu_hits)); + if (promisc) ifflags = enter_promiscuous_mode(ifname); ret = func_main(ifname, interval); |