hostname list
authorJulien Desfossez <jdesfossez@efficios.com>
Thu, 30 Aug 2012 00:38:18 +0000 (20:38 -0400)
committerJulien Desfossez <jdesfossez@efficios.com>
Sat, 19 Oct 2013 16:02:38 +0000 (12:02 -0400)
Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
src/common.c
src/common.h
src/cursesdisplay.c
src/lttngtop.c

index 3d8fc4040880c9a4f4dfc95031eae7dc7bd28c74..bc3fff3d55b3e0d5023e3ff910658637fa82c435 100644 (file)
@@ -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);
+}
index 022f2083808811d0ac821a03440db6d57c5c662f..d3361939b81741334653dbdc85f9eb93544fdd66 100644 (file)
@@ -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 */
index 848703873fe52315aec6ee0d3cb6155330a73c89..2686c621d21f0453066a95e435ad79d7f750f06c 100644 (file)
@@ -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;
@@ -1589,6 +1682,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();
index 5cbdc0da6e015b4037d6308d379724368ec91d7e..69a05e15854853fd84fe63bed9d253b519ca5488 100644 (file)
@@ -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;
This page took 0.026643 seconds and 4 git commands to generate.