cleanup hostname list for filtering
authorJulien Desfossez <jdesfossez@efficios.com>
Wed, 29 Aug 2012 23:57:52 +0000 (19:57 -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/lttngtop.c
src/lttngtoptypes.h

index e3e814be972b26d5f7e099644e52ec667a7f7852..3d8fc4040880c9a4f4dfc95031eae7dc7bd28c74 100644 (file)
@@ -212,7 +212,7 @@ struct processtop* add_proc(struct lttngtop *ctx, int tid, char *comm,
                        free(newproc->hostname);
                }
                newproc->hostname = strdup(hostname);
-               if (lookup_hostname_list(hostname)) {
+               if (is_hostname_filtered(hostname)) {
                        add_filter_tid_list(tid, newproc);
                }
        }
@@ -236,7 +236,7 @@ struct processtop* update_proc(struct processtop* proc, int pid, int tid,
                }
                if (hostname && !proc->hostname) {
                        proc->hostname = strdup(hostname);
-                       if (lookup_hostname_list(hostname)) {
+                       if (is_hostname_filtered(hostname)) {
                                add_filter_tid_list(tid, proc);
                        }
                }
@@ -675,20 +675,22 @@ int *lookup_tid_list(int tid)
        return g_hash_table_lookup(tid_filter_list, (gpointer) &tid);
 }
 
-char *lookup_hostname_list(const char *hostname)
+struct host *lookup_hostname_list(const char *hostname)
 {
-       if (!hostname || !hostname_filter_list)
+       if (!hostname || !global_host_list)
                return NULL;
 
-       return g_hash_table_lookup(hostname_filter_list, (gpointer) hostname);
+       return g_hash_table_lookup(global_host_list, (gpointer) hostname);
 }
 
-void remove_hostname_list(const char *hostname)
+int is_hostname_filtered(const char *hostname)
 {
-       if (!hostname || !hostname_filter_list)
-               return;
+       struct host *host;
 
-       g_hash_table_remove(hostname_filter_list, (gpointer) hostname);
+       host = lookup_hostname_list(hostname);
+       if (host)
+               return host->filter;
+       return 0;
 }
 
 int *lookup_filter_tid_list(int tid)
index 7e11cc6c5f8b508fe566300be5d3b0a3a53dcf21..022f2083808811d0ac821a03440db6d57c5c662f 100644 (file)
@@ -31,12 +31,12 @@ sem_t goodtodisplay, goodtoupdate, timer, pause_sem, end_trace_sem, bootstrap;
 GPtrArray *copies; /* struct lttngtop */
 GHashTable *global_perf_liszt;
 GHashTable *global_filter_list;
+GHashTable *global_host_list;
 
 char *opt_tid;
 char *opt_hostname;
 char *opt_kprobes;
 GHashTable *tid_filter_list;
-GHashTable *hostname_filter_list;
 
 int toggle_filter;
 
@@ -86,9 +86,10 @@ struct tm format_timestamp(uint64_t timestamp);
 
 int *lookup_filter_tid_list(int tid);
 int *lookup_tid_list(int tid);
-char *lookup_hostname_list(const char *hostname);
 void remove_hostname_list(const char *hostname);
 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);
 
 #endif /* _COMMON_H */
index c31b9fd873644f8a3117ce5b001d3b4600a49c23..5cbdc0da6e015b4037d6308d379724368ec91d7e 100644 (file)
@@ -481,6 +481,7 @@ void init_lttngtop()
        copies = g_ptr_array_new();
        global_perf_liszt = g_hash_table_new(g_str_hash, g_str_equal);
        global_filter_list = g_hash_table_new(g_str_hash, g_str_equal);
+       global_host_list = g_hash_table_new(g_str_hash, g_str_equal);
 
        sem_init(&goodtodisplay, 0, 0);
        sem_init(&goodtoupdate, 0, 1);
@@ -633,14 +634,17 @@ static int parse_options(int argc, char **argv)
                                break;
                        case OPT_HOSTNAME:
                                toggle_filter = 1;
-                               hostname_filter_list = g_hash_table_new(g_str_hash,
-                                               g_str_equal);
                                tmp_str = strtok(opt_hostname, ",");
                                while (tmp_str) {
-                                       char *new_str = strdup(tmp_str);
-                                       g_hash_table_insert(hostname_filter_list,
-                                                       (gpointer) new_str,
-                                                       (gpointer) new_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);
                                        tmp_str = strtok(NULL, ",");
                                }
                                break;
index 21e65a2aea6b0bac4e1f5dc3db3258e116b5ad50..2642e816fe0d9b6b986fd278b113c31016096363 100644 (file)
@@ -190,8 +190,9 @@ struct kprobes {
        int count;
 };
 
-struct hosts {
+struct host {
        char *hostname;
+       int filter;
 };
 
 #endif /* LTTNGTOPTYPES_H */
This page took 0.026567 seconds and 4 git commands to generate.