{
int i;
- LttvTraceHook th;
-
GString *fe_name = g_string_new("");
LttvNameTables *name_tables = g_new(LttvNameTables, 1);
LttvAttributeValue v;
+ GArray *hooks;
+
lttv_attribute_find(tcs->parent.t_a, LTTV_STATE_NAME_TABLES,
LTTV_POINTER, &v);
g_assert(*(v.v_pointer) == NULL);
*(v.v_pointer) = name_tables;
+ hooks = g_array_sized_new(FALSE, FALSE, sizeof(LttvTraceHook), 1);
+
if(!lttv_trace_find_hook(tcs->parent.t,
LTT_EVENT_SYSCALL_ENTRY,
FIELD_ARRAY(LTT_FIELD_SYSCALL_ID),
- NULL, NULL)) {
+ NULL, NULL, &hooks)) {
// th = lttv_trace_hook_get_first(&th);
//
// t = ltt_field_type(th->f1);
// nb = ltt_type_element_number(t);
//
- lttv_trace_hook_destroy(&th);
-//
// name_tables->syscall_names = g_new(GQuark, nb);
// name_tables->nb_syscalls = nb;
//
name_tables->syscall_names = NULL;
name_tables->nb_syscalls = 0;
}
+ lttv_trace_hook_destroy(&hooks);
if(!lttv_trace_find_hook(tcs->parent.t,
LTT_EVENT_TRAP_ENTRY,
- LTT_FIELD_TRAP_ID, 0, 0,
- NULL, NULL, &th)) {
+ FIELD_ARRAY(LTT_FIELD_TRAP_ID),
+ NULL, NULL, &hooks)) {
// th = lttv_trace_hook_get_first(&th);
//
// t = ltt_field_type(th->f1);
// //nb = ltt_type_element_number(t);
//
- lttv_trace_hook_destroy(&th);
-
// name_tables->trap_names = g_new(GQuark, nb);
// for(i = 0 ; i < nb ; i++) {
// name_tables->trap_names[i] = g_quark_from_string(
name_tables->trap_names = NULL;
name_tables->nb_traps = 0;
}
+ lttv_trace_hook_destroy(&hooks);
if(!lttv_trace_find_hook(tcs->parent.t,
LTT_EVENT_IRQ_ENTRY,
- LTT_FIELD_IRQ_ID, 0, 0,
- NULL, NULL, &th)) {
+ FIELD_ARRAY(LTT_FIELD_IRQ_ID),
+ NULL, NULL, &hooks)) {
- lttv_trace_hook_destroy(&th);
-
/*
name_tables->irq_names = g_new(GQuark, nb);
for(i = 0 ; i < nb ; i++) {
name_tables->nb_irqs = 0;
name_tables->irq_names = NULL;
}
+ lttv_trace_hook_destroy(&hooks);
/*
name_tables->soft_irq_names = g_new(GQuark, nb);
for(i = 0 ; i < nb ; i++) {
g_string_printf(fe_name, "softirq %d", i);
name_tables->soft_irq_names[i] = g_quark_from_string(fe_name->str);
}
-
+ g_array_free(hooks, TRUE);
g_string_free(fe_name, TRUE);
}
associated by id hooks. */
hooks = g_array_sized_new(FALSE, FALSE, sizeof(LttvTraceHook), 19);
- hooks = g_array_set_size(hooks, 19); // Max possible number of hooks.
- hn = 0;
+ //hooks = g_array_set_size(hooks, 19); // Max possible number of hooks.
+ //hn = 0;
- ret = lttv_trace_find_hook(ts->parent.t,
+ lttv_trace_find_hook(ts->parent.t,
LTT_EVENT_SYSCALL_ENTRY,
- LTT_FIELD_SYSCALL_ID, 0, 0,
- syscall_entry, NULL, &g_array_index(hooks, LttvTraceHook, hn++));
- if(ret) hn--;
+ FIELD_ARRAY(LTT_FIELD_SYSCALL_ID),
+ syscall_entry, NULL, &hooks);
- ret = lttv_trace_find_hook(ts->parent.t,
+ lttv_trace_find_hook(ts->parent.t,
LTT_EVENT_SYSCALL_EXIT,
- 0, 0, 0,
- syscall_exit, NULL, &g_array_index(hooks, LttvTraceHook, hn++));
- if(ret) hn--;
+ FIELD_ARRAY(0),
+ syscall_exit, NULL, &hooks);
- ret = lttv_trace_find_hook(ts->parent.t,
+ lttv_trace_find_hook(ts->parent.t,
LTT_EVENT_TRAP_ENTRY,
- LTT_FIELD_TRAP_ID, 0, 0,
- trap_entry, NULL, &g_array_index(hooks, LttvTraceHook, hn++));
- if(ret) hn--;
+ FIELD_ARRAY(LTT_FIELD_TRAP_ID),
+ trap_entry, NULL, &hooks);
ret = lttv_trace_find_hook(ts->parent.t,
LTT_EVENT_TRAP_EXIT,
}
-GArray *lttv_trace_find_hook(LttTrace *t, GQuark marker_name,
- GQuark fields[], LttvHook h, gpointer hook_data)
+int lttv_trace_find_hook(LttTrace *t, GQuark marker_name,
+ GQuark fields[], LttvHook h, gpointer hook_data, GArray **trace_hooks)
{
struct marker_info *info;
- GQuark *pfieldname;
struct marker_field *field;
guint16 marker_id;
-
- GArray * retval;
+ int init_array_size;
info = marker_get_info_from_name(t, marker_name);
if(unlikely(info == NULL)) {
return NULL;
}
- retval = g_array_new(FALSE, FALSE, sizeof(LttvTraceHook));
-
-
+ init_array_size = (*trace_hooks)->len;
/* for each marker with the requested name */
do {
LttvTraceHook tmpth;
int found;
+ GQuark f;
marker_id = marker_get_id_from_info(t, info);
tmpth.fields = g_ptr_array_new();
/* for each field requested */
- found = 0;
- for(pfieldname = fields; pfieldname != NULL; pfieldname++) {
- for_each_marker_field(field, info) {
- if(field->name == *pfieldname) {
-
+ for(f = fields; *f != 0; f++) {
+ found = 0;
+ for_each_marker_field(marker_field, info) {
+ if(marker_fieldfield->name == *f) {
found = 1;
- g_ptr_array_add(tmpth.fields, field);
+ g_ptr_array_add(tmpth.fields, marker_field);
break;
}
}
if(!found) {
/* Did not find the one of the fields in this instance of the
- marker. Skip it. */
+ marker. Print a warning and skip this marker completely.
+ Still iterate on other markers with same name. */
g_ptr_array_free(tmpth.fields, TRUE);
- goto free_retval;
+ g_warning("Field %s cannot be found in marker %s",
+ g_quark_to_string(*f), g_quark_to_string(marker_name));
+ goto skip_marker;
}
}
-
/* all fields were found: add the tracehook to the array */
- g_array_append_val(retval, tmpth);
-
+ *trace_hooks = g_array_append_val(*trace_hooks, tmpth);
+skip_marker:
info = info->next;
} while(info != NULL);
-
- if(retval->len)
- return retval;
-
- free_retval:
- g_array_free(retval, TRUE);
- return NULL;
+ /* Error if no new trace hook has been added */
+ return (init_array_size == (*trace_hooks)->len);
}
-void lttv_trace_hook_destroy(GArray *th)
+void lttv_trace_hook_destroy(GArray **th)
{
int i;
for(i=0; i<th->len; i++) {
g_ptr_array_free(g_array_index(th, LttvTraceHook, i).fields, TRUE);
}
-
- g_array_free(th, TRUE);
+ *th = g_array_remove_range(*th, 0, th->len);
}
-
-
-
LttvTracesetContextPosition *lttv_traceset_context_position_new(
const LttvTracesetContext *self)
{
is useful to find the specific id for an event within a trace, for
registering a hook using this structure as event data;
it already contains the (up to three) needed fields handles.
- Returns an array of LttvTraceHook, or NULL on error.
+ Returns the modified LttvTraceHook array.
+ Prints warnings if events or markers are not found. returns 1 on error,
+ 0 on success.
+ Adds the hooks to the trace_hooks array.
*/
-GArray *lttv_trace_find_hook(LttTrace *t, GQuark marker_name,
- GQuark fields[], LttvHook h, gpointer hook_data);
+int lttv_trace_find_hook(LttTrace *t, GQuark marker_name,
+ GQuark fields[], LttvHook h, gpointer hook_data, GArray **trace_hooks);
LttvTracefileContext *lttv_traceset_context_get_current_tfc(
LttvTracesetContext *self);