From cb03932ac8527313696af07dba4404603620c844 Mon Sep 17 00:00:00 2001 From: compudj Date: Sat, 20 Aug 2005 18:25:41 +0000 Subject: [PATCH] LTTV is now alive : needs testing git-svn-id: http://ltt.polymtl.ca/svn@1031 04897980-b3bd-0310-b5e0-8ef037075253 --- ltt/branches/poly/ltt/facility.c | 72 +++++++++++------ ltt/branches/poly/ltt/ltt-private.h | 1 + ltt/branches/poly/ltt/tracefile.c | 91 ++++++++++++---------- ltt/branches/poly/lttv/lttv/main.c | 4 +- ltt/branches/poly/lttv/lttv/state.c | 38 ++++----- ltt/branches/poly/lttv/lttv/stats.c | 12 +-- ltt/branches/poly/lttv/lttv/tracecontext.c | 6 +- 7 files changed, 130 insertions(+), 94 deletions(-) diff --git a/ltt/branches/poly/ltt/facility.c b/ltt/branches/poly/ltt/facility.c index e488005b..0b5f1ee7 100644 --- a/ltt/branches/poly/ltt/facility.c +++ b/ltt/branches/poly/ltt/facility.c @@ -90,7 +90,7 @@ int ltt_facility_open(LttFacility *f, LttTrace * t, gchar * pathname) //in.fd = g_open(in.name, O_RDONLY, 0); //if(in.fd < 0 ) { in.fp = fopen(in.name, "r"); - if(in.fp < 0 ) { + if(in.fp == NULL) { g_warning("cannot open facility description file %s", in.name); return 1; @@ -254,17 +254,35 @@ void construct_types_and_fields(LttFacility * fac, type_descriptor_t * td, type_descriptor_t * tmpTd; switch(td->type) { - case LTT_ENUM: - fld->field_type->element_number = td->labels.position; - fld->field_type->enum_strings = g_new(GQuark,td->labels.position); - for(i=0;ilabels.position;i++){ - fld->field_type->enum_strings[i] - = g_quark_from_string(((char*)(td->labels.array[i]))); - } - break; - case LTT_ARRAY: - fld->field_type->element_number = (unsigned)td->size; - case LTT_SEQUENCE: + case INT: + case UINT: + case FLOAT: + fld->field_type->size = td->size; + break; + case POINTER: + case LONG: + case ULONG: + case SIZE_T: + case SSIZE_T: + case OFF_T: + fld->field_type->size = 0; + break; + case STRING: + fld->field_type->size = 0; + break; + case ENUM: + fld->field_type->element_number = td->labels.position; + fld->field_type->enum_strings = g_new(GQuark,td->labels.position); + for(i=0;ilabels.position;i++){ + fld->field_type->enum_strings[i] + = g_quark_from_string(((char*)(td->labels.array[i]))); + } + fld->field_type->size = td->size; + break; + + case ARRAY: + fld->field_type->element_number = (unsigned)td->size; + case SEQUENCE: fld->field_type->element_type = g_new(LttType*,1); tmpTd = td->nested_type; fld->field_type->element_type[0] = lookup_named_type(fac, tmpTd); @@ -283,8 +301,9 @@ void construct_types_and_fields(LttFacility * fac, type_descriptor_t * td, fld->child[0]->current_element = 0; construct_types_and_fields(fac, tmpTd, fld->child[0]); break; - case LTT_STRUCT: - case LTT_UNION: + + case STRUCT: + case UNION: fld->field_type->element_number = td->fields.position; g_assert(fld->field_type->element_type == NULL); @@ -314,8 +333,8 @@ void construct_types_and_fields(LttFacility * fac, type_descriptor_t * td, fld->child[i]->current_element = 0; construct_types_and_fields(fac, tmpTd, fld->child[i]); } - break; + default: g_error("construct_types_and_fields : unknown type"); } @@ -420,15 +439,20 @@ void construct_types_and_fields(LttFacility * fac, type_descriptor * td, LttType * lookup_named_type(LttFacility *fac, type_descriptor_t * td) { - GQuark name = g_quark_from_string(td->type_name); + LttType *type = NULL; + GQuark name = 0; + + if(td->type_name != NULL) { + /* Named type */ + name = g_quark_from_string(td->type_name); + + type = g_datalist_id_get_data(&fac->named_types, name); + } - LttType *type = g_datalist_id_get_data(&fac->named_types, name); - if(type == NULL){ + /* Create the type */ type = g_new(LttType,1); type->type_name = name; - g_datalist_id_set_data_full(&fac->named_types, name, - type, (GDestroyNotify)freeLttNamedType); type->type_class = td->type; if(td->fmt) type->fmt = g_strdup(td->fmt); else type->fmt = NULL; @@ -436,8 +460,11 @@ LttType * lookup_named_type(LttFacility *fac, type_descriptor_t * td) type->enum_strings = NULL; type->element_type = NULL; type->element_number = 0; + + if(td->type_name != NULL) + g_datalist_id_set_data_full(&fac->named_types, name, + type, (GDestroyNotify)freeLttNamedType); } - return type; } @@ -496,6 +523,7 @@ void freeLttType(LttType ** type) { unsigned int i; if(*type == NULL) return; + if((*type)->type_name != 0) return; //this is a named type. //if((*type)->type_name){ // return; //this is a named type //} @@ -625,6 +653,6 @@ LttEventType *ltt_facility_eventtype_get(LttFacility *f, guint8 i) LttEventType *ltt_facility_eventtype_get_by_name(LttFacility *f, GQuark name) { - LttEventType *et = g_datalist_get_data(&f->events_by_name, name); + LttEventType *et = g_datalist_id_get_data(&f->events_by_name, name); } diff --git a/ltt/branches/poly/ltt/ltt-private.h b/ltt/branches/poly/ltt/ltt-private.h index b34d50bc..9ef7d481 100644 --- a/ltt/branches/poly/ltt/ltt-private.h +++ b/ltt/branches/poly/ltt/ltt-private.h @@ -268,6 +268,7 @@ struct _LttFacility{ guint32 id; //id of the facility guint32 pointer_size; + guint32 long_size; guint32 size_t_size; guint32 alignment; diff --git a/ltt/branches/poly/ltt/tracefile.c b/ltt/branches/poly/ltt/tracefile.c index fb951222..e6117b34 100644 --- a/ltt/branches/poly/ltt/tracefile.c +++ b/ltt/branches/poly/ltt/tracefile.c @@ -619,6 +619,7 @@ static int open_tracefiles(LttTrace *trace, char *root_path, int rel_path_len; char rel_path[PATH_MAX]; char *rel_path_ptr; + LttTracefile tmp_tf; if(dir == NULL) { perror(root_path); @@ -658,8 +659,6 @@ static int open_tracefiles(LttTrace *trace, char *root_path, ret = open_tracefiles(trace, path, rel_path); if(ret < 0) continue; } else if(S_ISREG(stat_buf.st_mode)) { - g_debug("Opening file.\n"); - GQuark name; guint num; GArray *group; @@ -669,9 +668,19 @@ static int open_tracefiles(LttTrace *trace, char *root_path, if(get_tracefile_name_number(rel_path, &name, &num)) continue; /* invalid name */ + g_debug("Opening file.\n"); + if(ltt_tracefile_open(trace, path, &tmp_tf)) { + g_info("Error opening tracefile %s", path); + + continue; /* error opening the tracefile : bad magic number ? */ + } + g_debug("Tracefile name is %s and number is %u", g_quark_to_string(name), num); + tmp_tf.cpu_online = 1; + tmp_tf.cpu_num = num; + group = g_datalist_id_get_data(&trace->tracefiles, name); if(group == NULL) { /* Elements are automatically cleared when the array is allocated. @@ -681,23 +690,13 @@ static int open_tracefiles(LttTrace *trace, char *root_path, g_datalist_id_set_data_full(&trace->tracefiles, name, group, ltt_tracefile_group_destroy); } + /* Add the per cpu tracefile to the named group */ unsigned int old_len = group->len; if(num+1 > old_len) group = g_array_set_size(group, num+1); - tf = &g_array_index (group, LttTracefile, num); - - if(ltt_tracefile_open(trace, path, tf)) { - g_info("Error opening tracefile %s", path); - g_array_set_size(group, old_len); + g_array_index (group, LttTracefile, num) = tmp_tf; - if(!ltt_tracefile_group_has_cpu_online(group)) - g_datalist_id_remove_data(&trace->tracefiles, name); - - continue; /* error opening the tracefile : bad magic number ? */ - } - tf->cpu_online = 1; - tf->cpu_num = num; } } @@ -724,8 +723,6 @@ static int ltt_get_facility_description(LttFacility *f, const gchar *text; guint textlen; gint err; - int i, j; - LttEventType *et; text = g_quark_to_string(t->pathname); textlen = strlen(text); @@ -761,17 +758,6 @@ static int ltt_get_facility_description(LttFacility *f, err = ltt_facility_open(f, t, desc_file_name); if(err) goto facility_error; - - for(i=0;ifacilities_by_num->len;i++){ - f = &g_array_index(t->facilities_by_num, LttFacility, i); - if(f->exists) { - for(j=0; jevents->len; j++){ - et = &g_array_index(f->events, LttEventType, j); - set_fields_offsets(fac_tf, et); - } - } - } - return 0; @@ -783,13 +769,6 @@ name_error: static void ltt_fac_ids_destroy(gpointer data) { GArray *fac_ids = (GArray *)data; - int i; - LttFacility *fac; - - for(i=0; ilen; i++) { - fac = &g_array_index (fac_ids, LttFacility, i); - ltt_facility_close(fac); - } g_array_free(fac_ids, TRUE); } @@ -802,6 +781,8 @@ static int ltt_process_facility_tracefile(LttTracefile *tf) int err; LttFacility *fac; GArray *fac_ids; + guint i; + LttEventType *et; while(1) { err = ltt_tracefile_read_seek(tf); @@ -853,15 +834,24 @@ static int ltt_process_facility_tracefile(LttTracefile *tf) fac->id = ltt_get_uint32(LTT_GET_BO(tf), &fac_load_data->id); fac->pointer_size = ltt_get_uint32(LTT_GET_BO(tf), &fac_load_data->pointer_size); + fac->long_size = ltt_get_uint32(LTT_GET_BO(tf), + &fac_load_data->long_size); fac->size_t_size = ltt_get_uint32(LTT_GET_BO(tf), &fac_load_data->size_t_size); fac->alignment = ltt_get_uint32(LTT_GET_BO(tf), &fac_load_data->alignment); if(ltt_get_facility_description(fac, tf->trace, tf)) - goto facility_error; + continue; /* error opening description */ fac->trace = tf->trace; + + /* Preset the field offsets */ + for(i=0; ievents->len; i++){ + et = &g_array_index(fac->events, LttEventType, i); + set_fields_offsets(tf, et); + } + fac->exists = 1; fac_ids = g_datalist_id_get_data(&tf->trace->facilities_by_name, @@ -896,15 +886,23 @@ static int ltt_process_facility_tracefile(LttTracefile *tf) fac->id = fac_state_dump_load_data->id; fac->pointer_size = ltt_get_uint32(LTT_GET_BO(tf), &fac_state_dump_load_data->pointer_size); + fac->long_size = ltt_get_uint32(LTT_GET_BO(tf), + &fac_state_dump_load_data->long_size); fac->size_t_size = ltt_get_uint32(LTT_GET_BO(tf), &fac_state_dump_load_data->size_t_size); fac->alignment = ltt_get_uint32(LTT_GET_BO(tf), &fac_state_dump_load_data->alignment); if(ltt_get_facility_description(fac, tf->trace, tf)) - goto facility_error; + continue; /* error opening description */ fac->trace = tf->trace; + /* Preset the field offsets */ + for(i=0; ievents->len; i++){ + et = &g_array_index(fac->events, LttEventType, i); + set_fields_offsets(tf, et); + } + fac->exists = 1; fac_ids = g_datalist_id_get_data(&tf->trace->facilities_by_name, @@ -1033,6 +1031,15 @@ LttTrace *ltt_trace_copy(LttTrace *self) void ltt_trace_close(LttTrace *t) { + guint i; + LttFacility *fac; + + for(i=0; ifacilities_by_num->len; i++) { + fac = &g_array_index (t->facilities_by_num, LttFacility, i); + if(fac->exists) + ltt_facility_close(fac); + } + g_datalist_clear(&t->facilities_by_name); g_array_free(t->facilities_by_num, TRUE); g_datalist_clear(&t->tracefiles); @@ -1720,11 +1727,6 @@ static int ltt_seek_next_event(LttTracefile *tf) } - if(tf->event.offset == tf->block_size - tf->buffer.lost_size) { - ret = ERANGE; - goto found; - } - pos = tf->event.data; if(tf->event.data_size < 0) goto error; @@ -1732,6 +1734,11 @@ static int ltt_seek_next_event(LttTracefile *tf) pos += (size_t)tf->event.data_size; tf->event.offset = pos - tf->buffer.head; + + if(tf->event.offset == tf->block_size - tf->buffer.lost_size) { + ret = ERANGE; + goto found; + } found: return ret; @@ -1863,7 +1870,7 @@ void preset_field_type_size(LttTracefile *tf, LttEventType *event_type, break; case LTT_LONG: case LTT_ULONG: - field->field_size = (off_t)event_type->facility->pointer_size; + field->field_size = (off_t)event_type->facility->long_size; field->fixed_size = FIELD_FIXED; break; case LTT_SIZE_T: diff --git a/ltt/branches/poly/lttv/lttv/main.c b/ltt/branches/poly/lttv/lttv/main.c index 2c4a9f0a..29aa288e 100644 --- a/ltt/branches/poly/lttv/lttv/main.c +++ b/ltt/branches/poly/lttv/lttv/main.c @@ -265,8 +265,8 @@ void lttv_debug(void *hook_data) void lttv_fatal(void *hook_data) { - //g_log_set_always_fatal(G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL); - g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL); + g_log_set_always_fatal(G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL); + //g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL); g_info("Critical log from glib will abort execution"); } diff --git a/ltt/branches/poly/lttv/lttv/state.c b/ltt/branches/poly/lttv/lttv/state.c index e8eb3db4..ba822513 100644 --- a/ltt/branches/poly/lttv/lttv/state.c +++ b/ltt/branches/poly/lttv/lttv/state.c @@ -172,8 +172,8 @@ restore_init_state(LttvTraceState *self) for(i = 0 ; i < nb_tracefile ; i++) { tfcs = - LTTV_TRACEFILE_STATE(&g_array_index(self->parent.tracefiles, - LttvTracefileContext, i)); + LTTV_TRACEFILE_STATE(g_array_index(self->parent.tracefiles, + LttvTracefileContext*, i)); ltt_trace_time_span_get(self->parent.t, &tfcs->parent.timestamp, NULL); // tfcs->saved_position = 0; tfcs->process = lttv_state_create_process(tfcs, NULL,0); @@ -221,8 +221,8 @@ init(LttvTracesetState *self, LttvTraceset *ts) for(j = 0 ; j < nb_tracefile ; j++) { tfcs = - LTTV_TRACEFILE_STATE(&g_array_index(tc->tracefiles, - LttvTracefileContext, j)); + LTTV_TRACEFILE_STATE(g_array_index(tc->tracefiles, + LttvTracefileContext*, j)); tfcs->cpu_name = ltt_tracefile_name(tfcs->parent.tf); } tcs->processes = NULL; @@ -338,8 +338,8 @@ void lttv_state_write(LttvTraceState *self, LttTime t, FILE *fp) for(i = 0 ; i < nb_tracefile ; i++) { tfcs = - LTTV_TRACEFILE_STATE(&g_array_index(self->parent.tracefiles, - LttvTracefileContext, i)); + LTTV_TRACEFILE_STATE(g_array_index(self->parent.tracefiles, + LttvTracefileContext*, i)); fprintf(fp, " process->pid, tfcs->parent.timestamp.tv_sec, tfcs->parent.timestamp.tv_nsec); @@ -425,8 +425,8 @@ static void state_save(LttvTraceState *self, LttvAttribute *container) for(i = 0 ; i < nb_tracefile ; i++) { tfcs = - LTTV_TRACEFILE_STATE(&g_array_index(self->parent.tracefiles, - LttvTracefileContext, i)); + LTTV_TRACEFILE_STATE(g_array_index(self->parent.tracefiles, + LttvTracefileContext*, i)); tracefile_tree = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); value = lttv_attribute_add(tracefiles_tree, i, LTTV_GOBJECT); @@ -484,8 +484,8 @@ static void state_restore(LttvTraceState *self, LttvAttribute *container) for(i = 0 ; i < nb_tracefile ; i++) { tfcs = - LTTV_TRACEFILE_STATE(&g_array_index(self->parent.tracefiles, - LttvTracefileContext, i)); + LTTV_TRACEFILE_STATE(g_array_index(self->parent.tracefiles, + LttvTracefileContext*, i)); type = lttv_attribute_get(tracefiles_tree, i, &name, &value); g_assert(type == LTTV_GOBJECT); tracefile_tree = *((LttvAttribute **)(value.v_gobject)); @@ -539,8 +539,8 @@ static void state_saved_free(LttvTraceState *self, LttvAttribute *container) for(i = 0 ; i < nb_tracefile ; i++) { tfcs = - LTTV_TRACEFILE_STATE(&g_array_index(self->parent.tracefiles, - LttvTracefileContext, i)); + LTTV_TRACEFILE_STATE(g_array_index(self->parent.tracefiles, + LttvTracefileContext*, i)); type = lttv_attribute_get(tracefiles_tree, i, &name, &value); g_assert(type == LTTV_GOBJECT); tracefile_tree = *((LttvAttribute **)(value.v_gobject)); @@ -857,7 +857,7 @@ lttv_state_create_process(LttvTracefileState *tfs, LttvProcessState *parent, process->pid = pid; process->last_cpu = tfs->cpu_name; process->last_cpu_index = ((LttvTracefileContext*)tfs)->index; - g_warning("Process %u, core %p", process->pid, process); + g_info("Process %u, core %p", process->pid, process); g_hash_table_insert(tcs->processes, process, process); if(parent) { @@ -1320,8 +1320,8 @@ void lttv_state_remove_event_hooks(LttvTracesetState *self) for(j = 0 ; j < nb_tracefile ; j++) { tfs = - LTTV_TRACEFILE_STATE(&g_array_index(ts->parent.tracefiles, - LttvTracefileContext, j)); + LTTV_TRACEFILE_STATE(g_array_index(ts->parent.tracefiles, + LttvTracefileContext*, j)); for(k = 0 ; k < hooks->len ; k++) { hook = &g_array_index(hooks, LttvTraceHook, k); @@ -1523,8 +1523,8 @@ void lttv_state_save_add_event_hooks(LttvTracesetState *self) for(j = 0 ; j < nb_tracefile ; j++) { tfs = - LTTV_TRACEFILE_STATE(&g_array_index(ts->parent.tracefiles, - LttvTracefileContext, j)); + LTTV_TRACEFILE_STATE(g_array_index(ts->parent.tracefiles, + LttvTracefileContext*, j)); lttv_hooks_add(tfs->parent.event, state_save_event_hook, event_count, @@ -1603,8 +1603,8 @@ void lttv_state_save_remove_event_hooks(LttvTracesetState *self) for(j = 0 ; j < nb_tracefile ; j++) { tfs = - LTTV_TRACEFILE_STATE(&g_array_index(ts->parent.tracefiles, - LttvTracefileContext, j)); + LTTV_TRACEFILE_STATE(g_array_index(ts->parent.tracefiles, + LttvTracefileContext*, j)); event_count = lttv_hooks_remove(tfs->parent.event, state_save_event_hook); g_free(event_count); diff --git a/ltt/branches/poly/lttv/lttv/stats.c b/ltt/branches/poly/lttv/lttv/stats.c index 330166ba..bfd88d46 100644 --- a/ltt/branches/poly/lttv/lttv/stats.c +++ b/ltt/branches/poly/lttv/lttv/stats.c @@ -113,8 +113,8 @@ init(LttvTracesetStats *self, LttvTraceset *ts) nb_tracefile = tc->tracefiles->len; for(j = 0 ; j < nb_tracefile ; j++) { - tfcs = LTTV_TRACEFILE_STATS(&g_array_index(tc->tracefiles, - LttvTracefileContext, j)); + tfcs = LTTV_TRACEFILE_STATS(g_array_index(tc->tracefiles, + LttvTracefileContext*, j)); tfcs->stats = lttv_attribute_find_subdir(tracefiles_stats, tfcs->parent.cpu_name); find_event_tree(tfcs, LTTV_STATS_PROCESS_UNKNOWN, @@ -177,8 +177,8 @@ fini(LttvTracesetStats *self) nb_tracefile = tc->tracefiles->len; for(j = 0 ; j < nb_tracefile ; j++) { - tfc = &g_array_index(tc->tracefiles, - LttvTracefileContext, j); + tfc = g_array_index(tc->tracefiles, + LttvTracefileContext*, j); tfcs = (LttvTracefileStats *)tfc; tfcs->stats = NULL; tfcs->current_events_tree = NULL; @@ -954,8 +954,8 @@ void lttv_stats_remove_event_hooks(LttvTracesetStats *self) nb_tracefile = ts->parent.parent.tracefiles->len; for(j = 0 ; j < nb_tracefile ; j++) { - tfs = LTTV_TRACEFILE_STATS(&g_array_index(ts->parent.parent.tracefiles, - LttvTracefileContext, j)); + tfs = LTTV_TRACEFILE_STATS(g_array_index(ts->parent.parent.tracefiles, + LttvTracefileContext*, j)); lttv_hooks_remove_data(tfs->parent.parent.event, every_event, NULL); diff --git a/ltt/branches/poly/lttv/lttv/tracecontext.c b/ltt/branches/poly/lttv/lttv/tracecontext.c index d6ee6c4c..3c8742f6 100644 --- a/ltt/branches/poly/lttv/lttv/tracecontext.c +++ b/ltt/branches/poly/lttv/lttv/tracecontext.c @@ -350,7 +350,7 @@ void lttv_trace_context_add_hooks(LttvTraceContext *self, nb_tracefile = self->tracefiles->len; for(i = 0 ; i < nb_tracefile ; i++) { - tfc = &g_array_index(self->tracefiles, LttvTracefileContext, i); + tfc = g_array_index(self->tracefiles, LttvTracefileContext*, i); lttv_tracefile_context_add_hooks(tfc, before_tracefile, event, @@ -373,7 +373,7 @@ void lttv_trace_context_remove_hooks(LttvTraceContext *self, nb_tracefile = self->tracefiles->len; for(i = 0 ; i < nb_tracefile ; i++) { - tfc = &g_array_index(self->tracefiles, LttvTracefileContext, i); + tfc = g_array_index(self->tracefiles, LttvTracefileContext*, i); lttv_tracefile_context_remove_hooks(tfc, after_tracefile, event, @@ -935,7 +935,7 @@ lttv_trace_find_hook(LttTrace *t, GQuark facility, GQuark event, fac_id = g_array_index(facilities, guint, 0); f = ltt_trace_get_facility_by_num(t, fac_id); - et = ltt_facility_eventtype_get_by_name(f, ltt_eventtype_name(et)); + et = ltt_facility_eventtype_get_by_name(f, event); if(unlikely(et == NULL)) goto event_error; thf = &g_array_index(th->fac_index, LttvTraceHookByFacility, fac_id); -- 2.34.1