From: Julien Desfossez Date: Wed, 29 Aug 2012 23:57:52 +0000 (-0400) Subject: cleanup hostname list for filtering X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=3a8dcb1b8028fca2a581198c8b0e4a58c1a22897;p=lttngtop.git cleanup hostname list for filtering Signed-off-by: Julien Desfossez --- diff --git a/src/common.c b/src/common.c index 95f0210..f52497c 100644 --- a/src/common.c +++ b/src/common.c @@ -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) diff --git a/src/common.h b/src/common.h index 7e11cc6..022f208 100644 --- a/src/common.h +++ b/src/common.h @@ -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 */ diff --git a/src/lttngtop.c b/src/lttngtop.c index 6cee426..1799858 100644 --- a/src/lttngtop.c +++ b/src/lttngtop.c @@ -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; diff --git a/src/lttngtoptypes.h b/src/lttngtoptypes.h index 21e65a2..2642e81 100644 --- a/src/lttngtoptypes.h +++ b/src/lttngtoptypes.h @@ -190,8 +190,9 @@ struct kprobes { int count; }; -struct hosts { +struct host { char *hostname; + int filter; }; #endif /* LTTNGTOPTYPES_H */