From: Julien Desfossez Date: Thu, 30 Aug 2012 00:38:18 +0000 (-0400) Subject: hostname list X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=7121c2890c0e4fb9eca589c0dbb2dc02bf115a79;p=lttngtop.git hostname list Signed-off-by: Julien Desfossez --- diff --git a/src/common.c b/src/common.c index f52497c..10eb44e 100644 --- a/src/common.c +++ b/src/common.c @@ -215,6 +215,7 @@ struct processtop* add_proc(struct lttngtop *ctx, int tid, char *comm, if (is_hostname_filtered(hostname)) { add_filter_tid_list(tid, newproc); } + add_hostname_list(hostname, 0); } return newproc; @@ -239,6 +240,7 @@ struct processtop* update_proc(struct processtop* proc, int pid, int tid, if (is_hostname_filtered(hostname)) { add_filter_tid_list(tid, proc); } + add_hostname_list(hostname, 0); } } return proc; @@ -713,3 +715,18 @@ void remove_filter_tid_list(int tid) g_hash_table_remove(global_filter_list, (gpointer) (unsigned long) &tid); } + +void add_hostname_list(char *hostname, int filter) +{ + struct host *host; + + if (lookup_hostname_list(hostname)) + return; + + host = g_new0(struct host, 1); + host->hostname = strdup(hostname); + host->filter = filter; + g_hash_table_insert(global_host_list, + (gpointer) host->hostname, + (gpointer) host); +} diff --git a/src/common.h b/src/common.h index 022f208..d336193 100644 --- a/src/common.h +++ b/src/common.h @@ -91,5 +91,6 @@ void add_filter_tid_list(int tid, struct processtop *newproc); void remove_filter_tid_list(int tid); struct host *lookup_hostname_list(const char *hostname); int is_hostname_filtered(const char *hostname); +void add_hostname_list(char *hostname, int filter); #endif /* _COMMON_H */ diff --git a/src/cursesdisplay.c b/src/cursesdisplay.c index a933eff..9399209 100644 --- a/src/cursesdisplay.c +++ b/src/cursesdisplay.c @@ -62,6 +62,8 @@ int toggle_threads = 1; int toggle_virt = -1; int toggle_pause = -1; +int filter_host_panel = 0; + int max_center_lines; pthread_t keyboard_thread; @@ -1307,22 +1309,95 @@ void update_perf_pref(int *line_selected, int toggle_view, int toggle_sort) doupdate(); } +void update_hostname_pref(int *line_selected, int toggle_filter, int toggle_sort) +{ + int i; + struct host *host; + GList *hostlist; + int size; + + if (!data) + return; + if (pref_panel_window) { + del_panel(pref_panel); + delwin(pref_panel_window); + } + size = g_hash_table_size(global_host_list); + + pref_panel_window = create_window(size + 2, 30, 10, 10); + pref_panel = new_panel(pref_panel_window); + + werase(pref_panel_window); + box(pref_panel_window, 0 , 0); + set_window_title(pref_panel_window, "Hosts Preferences "); + wattron(pref_panel_window, A_BOLD); + mvwprintw(pref_panel_window, g_hash_table_size(global_host_list) + 1, 1, + " space : toggle filter"); + wattroff(pref_panel_window, A_BOLD); + + if (*line_selected > (size - 1)) + *line_selected = size - 1; + else if (*line_selected < 0) + *line_selected = 0; + + i = 0; + hostlist = g_list_first(g_hash_table_get_keys(global_host_list)); + while (hostlist) { + host = g_hash_table_lookup(global_host_list, hostlist->data); + if (i == *line_selected && toggle_filter == 1) { + host->filter = host->filter == 1 ? 0:1; + update_current_view(); + } + if (i == *line_selected) { + wattron(pref_panel_window, COLOR_PAIR(5)); + mvwhline(pref_panel_window, i + 1, 1, ' ', 30 - 2); + } + if (host->filter == 1) + wattron(pref_panel_window, A_BOLD); + mvwprintw(pref_panel_window, i + 1, 1, "[%c] %s", + host->filter == 1 ? 'x' : ' ', + (char *) hostlist->data); + wattroff(pref_panel_window, A_BOLD); + wattroff(pref_panel_window, COLOR_PAIR(5)); + i++; + hostlist = g_list_next(hostlist); + } + update_panels(); + doupdate(); +} + int update_preference_panel(int *line_selected, int toggle_view, int toggle_sort) { int ret = 0; switch(current_view) { case perf: - update_perf_pref(line_selected, toggle_view, toggle_sort); + if (filter_host_panel) + update_hostname_pref(line_selected, + toggle_view, toggle_sort); + else + update_perf_pref(line_selected, + toggle_view, toggle_sort); break; case cpu: - update_cpu_pref(line_selected, toggle_view, toggle_sort); + if (filter_host_panel) + update_hostname_pref(line_selected, + toggle_view, toggle_sort); + else + update_cpu_pref(line_selected, + toggle_view, toggle_sort); break; case iostream: - update_iostream_pref(line_selected, toggle_view, toggle_sort); + if (filter_host_panel) + update_hostname_pref(line_selected, + toggle_view, toggle_sort); + else + update_iostream_pref(line_selected, + toggle_view, toggle_sort); break; case process_details: - update_process_detail_pref(line_selected, toggle_view, toggle_sort); + update_process_detail_pref(line_selected, + toggle_view, toggle_sort); break; default: ret = -1; @@ -1357,7 +1432,6 @@ int update_sort(int *line_selected) return ret; } - void toggle_pref_panel(void) { int ret; @@ -1376,6 +1450,25 @@ void toggle_pref_panel(void) doupdate(); } +void toggle_host_panel(void) +{ + int ret; + + filter_host_panel = filter_host_panel ? 0 : 1; + if (pref_panel_visible) { + hide_panel(pref_panel); + pref_panel_visible = 0; + } else { + ret = update_preference_panel(&pref_line_selected, 0, 0); + if (ret < 0) + return; + show_panel(pref_panel); + pref_panel_visible = 1; + } + update_panels(); + doupdate(); +} + void display(unsigned int index) { last_display_index = index; @@ -1588,6 +1681,9 @@ void *handle_keyboard(void *p) max_elements = data->process_table->len; update_current_view(); break; + case 'h': + toggle_host_panel(); + break; case 't': toggle_threads *= -1; update_current_view(); diff --git a/src/lttngtop.c b/src/lttngtop.c index 1799858..5b5fbea 100644 --- a/src/lttngtop.c +++ b/src/lttngtop.c @@ -636,15 +636,7 @@ static int parse_options(int argc, char **argv) toggle_filter = 1; tmp_str = strtok(opt_hostname, ","); while (tmp_str) { -// char *new_str = strdup(tmp_str); - struct host *host; - - host = g_new0(struct host, 1); - host->hostname = strdup(tmp_str); - host->filter = 1; - g_hash_table_insert(global_host_list, - (gpointer) host->hostname, - (gpointer) host); + add_hostname_list(tmp_str, 1); tmp_str = strtok(NULL, ","); } break;