hash table for processes and fix path for traces
authorJulien Desfossez <jdesfossez@efficios.com>
Thu, 16 Aug 2012 02:03:24 +0000 (22:03 -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/lttngtop.c
src/lttngtoptypes.h

index bff5b00715685b312c7ad3745811776b7a473e3d..43e258be683d49bc8101fdd8654d9898b20df0de 100644 (file)
@@ -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);
 
index 7c0ec53b71c34f280bde95b8698bff32c5763fff..9ac8d39c1c9f8c262a9fea039de0c7c9b663e339 100644 (file)
@@ -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) {
index c69ea0192c56657b1eb99ab850f7324fec5c1dd8..e01f804f19039a8004623f214c3ff5699fc7a96f 100644 (file)
@@ -21,6 +21,7 @@
 #include <glib.h>
 
 struct lttngtop {
+       GHashTable *process_hash_table; /* struct processtop */
        GPtrArray *process_table;       /* struct processtop */
        GPtrArray *files_table;         /* struct files */
        GPtrArray *cpu_table;           /* struct cputime */
This page took 0.034643 seconds and 4 git commands to generate.