There's no reason to print counters of given interface after every
packet received. Print counters only when screen update is needed.
This lowers CPU utilization from 23% to 15% for roughly the same
workload.
Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/ifstats.c | 9 ++++-----
1 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/src/ifstats.c b/src/ifstats.c
index 8214838..df43afe 100644
--- a/src/ifstats.c
+++ b/src/ifstats.c
@@ -302,15 +302,13 @@ static void printifentry(struct iflist *ptmp, WINDOW * win, unsigned
int idx)
wprintw(win, "%7lu", ptmp->badtotal);
}
-static void preparescreen(struct iftab *table)
+static void print_if_entries(struct iftab *table)
{
struct iflist *ptmp = table->head;
unsigned int i = 1;
unsigned int winht = LINES - 4;
- table->firstvisible = table->head;
-
do {
printifentry(ptmp, table->statwin, 1);
@@ -501,7 +499,8 @@ void ifstats(time_t facilitytime)
"******** General interface statistics started ********");
}
- preparescreen(&table);
+ table.firstvisible = table.head;
+ print_if_entries(&table);
update_panels();
doupdate();
@@ -544,6 +543,7 @@ void ifstats(time_t facilitytime)
}
}
if (screen_update_needed(&tv, &updtime)) {
+ print_if_entries(&table);
update_panels();
doupdate();
@@ -624,7 +624,6 @@ void ifstats(time_t facilitytime)
} else {
(ptmp->noniptotal)++;
}
- printifentry(ptmp, table.statwin, idx);
}
close(fd);
--
1.7.8.4