From 30b646c4e7aab1e1bee8fef60619a61bd80bedad Mon Sep 17 00:00:00 2001 From: Julien Desfossez Date: Wed, 15 Aug 2012 22:03:24 -0400 Subject: [PATCH] hash table for processes and fix path for traces Signed-off-by: Julien Desfossez --- src/common.c | 26 +++++++++++++++++--------- src/lttngtop.c | 7 +++++-- src/lttngtoptypes.h | 1 + 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/common.c b/src/common.c index bff5b00..43e258b 100644 --- a/src/common.c +++ b/src/common.c @@ -103,20 +103,15 @@ char *get_context_comm(const struct bt_ctf_event *event) /* * To get the parent process, put the pid in the tid field * because the parent process gets pid = tid - * - * FIXME : char *comm useful ??? */ struct processtop *find_process_tid(struct lttngtop *ctx, int tid, char *comm) { - gint i; struct processtop *tmp; - for (i = 0; i < ctx->process_table->len; i++) { - tmp = g_ptr_array_index(ctx->process_table, i); - if (tmp && tmp->tid == tid) - return tmp; - } - return NULL; + tmp = g_hash_table_lookup(ctx->process_hash_table, + (gconstpointer) (unsigned long) tid); + + return tmp; } struct processtop* add_proc(struct lttngtop *ctx, int tid, char *comm, @@ -142,6 +137,8 @@ struct processtop* add_proc(struct lttngtop *ctx, int tid, char *comm, newproc->threads = g_ptr_array_new(); newproc->perf = g_hash_table_new(g_str_hash, g_str_equal); g_ptr_array_add(ctx->process_table, newproc); + g_hash_table_insert(ctx->process_hash_table, + (gpointer) (unsigned long) tid, newproc); ctx->nbnewthreads++; ctx->nbthreads++; @@ -175,6 +172,9 @@ void death_proc(struct lttngtop *ctx, int tid, char *comm, { struct processtop *tmp; tmp = find_process_tid(ctx, tid, comm); + + g_hash_table_remove(ctx->process_hash_table, + (gpointer) (unsigned long) tid); if (tmp && strcmp(tmp->comm, comm) == 0) { tmp->death = timestamp; ctx->nbdeadthreads++; @@ -283,6 +283,11 @@ void copy_perf_counter(gpointer key, gpointer value, gpointer new_table) g_hash_table_insert((GHashTable *) new_table, strdup(key), newperf); } +void copy_process_table(gpointer key, gpointer value, gpointer new_table) +{ + g_hash_table_insert((GHashTable *) new_table, key, value); +} + void rotate_perfcounter() { int i; struct processtop *tmp; @@ -360,6 +365,9 @@ struct lttngtop* get_copy_lttngtop(unsigned long start, unsigned long end) dst->process_table = g_ptr_array_new(); dst->files_table = g_ptr_array_new(); dst->cpu_table = g_ptr_array_new(); + dst->process_hash_table = g_hash_table_new(g_direct_hash, g_direct_equal); + g_hash_table_foreach(lttngtop.process_hash_table, copy_process_table, + dst->process_hash_table); rotate_cputime(end); diff --git a/src/lttngtop.c b/src/lttngtop.c index 7c0ec53..9ac8d39 100644 --- a/src/lttngtop.c +++ b/src/lttngtop.c @@ -343,6 +343,7 @@ void init_lttngtop() copies = g_ptr_array_new(); global_perf_liszt = g_hash_table_new(g_str_hash, g_str_equal); + sem_init(&goodtodisplay, 0, 0); sem_init(&goodtoupdate, 0, 1); sem_init(&timer, 0, 1); @@ -355,6 +356,8 @@ void init_lttngtop() lttngtop.nbthreads = 0; lttngtop.nbfiles = 0; + lttngtop.process_hash_table = g_hash_table_new(g_direct_hash, + g_direct_equal); lttngtop.process_table = g_ptr_array_new(); lttngtop.files_table = g_ptr_array_new(); lttngtop.cpu_table = g_ptr_array_new(); @@ -770,12 +773,12 @@ void *live_consume() if (!metadata_ready) { sem_wait(&metadata_available); - if (access("/tmp/livesession/kernel/metadata", F_OK) != 0) { + if (access("/tmp/livesession/metadata", F_OK) != 0) { fprintf(stderr,"no metadata\n"); return NULL; } metadata_ready = 1; - metadata_fp = fopen("/tmp/livesession/kernel/metadata", "r"); + metadata_fp = fopen("/tmp/livesession/metadata", "r"); } if (!trace_opened) { diff --git a/src/lttngtoptypes.h b/src/lttngtoptypes.h index c69ea01..e01f804 100644 --- a/src/lttngtoptypes.h +++ b/src/lttngtoptypes.h @@ -21,6 +21,7 @@ #include struct lttngtop { + GHashTable *process_hash_table; /* struct processtop */ GPtrArray *process_table; /* struct processtop */ GPtrArray *files_table; /* struct files */ GPtrArray *cpu_table; /* struct cputime */ -- 2.34.1