#include <stdio.h>
#include <string.h>
#include <ltt/ltt-private.h>
+#include <inttypes.h>
/* Comment :
* Mathieu Desnoyers
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,
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,
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 */
LTT_FIELD_ACTION,
LTT_FIELD_ID,
LTT_FIELD_ADDRESS,
- LTT_FIELD_SYMBOL;
+ LTT_FIELD_SYMBOL,
+ LTT_FIELD_IP;
LttvExecutionMode
LTTV_STATE_MODE_UNKNOWN,
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);
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);
/* reset cpu states */
if(self->cpu_states[i].mode_stack->len > 0) {
g_array_remove_range(self->cpu_states[i].mode_stack, 0, self->cpu_states[i].mode_stack->len);
- self->cpu_states[i].last_irq = -1;
+ if(self->cpu_states[i].irq_stack->len)
+ g_array_remove_range(self->cpu_states[i].irq_stack, 0, self->cpu_states[i].irq_stack->len);
self->cpu_states[i].last_soft_irq = -1;
self->cpu_states[i].last_trap = -1;
}
tcs->cpu_states = g_new(LttvCPUState, nb_cpu);
for(j = 0; j<nb_cpu; j++) {
tcs->cpu_states[j].mode_stack = g_array_new(FALSE, FALSE, sizeof(LttvCPUMode));
- tcs->cpu_states[j].last_irq = -1;
+ tcs->cpu_states[j].irq_stack = g_array_new(FALSE, FALSE, sizeof(gint));
tcs->cpu_states[j].last_soft_irq = -1;
tcs->cpu_states[j].last_trap = -1;
g_assert(tcs->cpu_states[j].mode_stack != NULL);
/* 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,
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);
}
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);
}
}
retval = g_new(LttvCPUState, n);
for(i=0; i<n; i++) {
- retval[i].mode_stack = g_array_new(FALSE, FALSE, sizeof(LttvCPUMode));
- retval[i].last_irq = states[i].last_irq;
retval[i].last_soft_irq = states[i].last_soft_irq;
retval[i].last_trap = states[i].last_trap;
+
+ retval[i].irq_stack = g_array_new(FALSE, FALSE, sizeof(gint));
+ g_array_set_size(retval[i].irq_stack, states[i].irq_stack->len);
+ for(j=0; j<states[i].irq_stack->len; j++) {
+ g_array_index(retval[i].irq_stack, gint, j) = g_array_index(states[i].irq_stack, gint, j);
+ }
+
+ retval[i].mode_stack = g_array_new(FALSE, FALSE, sizeof(LttvCPUMode));
g_array_set_size(retval[i].mode_stack, states[i].mode_stack->len);
for(j=0; j<states[i].mode_stack->len; j++) {
g_array_index(retval[i].mode_stack, GQuark, j) = g_array_index(states[i].mode_stack, GQuark, j);
for(i=0; i<n; i++) {
g_array_free(states[i].mode_stack, TRUE);
+ g_array_free(states[i].irq_stack, TRUE);
}
g_free(states);
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);
}
guint nb_irqs;
GQuark *soft_irq_names;
guint nb_softirqs;
+ GHashTable *kprobe_hash;
} LttvNameTables;
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);
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
}
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;
}
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
* 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)
cpu_push_mode(s->cpu_state, LTTV_CPU_IRQ);
/* update irq status */
- s->cpu_state->last_irq = irq;
+ g_array_append_val(s->cpu_state->irq_stack, irq);
irq_push_mode(&ts->irq_states[irq], LTTV_IRQ_BUSY);
return FALSE;
cpu_pop_mode(s->cpu_state);
/* update irq status */
- if (s->cpu_state->last_irq != -1)
- irq_pop_mode(&ts->irq_states[s->cpu_state->last_irq]);
+ if (s->cpu_state->irq_stack->len > 0) {
+ gint last = g_array_index(s->cpu_state->irq_stack, gint, s->cpu_state->irq_stack->len-1);
+ g_array_remove_index(s->cpu_state->irq_stack, s->cpu_state->irq_stack->len-1);
+ irq_pop_mode(&ts->irq_states[last]);
+ }
return FALSE;
}
} 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);
}
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,
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;
/* 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;
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,
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,
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);
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");
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");
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");
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");