summaryrefslogtreecommitdiff
path: root/flowtop.c
diff options
context:
space:
mode:
authorVadim Kochan <vadim4j@gmail.com>2015-11-06 00:07:45 +0200
committerTobias Klauser <tklauser@distanz.ch>2015-11-06 09:32:56 +0100
commitb39b142f6b99074376fad020e65e22e42809b971 (patch)
tree25607173f0770ab50096359c0e19a70f0cef59da /flowtop.c
parenta5838d3ec8bc987930df68545e1e91374ee4fca7 (diff)
flowtop: Redraw screen in 1s if no key was pressed
Seems like screen is updating too frequently which may block some terminals, so lets do it once in 1s but only if no key was pressed. Signed-off-by: Vadim Kochan <vadim4j@gmail.com> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'flowtop.c')
-rw-r--r--flowtop.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/flowtop.c b/flowtop.c
index 2791a74..d4a8ad9 100644
--- a/flowtop.c
+++ b/flowtop.c
@@ -1161,6 +1161,8 @@ static void presenter_screen_update(WINDOW *screen, struct flow_list *fl,
static void presenter(void)
{
+ int time_sleep_us = 200000;
+ int time_passed_us = 0;
int skip_lines = 0;
WINDOW *screen;
@@ -1170,6 +1172,8 @@ static void presenter(void)
rcu_register_thread();
while (!sigint) {
+ bool do_redraw = true;
+
switch (getch()) {
case 'q':
sigint = 1;
@@ -1190,11 +1194,21 @@ static void presenter(void)
break;
default:
fflush(stdin);
+ do_redraw = false;
break;
}
- presenter_screen_update(screen, &flow_list, skip_lines);
- usleep(200000);
+ if (!do_redraw)
+ do_redraw = time_passed_us >= 1 * USEC_PER_SEC;
+
+ if (do_redraw) {
+ presenter_screen_update(screen, &flow_list, skip_lines);
+ time_passed_us = 0;
+ } else {
+ time_passed_us += time_sleep_us;
+ }
+
+ usleep(time_sleep_us);
}
rcu_unregister_thread();