update compat
[lttv.git] / trunk / lttv / lttv / lttv / state.c
index 1a3d907db0adfb81f6447485c5d1ae1f31afc4eb..821ea4d8112e70464777194f880398598e63aaa9 100644 (file)
@@ -32,6 +32,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <ltt/ltt-private.h>
+#include <inttypes.h>
 
 /* Comment :
  * Mathieu Desnoyers
@@ -58,6 +59,7 @@ GQuark
     LTT_CHANNEL_SYSCALL_STATE,
     LTT_CHANNEL_TASK_STATE,
     LTT_CHANNEL_VM_STATE,
+    LTT_CHANNEL_KPROBE_STATE,
     LTT_CHANNEL_FS,
     LTT_CHANNEL_KERNEL,
     LTT_CHANNEL_MM,
@@ -69,6 +71,10 @@ GQuark
 GQuark 
     LTT_EVENT_SYSCALL_ENTRY,
     LTT_EVENT_SYSCALL_EXIT,
+    LTT_EVENT_PAGE_FAULT_NOSEM_ENTRY,
+    LTT_EVENT_PAGE_FAULT_NOSEM_EXIT,
+    LTT_EVENT_PAGE_FAULT_ENTRY,
+    LTT_EVENT_PAGE_FAULT_EXIT,
     LTT_EVENT_TRAP_ENTRY,
     LTT_EVENT_TRAP_EXIT,
     LTT_EVENT_IRQ_ENTRY,
@@ -91,7 +97,9 @@ GQuark
     LTT_EVENT_REQUEST_COMPLETE,
     LTT_EVENT_LIST_INTERRUPT,
     LTT_EVENT_SYS_CALL_TABLE,
-    LTT_EVENT_SOFTIRQ_VEC;
+    LTT_EVENT_SOFTIRQ_VEC,
+    LTT_EVENT_KPROBE_TABLE,
+    LTT_EVENT_KPROBE;
 
 /* Fields Quarks */
 
@@ -122,7 +130,8 @@ GQuark
     LTT_FIELD_ACTION,
     LTT_FIELD_ID,
     LTT_FIELD_ADDRESS,
-    LTT_FIELD_SYMBOL;
+    LTT_FIELD_SYMBOL,
+    LTT_FIELD_IP;
 
 LttvExecutionMode
   LTTV_STATE_MODE_UNKNOWN,
@@ -218,6 +227,23 @@ static void bdevstate_free_cb(gpointer key, gpointer value, gpointer user_data);
 static LttvBdevState *bdevstate_copy(LttvBdevState *bds);
 
 
+#if (__SIZEOF_LONG__ == 4)
+guint guint64_hash(gconstpointer key)
+{
+       guint64 ukey = *(const guint64 *)key;
+
+       return (guint)ukey ^ (guint)(ukey >> 32);
+}
+
+gboolean guint64_equal(gconstpointer a, gconstpointer b)
+{
+       guint64 ua = *(const guint64 *)a;
+       guint64 ub = *(const guint64 *)b;
+
+       return ua == ub;
+}
+#endif
+
 void lttv_state_save(LttvTraceState *self, LttvAttribute *container)
 {
   LTTV_TRACE_STATE_GET_CLASS(self)->state_save(self, container);
@@ -317,6 +343,18 @@ static void expand_syscall_table(LttvTraceState *ts, int id)
   ts->nb_syscalls = new_nb;
 }
 
+static void expand_kprobe_table(LttvTraceState *ts, guint64 ip, char *symbol)
+{
+#if (__SIZEOF_LONG__ == 4)
+  guint64 *ip_ptr = g_new(guint64, 1);
+  g_hash_table_insert(ts->kprobe_hash, ip_ptr,
+    (gpointer)(glong)g_quark_from_string(symbol));
+#else
+  g_hash_table_insert(ts->kprobe_hash, (gpointer)ip,
+    (gpointer)(glong)g_quark_from_string(symbol));
+#endif
+}
+
 static void expand_trap_table(LttvTraceState *ts, int id)
 {
   guint new_nb = check_expand(ts->nb_traps, id);
@@ -646,12 +684,12 @@ init(LttvTracesetState *self, LttvTraceset *ts)
         /* It's a Usertrace */
         guint tid = ltt_tracefile_tid(tfcs->parent.tf);
         GTree *usertrace_tree = (GTree*)g_hash_table_lookup(tcs->usertraces,
-            (gconstpointer)tid);
+                                                           GUINT_TO_POINTER(tid));
         if(!usertrace_tree) {
           usertrace_tree = g_tree_new_full(compare_usertraces,
               NULL, free_usertrace_key, NULL);
           g_hash_table_insert(tcs->usertraces,
-              (gpointer)tid, usertrace_tree);
+                             GUINT_TO_POINTER(tid), usertrace_tree);
         }
         LttTime *timestamp = g_new(LttTime, 1);
         *timestamp = ltt_interpolate_time_from_tsc(tfcs->parent.tf,
@@ -761,7 +799,7 @@ static void write_process_state(gpointer key, gpointer value,
 
   for(i = 0 ; i < process->user_stack->len; i++) {
     address = g_array_index(process->user_stack, guint64, i);
-    fprintf(fp, "    <USER_STACK ADDRESS=\"%llu\"/>\n",
+    fprintf(fp, "    <USER_STACK ADDRESS=\"%" PRIu64 "\"/>\n",
             address);
   }
 
@@ -815,7 +853,7 @@ void lttv_state_write(LttvTraceState *self, LttTime t, FILE *fp)
     else {
       ltt_event_position(e, ep);
       ltt_event_position_get(ep, &tf, &nb_block, &offset, &tsc);
-      fprintf(fp, " BLOCK=%u OFFSET=%u TSC=%llu/>\n", nb_block, offset,
+      fprintf(fp, " BLOCK=%u OFFSET=%u TSC=%" PRIu64 "/>\n", nb_block, offset,
           tsc);
     }
   }
@@ -1536,7 +1574,7 @@ static void state_save(LttvTraceState *self, LttvAttribute *container)
       guint64 tsc;
       LttTracefile *tf;
       ltt_event_position_get(ep, &tf, &nb_block, &offset, &tsc);
-      g_info("Block %u offset %u tsc %llu time %lu.%lu", nb_block, offset,
+      g_info("Block %u offset %u tsc %" PRIu64 " time %lu.%lu", nb_block, offset,
           tsc,
           tfcs->parent.timestamp.tv_sec, tfcs->parent.timestamp.tv_nsec);
     }
@@ -1860,6 +1898,7 @@ typedef struct _LttvNameTables {
   guint nb_irqs;
   GQuark *soft_irq_names;
   guint nb_softirqs;
+  GHashTable *kprobe_hash;
 } LttvNameTables;
 
 
@@ -1923,6 +1962,11 @@ create_name_tables(LttvTraceState *tcs)
         LTT_CHANNEL_KERNEL,
         LTT_EVENT_TRAP_ENTRY,
         FIELD_ARRAY(LTT_FIELD_TRAP_ID),
+        NULL, NULL, &hooks) ||
+     !lttv_trace_find_hook(tcs->parent.t,
+        LTT_CHANNEL_KERNEL,
+        LTT_EVENT_PAGE_FAULT_ENTRY,
+        FIELD_ARRAY(LTT_FIELD_TRAP_ID),
         NULL, NULL, &hooks)) {
 
 //    th = lttv_trace_hook_get_first(&th);
@@ -1989,6 +2033,13 @@ create_name_tables(LttvTraceState *tcs)
   g_array_free(hooks, TRUE);
 
   g_string_free(fe_name, TRUE);
+
+#if (__SIZEOF_LONG__ == 4)
+  name_tables->kprobe_hash = g_hash_table_new_full(guint64_hash, guint64_equal,
+    g_free, NULL);
+#else
+  name_tables->kprobe_hash = g_hash_table_new(g_direct_hash, g_direct_equal);
+#endif
 }
 
 
@@ -2012,6 +2063,7 @@ get_name_tables(LttvTraceState *tcs)
   tcs->soft_irq_names = name_tables->soft_irq_names;
   tcs->nb_irqs = name_tables->nb_irqs;
   tcs->nb_soft_irqs = name_tables->nb_softirqs;
+  tcs->kprobe_hash = name_tables->kprobe_hash;
 }
 
 
@@ -2033,6 +2085,7 @@ free_name_tables(LttvTraceState *tcs)
   if(name_tables->irq_names) g_free(name_tables->irq_names);
   if(name_tables->soft_irq_names) g_free(name_tables->soft_irq_names);
   if(name_tables) g_free(name_tables);
+  if(name_tables) g_hash_table_destroy(name_tables->kprobe_hash);
 } 
 
 #ifdef HASH_TABLE_DEBUG
@@ -2242,7 +2295,8 @@ static LttvTracefileState *ltt_state_usertrace_find(LttvTraceState *tcs,
    * timestamp the lowest, but higher or equal to "timestamp". */
   res.time = timestamp;
   res.best = NULL;
-  GTree *usertrace_tree = g_hash_table_lookup(tcs->usertraces, (gpointer)pid);
+  GTree *usertrace_tree = g_hash_table_lookup(tcs->usertraces,
+                                             GUINT_TO_POINTER(pid));
   if(usertrace_tree) {
     g_tree_search(usertrace_tree, search_usertrace, &res);
     if(res.best)
@@ -2571,7 +2625,7 @@ static gboolean soft_irq_raise(void *hook_data, void *call_data)
   } else {
     /* Fixup an incomplete irq table */
     GString *string = g_string_new("");
-    g_string_printf(string, "softirq %llu", softirq);
+    g_string_printf(string, "softirq %" PRIu64, softirq);
     submode = g_quark_from_string(string->str);
     g_string_free(string, TRUE);
   }
@@ -2708,7 +2762,7 @@ static void pop_function(LttvTracefileState *tfs, guint64 funcptr)
   if(process->current_function != funcptr){
     g_info("Different functions (%lu.%09lu): ignore it\n",
         tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec);
-    g_info("process state has %llu when pop_function is %llu\n",
+    g_info("process state has %" PRIu64 " when pop_function is %" PRIu64 "\n",
         process->current_function, funcptr);
     g_info("{ %u, %u, %s, %s, %s }\n",
         process->pid,
@@ -2779,6 +2833,23 @@ static gboolean dump_syscall(void *hook_data, void *call_data)
   return FALSE;
 }
 
+static gboolean dump_kprobe(void *hook_data, void *call_data)
+{
+  LttvTracefileState *s = (LttvTracefileState *)call_data;
+  LttvTraceState *ts = (LttvTraceState*)s->parent.t_context;
+  LttEvent *e = ltt_tracefile_get_event(s->parent.tf);
+  LttvTraceHook *th = (LttvTraceHook *)hook_data;
+  guint64 ip;
+  char *symbol;
+
+  ip = ltt_event_get_long_unsigned(e, lttv_trace_get_hook_field(th, 0));
+  symbol = ltt_event_get_string(e, lttv_trace_get_hook_field(th, 1));
+
+  expand_kprobe_table(ts, ip, symbol);
+
+  return FALSE;
+}
+
 static gboolean dump_softirq(void *hook_data, void *call_data)
 {
   LttvTracefileState *s = (LttvTracefileState *)call_data;
@@ -3391,7 +3462,7 @@ void lttv_state_add_event_hooks(LttvTracesetState *self)
     /* Find the eventtype id for the following events and register the
        associated by id hooks. */
 
-    hooks = g_array_sized_new(FALSE, FALSE, sizeof(LttvTraceHook), 19);
+    hooks = g_array_sized_new(FALSE, FALSE, sizeof(LttvTraceHook), 20);
     //hooks = g_array_set_size(hooks, 19); // Max possible number of hooks.
     //hn = 0;
 
@@ -3419,6 +3490,30 @@ void lttv_state_add_event_hooks(LttvTracesetState *self)
         NULL,
         trap_exit, NULL, &hooks);
 
+    lttv_trace_find_hook(ts->parent.t,
+        LTT_CHANNEL_KERNEL,
+        LTT_EVENT_PAGE_FAULT_ENTRY,
+        FIELD_ARRAY(LTT_FIELD_TRAP_ID),
+        trap_entry, NULL, &hooks);
+
+    lttv_trace_find_hook(ts->parent.t,
+        LTT_CHANNEL_KERNEL,
+        LTT_EVENT_PAGE_FAULT_EXIT,
+        NULL,
+        trap_exit, NULL, &hooks);
+
+    lttv_trace_find_hook(ts->parent.t,
+        LTT_CHANNEL_KERNEL,
+        LTT_EVENT_PAGE_FAULT_NOSEM_ENTRY,
+        FIELD_ARRAY(LTT_FIELD_TRAP_ID),
+        trap_entry, NULL, &hooks);
+
+    lttv_trace_find_hook(ts->parent.t,
+        LTT_CHANNEL_KERNEL,
+        LTT_EVENT_PAGE_FAULT_NOSEM_EXIT,
+        NULL,
+        trap_exit, NULL, &hooks);
+
     lttv_trace_find_hook(ts->parent.t,
         LTT_CHANNEL_KERNEL,
         LTT_EVENT_IRQ_ENTRY,
@@ -3544,6 +3639,12 @@ void lttv_state_add_event_hooks(LttvTracesetState *self)
         FIELD_ARRAY(LTT_FIELD_ID, LTT_FIELD_ADDRESS, LTT_FIELD_SYMBOL),
         dump_syscall, NULL, &hooks);
 
+    lttv_trace_find_hook(ts->parent.t,
+        LTT_CHANNEL_KPROBE_STATE,
+        LTT_EVENT_KPROBE_TABLE,
+        FIELD_ARRAY(LTT_FIELD_IP, LTT_FIELD_SYMBOL),
+        dump_kprobe, NULL, &hooks);
+
     lttv_trace_find_hook(ts->parent.t,
         LTT_CHANNEL_SOFTIRQ_STATE,
         LTT_EVENT_SOFTIRQ_VEC,
@@ -3957,7 +4058,7 @@ void lttv_state_traceset_seek_time_closest(LttvTracesetState *self, LttTime t)
 
   gboolean is_named;
 
-  LttvAttribute *saved_states_tree, *saved_state_tree, *closest_tree;
+  LttvAttribute *saved_states_tree, *saved_state_tree, *closest_tree = NULL;
 
   //g_tree_destroy(self->parent.pqueue);
   //self->parent.pqueue = g_tree_new(compare_tracefile);
@@ -4218,6 +4319,7 @@ static void module_init()
   LTT_CHANNEL_SYSCALL_STATE     = g_quark_from_string("syscall_state");
   LTT_CHANNEL_TASK_STATE     = g_quark_from_string("task_state");
   LTT_CHANNEL_VM_STATE     = g_quark_from_string("vm_state");
+  LTT_CHANNEL_KPROBE_STATE     = g_quark_from_string("kprobe_state");
   LTT_CHANNEL_FS     = g_quark_from_string("fs");
   LTT_CHANNEL_KERNEL     = g_quark_from_string("kernel");
   LTT_CHANNEL_MM     = g_quark_from_string("mm");
@@ -4228,6 +4330,10 @@ static void module_init()
   LTT_EVENT_SYSCALL_EXIT  = g_quark_from_string("syscall_exit");
   LTT_EVENT_TRAP_ENTRY    = g_quark_from_string("trap_entry");
   LTT_EVENT_TRAP_EXIT     = g_quark_from_string("trap_exit");
+  LTT_EVENT_PAGE_FAULT_ENTRY    = g_quark_from_string("page_fault_entry");
+  LTT_EVENT_PAGE_FAULT_EXIT     = g_quark_from_string("page_fault_exit");
+  LTT_EVENT_PAGE_FAULT_NOSEM_ENTRY = g_quark_from_string("page_fault_nosem_entry");
+  LTT_EVENT_PAGE_FAULT_NOSEM_EXIT = g_quark_from_string("page_fault_nosem_exit");
   LTT_EVENT_IRQ_ENTRY     = g_quark_from_string("irq_entry");
   LTT_EVENT_IRQ_EXIT      = g_quark_from_string("irq_exit");
   LTT_EVENT_SOFT_IRQ_RAISE     = g_quark_from_string("softirq_raise");
@@ -4249,6 +4355,8 @@ static void module_init()
   LTT_EVENT_LIST_INTERRUPT = g_quark_from_string("interrupt");
   LTT_EVENT_SYS_CALL_TABLE = g_quark_from_string("sys_call_table");
   LTT_EVENT_SOFTIRQ_VEC = g_quark_from_string("softirq_vec");
+  LTT_EVENT_KPROBE_TABLE = g_quark_from_string("kprobe_table");
+  LTT_EVENT_KPROBE = g_quark_from_string("kprobe");
 
   LTT_FIELD_SYSCALL_ID    = g_quark_from_string("syscall_id");
   LTT_FIELD_TRAP_ID       = g_quark_from_string("trap_id");
@@ -4277,6 +4385,7 @@ static void module_init()
   LTT_FIELD_ID            = g_quark_from_string("id");
   LTT_FIELD_ADDRESS       = g_quark_from_string("address");
   LTT_FIELD_SYMBOL        = g_quark_from_string("symbol");
+  LTT_FIELD_IP            = g_quark_from_string("ip");
   
   LTTV_CPU_UNKNOWN = g_quark_from_string("unknown");
   LTTV_CPU_IDLE = g_quark_from_string("idle");
This page took 0.036636 seconds and 4 git commands to generate.