basic functions stats, sums not done
[lttv.git] / ltt / branches / poly / lttv / lttv / stats.c
index 22600255efde4a29dcc9eb5bde8c88311dce8a53..6117e112c091c1f6caef6d45acad283497bfd4f9 100644 (file)
@@ -31,6 +31,7 @@
 #include <ltt/type.h>
 
 #define BUF_SIZE 256
+#define MAX_64_HEX_STRING_LEN 19
 
 GQuark
   LTTV_STATS_PROCESS_UNKNOWN,
@@ -54,6 +55,7 @@ GQuark
 
 static void
 find_event_tree(LttvTracefileStats *tfcs, GQuark pid_time, GQuark cpu,
+               guint64 function,
     GQuark mode, GQuark sub_mode, LttvAttribute **events_tree, 
     LttvAttribute **event_types_tree);
 
@@ -120,6 +122,7 @@ static void lttv_stats_init(LttvTracesetStats *self)
           ltt_tracefile_long_name(tfcs->parent.parent.tf));
       find_event_tree(tfcs, LTTV_STATS_PROCESS_UNKNOWN,
           ltt_tracefile_long_name(tfcs->parent.parent.tf),
+                                       0x0ULL,
           LTTV_STATE_MODE_UNKNOWN, 
           LTTV_STATE_SUBMODE_UNKNOWN, &tfcs->current_events_tree,
           &tfcs->current_event_types_tree);
@@ -393,18 +396,26 @@ static void
 find_event_tree(LttvTracefileStats *tfcs,
                 GQuark pid_time,
                 GQuark cpu,
+                                                               guint64 function,
                 GQuark mode,
                 GQuark sub_mode,
                 LttvAttribute **events_tree, 
                 LttvAttribute **event_types_tree)
 {
   LttvAttribute *a;
+       gchar fstring[MAX_64_HEX_STRING_LEN];
+
+       g_assert(snprintf(fstring, MAX_64_HEX_STRING_LEN-1,
+                               "0x%llX", function) > 0);
+       fstring[MAX_64_HEX_STRING_LEN-1] = '\0';
 
   LttvTraceStats *tcs = (LttvTraceStats*)tfcs->parent.parent.t_context;
   a = lttv_attribute_find_subdir(tcs->stats, LTTV_STATS_PROCESSES);
   a = lttv_attribute_find_subdir(a, pid_time);
   a = lttv_attribute_find_subdir(a, LTTV_STATS_CPU);
   a = lttv_attribute_find_subdir(a, cpu);
+  a = lttv_attribute_find_subdir(a, LTTV_STATS_FUNCTIONS);
+  a = lttv_attribute_find_subdir(a, g_quark_from_string(fstring));
   a = lttv_attribute_find_subdir(a, LTTV_STATS_MODE_TYPES);
   a = lttv_attribute_find_subdir(a, mode);
   a = lttv_attribute_find_subdir(a, LTTV_STATS_SUBMODES);
@@ -423,7 +434,8 @@ static void update_event_tree(LttvTracefileStats *tfcs)
   LttvExecutionState *es = process->state;
 
   find_event_tree(tfcs, process->pid_time,
-      ltt_tracefile_long_name(tfcs->parent.parent.tf), 
+      ltt_tracefile_long_name(tfcs->parent.parent.tf),
+                       process->current_function,
       es->t, es->n, &(tfcs->current_events_tree), 
       &(tfcs->current_event_types_tree));
 }
@@ -578,6 +590,30 @@ gboolean after_soft_irq_exit(void *hook_data, void *call_data)
   return FALSE;
 }
 
+gboolean before_function_entry(void *hook_data, void *call_data)
+{
+  mode_end((LttvTracefileStats *)call_data);
+  return FALSE;
+}
+
+gboolean after_function_entry(void *hook_data, void *call_data)
+{
+  update_event_tree((LttvTracefileStats *)call_data);
+  return FALSE;
+}
+
+gboolean before_function_exit(void *hook_data, void *call_data)
+{
+  mode_end((LttvTracefileStats *)call_data);
+  return FALSE;
+}
+
+gboolean after_function_exit(void *hook_data, void *call_data)
+{
+  update_event_tree((LttvTracefileStats *)call_data);
+  return FALSE;
+}
+
 
 gboolean before_schedchange(void *hook_data, void *call_data)
 {
@@ -610,6 +646,7 @@ gboolean before_schedchange(void *hook_data, void *call_data)
 
   find_event_tree(tfcs, process->pid_time,
       ltt_tracefile_long_name(tfcs->parent.parent.tf), 
+                       process->current_function,
       process->state->t, process->state->n, &(tfcs->current_events_tree), 
       &(tfcs->current_event_types_tree));
 
@@ -823,6 +860,7 @@ void lttv_stats_add_event_hooks(LttvTracesetStats *self)
   LttvAttributeValue val;
 
   gint ret;
+       gint hn;
 
   nb_trace = lttv_traceset_number(traceset);
   for(i = 0 ; i < nb_trace ; i++) {
@@ -831,154 +869,187 @@ void lttv_stats_add_event_hooks(LttvTracesetStats *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), 9);
-    g_array_set_size(hooks, 9);
+    hooks = g_array_sized_new(FALSE, FALSE, sizeof(LttvTraceHook), 11);
+    g_array_set_size(hooks, 11);
+               hn=0;
 
     ret = lttv_trace_find_hook(ts->parent.parent.t,
         LTT_FACILITY_KERNEL_ARCH, LTT_EVENT_SYSCALL_ENTRY,
         LTT_FIELD_SYSCALL_ID, 0, 0,
         before_syscall_entry, NULL, 
-        &g_array_index(hooks, LttvTraceHook, 0));
-    g_assert(!ret);
+        &g_array_index(hooks, LttvTraceHook, hn++));
+    if(ret) hn--;
 
     ret = lttv_trace_find_hook(ts->parent.parent.t,
         LTT_FACILITY_KERNEL_ARCH, LTT_EVENT_SYSCALL_EXIT,
         0, 0, 0,
         before_syscall_exit, NULL, 
-        &g_array_index(hooks, LttvTraceHook, 1));
-    g_assert(!ret);
+        &g_array_index(hooks, LttvTraceHook, hn++));
+    if(ret) hn--;
 
     ret = lttv_trace_find_hook(ts->parent.parent.t,
         LTT_FACILITY_KERNEL, LTT_EVENT_TRAP_ENTRY,
         LTT_FIELD_TRAP_ID, 0, 0,
         before_trap_entry, NULL, 
-        &g_array_index(hooks, LttvTraceHook, 2));
-    g_assert(!ret);
+        &g_array_index(hooks, LttvTraceHook, hn++));
+    if(ret) hn--;
 
     ret = lttv_trace_find_hook(ts->parent.parent.t,
         LTT_FACILITY_KERNEL, LTT_EVENT_TRAP_EXIT,
         0, 0, 0,
         before_trap_exit, NULL,
-        &g_array_index(hooks, LttvTraceHook, 3));
-    g_assert(!ret);
+        &g_array_index(hooks, LttvTraceHook, hn++));
+    if(ret) hn--;
 
     ret = lttv_trace_find_hook(ts->parent.parent.t,
         LTT_FACILITY_KERNEL, LTT_EVENT_IRQ_ENTRY,
         LTT_FIELD_IRQ_ID, 0, 0,
         before_irq_entry, NULL,
-        &g_array_index(hooks, LttvTraceHook, 4));
-    g_assert(!ret);
+        &g_array_index(hooks, LttvTraceHook, hn++));
+    if(ret) hn--;
 
     ret = lttv_trace_find_hook(ts->parent.parent.t,
         LTT_FACILITY_KERNEL, LTT_EVENT_IRQ_EXIT,
         0, 0, 0,
         before_irq_exit, NULL,
-        &g_array_index(hooks, LttvTraceHook, 5));
-    g_assert(!ret);
+        &g_array_index(hooks, LttvTraceHook, hn++));
+    if(ret) hn--;
 
     ret = lttv_trace_find_hook(ts->parent.parent.t,
         LTT_FACILITY_KERNEL, LTT_EVENT_SOFT_IRQ_ENTRY,
         LTT_FIELD_SOFT_IRQ_ID, 0, 0,
         before_soft_irq_entry, NULL,
-        &g_array_index(hooks, LttvTraceHook, 6));
-    g_assert(!ret);
+        &g_array_index(hooks, LttvTraceHook, hn++));
+    if(ret) hn--;
 
     ret = lttv_trace_find_hook(ts->parent.parent.t,
         LTT_FACILITY_KERNEL, LTT_EVENT_SOFT_IRQ_EXIT,
         0, 0, 0,
         before_soft_irq_exit, NULL,
-        &g_array_index(hooks, LttvTraceHook, 7));
-    g_assert(!ret);
+        &g_array_index(hooks, LttvTraceHook, hn++));
+    if(ret) hn--;
 
     ret = lttv_trace_find_hook(ts->parent.parent.t,
         LTT_FACILITY_PROCESS, LTT_EVENT_SCHEDCHANGE,
         LTT_FIELD_OUT, LTT_FIELD_IN, LTT_FIELD_OUT_STATE,
         before_schedchange, NULL, 
-        &g_array_index(hooks, LttvTraceHook, 8));
-    g_assert(!ret);
+        &g_array_index(hooks, LttvTraceHook, hn++));
+    if(ret) hn--;
+
+    ret = lttv_trace_find_hook(ts->parent.parent.t,
+        LTT_FACILITY_USER_GENERIC, LTT_EVENT_FUNCTION_ENTRY,
+        LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE, 0,
+        before_function_entry, NULL,
+        &g_array_index(hooks, LttvTraceHook, hn++));
+    if(ret) hn--;
+
+    ret = lttv_trace_find_hook(ts->parent.parent.t,
+        LTT_FACILITY_USER_GENERIC, LTT_EVENT_FUNCTION_EXIT,
+        LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE, 0,
+        before_function_exit, NULL,
+        &g_array_index(hooks, LttvTraceHook, hn++));
+    if(ret) hn--;
+               
+    g_array_set_size(hooks, hn);
 
     before_hooks = hooks;
 
-    hooks = g_array_sized_new(FALSE, FALSE, sizeof(LttvTraceHook), 11);
-    g_array_set_size(hooks, 11);
+    hooks = g_array_sized_new(FALSE, FALSE, sizeof(LttvTraceHook), 13);
+    g_array_set_size(hooks, 13);
+               hn=0;
 
     ret = lttv_trace_find_hook(ts->parent.parent.t,
         LTT_FACILITY_KERNEL_ARCH, LTT_EVENT_SYSCALL_ENTRY,
         LTT_FIELD_SYSCALL_ID, 0, 0,
         after_syscall_entry, NULL, 
-        &g_array_index(hooks, LttvTraceHook, 0));
-    g_assert(!ret);
+        &g_array_index(hooks, LttvTraceHook, hn++));
+    if(ret) hn--;
 
     ret = lttv_trace_find_hook(ts->parent.parent.t,
         LTT_FACILITY_KERNEL_ARCH, LTT_EVENT_SYSCALL_EXIT,
         0, 0, 0,
         after_syscall_exit, NULL, 
-        &g_array_index(hooks, LttvTraceHook, 1));
-    g_assert(!ret);
+        &g_array_index(hooks, LttvTraceHook, hn++));
+    if(ret) hn--;
 
     ret = lttv_trace_find_hook(ts->parent.parent.t,
         LTT_FACILITY_KERNEL, LTT_EVENT_TRAP_ENTRY, 
         LTT_FIELD_TRAP_ID, 0, 0,
         after_trap_entry, NULL,
-        &g_array_index(hooks, LttvTraceHook, 2));
-    g_assert(!ret);
+        &g_array_index(hooks, LttvTraceHook, hn++));
+    if(ret) hn--;
 
     ret = lttv_trace_find_hook(ts->parent.parent.t,
         LTT_FACILITY_KERNEL, LTT_EVENT_TRAP_EXIT,
         0, 0, 0,
         after_trap_exit, NULL,
-        &g_array_index(hooks, LttvTraceHook, 3));
-    g_assert(!ret);
+        &g_array_index(hooks, LttvTraceHook, hn++));
+    if(ret) hn--;
 
     ret = lttv_trace_find_hook(ts->parent.parent.t,
         LTT_FACILITY_KERNEL, LTT_EVENT_IRQ_ENTRY, 
         LTT_FIELD_IRQ_ID, 0, 0,
         after_irq_entry, NULL,
-        &g_array_index(hooks, LttvTraceHook, 4));
-    g_assert(!ret);
+        &g_array_index(hooks, LttvTraceHook, hn++));
+    if(ret) hn--;
 
     ret = lttv_trace_find_hook(ts->parent.parent.t,
         LTT_FACILITY_KERNEL, LTT_EVENT_IRQ_EXIT,
         0, 0, 0,
         after_irq_exit, NULL,
-        &g_array_index(hooks, LttvTraceHook, 5));
-    g_assert(!ret);
+        &g_array_index(hooks, LttvTraceHook, hn++));
+    if(ret) hn--;
 
     ret = lttv_trace_find_hook(ts->parent.parent.t,
         LTT_FACILITY_KERNEL, LTT_EVENT_SOFT_IRQ_ENTRY, 
         LTT_FIELD_SOFT_IRQ_ID, 0, 0,
         after_irq_entry, NULL,
-        &g_array_index(hooks, LttvTraceHook, 6));
-    g_assert(!ret);
+        &g_array_index(hooks, LttvTraceHook, hn++));
+    if(ret) hn--;
 
     ret = lttv_trace_find_hook(ts->parent.parent.t,
         LTT_FACILITY_KERNEL, LTT_EVENT_SOFT_IRQ_EXIT,
         0, 0, 0,
         after_soft_irq_exit, NULL,
-        &g_array_index(hooks, LttvTraceHook, 7));
-    g_assert(!ret);
+        &g_array_index(hooks, LttvTraceHook, hn++));
+    if(ret) hn--;
 
     ret = lttv_trace_find_hook(ts->parent.parent.t,
         LTT_FACILITY_PROCESS, LTT_EVENT_FORK, 
         LTT_FIELD_PARENT_PID, LTT_FIELD_CHILD_PID, 0,
         process_fork, NULL, 
-        &g_array_index(hooks, LttvTraceHook, 8));
-    g_assert(!ret);
+        &g_array_index(hooks, LttvTraceHook, hn++));
+    if(ret) hn--;
 
     ret = lttv_trace_find_hook(ts->parent.parent.t,
         LTT_FACILITY_PROCESS, LTT_EVENT_EXIT,
         LTT_FIELD_PID, 0, 0,
         process_exit, NULL,
-        &g_array_index(hooks, LttvTraceHook, 9));
-    g_assert(!ret);
+        &g_array_index(hooks, LttvTraceHook, hn++));
+    if(ret) hn--;
     
     ret = lttv_trace_find_hook(ts->parent.parent.t,
         LTT_FACILITY_PROCESS, LTT_EVENT_FREE,
         LTT_FIELD_PID, 0, 0,
         process_free, NULL,
-        &g_array_index(hooks, LttvTraceHook, 10));
-    g_assert(!ret);
+        &g_array_index(hooks, LttvTraceHook, hn++));
+    if(ret) hn--;
+
+    ret = lttv_trace_find_hook(ts->parent.parent.t,
+        LTT_FACILITY_USER_GENERIC, LTT_EVENT_FUNCTION_ENTRY,
+        LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE, 0,
+        after_function_entry, NULL,
+        &g_array_index(hooks, LttvTraceHook, hn++));
+    if(ret) hn--;
 
+    ret = lttv_trace_find_hook(ts->parent.parent.t,
+        LTT_FACILITY_USER_GENERIC, LTT_EVENT_FUNCTION_EXIT,
+        LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE, 0,
+        after_function_exit, NULL,
+        &g_array_index(hooks, LttvTraceHook, hn++));
+    if(ret) hn--;
+       
+    g_array_set_size(hooks, hn);
 
     after_hooks = hooks;
 
@@ -1110,7 +1181,7 @@ static void module_init()
   LTTV_STATS_MODE_TYPES = g_quark_from_string("mode_types");
   LTTV_STATS_MODES = g_quark_from_string("modes");
   LTTV_STATS_SUBMODES = g_quark_from_string("submodes");
-  LTTV_STATS_SUBMODES = g_quark_from_string("functions");
+  LTTV_STATS_FUNCTIONS = g_quark_from_string("functions");
   LTTV_STATS_EVENT_TYPES = g_quark_from_string("event_types");
   LTTV_STATS_CPU_TIME = g_quark_from_string("cpu time");
   LTTV_STATS_ELAPSED_TIME = g_quark_from_string("elapsed time");
This page took 0.028382 seconds and 4 git commands to generate.