From 636724e3089dade8f6cf2e9827fc434ab1a7a75c Mon Sep 17 00:00:00 2001 From: Felix Lu Date: Thu, 24 Mar 2016 11:14:30 -0400 Subject: [PATCH] Monitor mode: add option to hide status window This allows users to use the entire window for output. --- man/stap.1.in | 15 +++++++------ staprun/monitor.c | 55 +++++++++++++++++++++++++++++++---------------- 2 files changed, 46 insertions(+), 24 deletions(-) diff --git a/man/stap.1.in b/man/stap.1.in index ef652c05d..c91717d8f 100644 --- a/man/stap.1.in +++ b/man/stap.1.in @@ -792,24 +792,27 @@ of commands using the following keys: .RS .TP .BI c -resets all global variables to their initial values or zeroes them if they +Resets all global variables to their initial values or zeroes them if they did not have an initial value. .TP .BI s -rotates the attribute used to sort the list of probes. +Rotates the attribute used to sort the list of probes. .TP .BI t -brings up a prompt to allow toggling(on/off) of probes by index. Probe points +Brings up a prompt to allow toggling(on/off) of probes by index. Probe points are still affected by their conditions. .TP .BI r -resumes the script by toggling on all probes. +Resumes the script by toggling on all probes. .TP .BI p -pauses the script by toggling off all probes. +Pauses the script by toggling off all probes. +.TP +.BI x +Hides/shows the status window. This allows for more output to be seen. .TP .BI navigation-keys -the j/k/ArrowDown/ArrowUp keys can be used to scroll through the probe +The j/k/ArrowDown/ArrowUp keys can be used to scroll through the probe list and the d/u/PageDown/PageUp keys can be used to scroll through the module output. .RE diff --git a/staprun/monitor.c b/staprun/monitor.c index cc737f159..006f0bfca 100644 --- a/staprun/monitor.c +++ b/staprun/monitor.c @@ -61,6 +61,7 @@ static time_t start_time = 0; static int resized = 0; static int input = 0; /* fresh input received in monitor_input() */ static int rendered = 0; +static int status_hidden = 0; /* Forward declarations */ static int comp_index(const void *p1, const void *p2); @@ -174,17 +175,22 @@ static void handle_resize() usleep (500*1000); /* prevent too many allocations */ endwin(); refresh(); + if (monitor_status) - { - delwin(monitor_status); - monitor_status = newwin(LINES/2,COLS,0,0); - } + delwin(monitor_status); + /* Status window not needed when hidden */ + if (!status_hidden) + monitor_status = newwin(LINES/2,COLS,0,0); + if (monitor_output) - { - delwin(monitor_output); - monitor_output = newwin(LINES/2,COLS,LINES/2,0); - scrollok(monitor_output, TRUE); - } + delwin(monitor_output); + /* Use the entire screen if not displaying status */ + if (status_hidden) + monitor_output = newwin(LINES,COLS,0,0); + else + monitor_output = newwin(LINES/2,COLS,LINES/2,0); + + scrollok(monitor_output, TRUE); resized = 0; } @@ -227,13 +233,19 @@ void monitor_render(void) if (resized) handle_resize(); + /* Adjust scrolling to window height */ + getmaxyx(monitor_output, max_rows, max_cols); + output_scroll = MIN(MAX(0, h_queue.count-max_rows+1), output_scroll); + /* Render previously recorded output */ wclear(monitor_output); - getmaxyx(monitor_output, monitor_y, monitor_x); for (i = 0; i < h_queue.count-output_scroll; i++) wprintw(monitor_output, "%s", h_queue.lines[(h_queue.oldest+i) % MAX_HISTORY]); wrefresh(monitor_output); + if (status_hidden) + return; + if (!input && rendered && (elapsed_time = current_time - start_time) < monitor_interval) return; @@ -254,7 +266,8 @@ void monitor_render(void) wprintw(monitor_status, "c - Reset all global variables to initial state, zeroes if unset.\n"); wprintw(monitor_status, "s - Rotate sort columns for probes.\n"); wprintw(monitor_status, "t - Open a prompt to enter the index of a probe to toggle.\n"); - wprintw(monitor_status, "p/r Pause/Resume script by toggling off/on all probes.\n"); + wprintw(monitor_status, "p/r - Pause/Resume script by toggling off/on all probes.\n"); + wprintw(monitor_status, "x - Hide/Show the status window.\n"); wprintw(monitor_status, "q - Quit script.\n"); wprintw(monitor_status, "j/DownArrow - Scroll down the probe list.\n"); wprintw(monitor_status, "k/UpArrow - Scroll up the probe list.\n"); @@ -511,11 +524,13 @@ void monitor_input(void) } } + getmaxyx(monitor_output, max_rows, max_cols); + (void) max_cols; /* Unused */ switch (monitor_state) { - case normal: - case exited: + case normal: + case exited: ch = getch(); switch (ch) { @@ -530,17 +545,12 @@ void monitor_input(void) break; case 'd': /* Fallthrough */ case KEY_NPAGE: - getmaxyx(monitor_status, max_rows, max_cols); - (void) max_cols; /* Unused */ output_scroll -= max_rows-1; output_scroll = MAX(0, output_scroll); break; case 'u': /* Fallthrough */ case KEY_PPAGE: - getmaxyx(monitor_status, max_rows, max_cols); - (void) max_cols; /* Unused */ output_scroll += max_rows-1; - output_scroll = MIN(MAX(0, h_queue.count-max_rows+1), output_scroll); break; case 's': comp_fn_index++; @@ -557,6 +567,11 @@ void monitor_input(void) write_command("pause", 5); break; case 'q': + if (status_hidden) + { + status_hidden = 0; + handle_resize(); + } if (monitor_state == exited) cleanup_and_exit(0, 0 /* error_detected unavailable here */ ); else @@ -568,6 +583,10 @@ void monitor_input(void) case 'h': monitor_state = (monitor_state == exited) ? exited_help : help; break; + case 'x': + status_hidden ^= 1; + handle_resize(); + break; } if (ch != ERR) input = 1; -- 2.43.5