From: compudj Date: Mon, 28 Jun 2004 18:47:07 +0000 (+0000) Subject: removed many g_error and exit(1) from the tracefile reader X-Git-Tag: v0.12.20~2875 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=2a74fbf4e7e641f94517b3e996c674291248bb1d;p=lttv.git removed many g_error and exit(1) from the tracefile reader git-svn-id: http://ltt.polymtl.ca/svn@614 04897980-b3bd-0310-b5e0-8ef037075253 --- diff --git a/ltt/branches/poly/ltt/event.c b/ltt/branches/poly/ltt/event.c index 68920d22..a7772d5d 100644 --- a/ltt/branches/poly/ltt/event.c +++ b/ltt/branches/poly/ltt/event.c @@ -305,8 +305,8 @@ gint ltt_event_position_compare(const LttEventPosition *ep1, gint ltt_event_event_position_compare(const LttEvent *event, const LttEventPosition *ep) { - if(event->tracefile != ep->tf) - g_error("ltt_event_position_compare on different tracefiles makes no sense"); + g_assert(event->tracefile == ep->tf); + if(event->which_block < ep->block_num) return -1; if(event->which_block > ep->block_num) @@ -318,6 +318,20 @@ gint ltt_event_event_position_compare(const LttEvent *event, return 0; } +/***************************************************************************** + * Function name + * ltt_event_position_copy : copy position + * Input params + * src : a pointer to event's position structure source + * dest : a pointer to event's position structure dest + * Return + * void + ****************************************************************************/ +void ltt_event_position_copy(LttEventPosition *dest, + const LttEventPosition *src) +{ + *dest = *src; +} /***************************************************************************** @@ -434,8 +448,7 @@ unsigned ltt_event_get_unsigned(LttEvent *e, LttField *f) e->tracefile->trace->system_description->endian ? 0:1; LttTypeEnum t = f->field_type->type_class; - if(t != LTT_UINT && t != LTT_ENUM) - g_error("The type of the field is not unsigned int\n"); + g_assert(t == LTT_UINT || t == LTT_ENUM); if(f->field_size == 1){ guint8 x = *(guint8 *)(e->data + f->offset_root); @@ -466,8 +479,7 @@ int ltt_event_get_int(LttEvent *e, LttField *f) int revFlag = e->tracefile->trace->my_arch_endian == e->tracefile->trace->system_description->endian ? 0:1; - if(f->field_type->type_class != LTT_INT) - g_error("The type of the field is not int\n"); + g_assert(f->field_type->type_class == LTT_INT); if(f->field_size == 1){ gint8 x = *(gint8 *)(e->data + f->offset_root); @@ -499,8 +511,7 @@ unsigned long ltt_event_get_long_unsigned(LttEvent *e, LttField *f) e->tracefile->trace->system_description->endian ? 0:1; LttTypeEnum t = f->field_type->type_class; - if(t != LTT_UINT && t != LTT_ENUM) - g_error("The type of the field is not unsigned long\n"); + g_assert(t == LTT_UINT || t == LTT_ENUM); if(f->field_size == 1){ guint8 x = *(guint8 *)(e->data + f->offset_root); @@ -531,8 +542,7 @@ long int ltt_event_get_long_int(LttEvent *e, LttField *f) int revFlag = e->tracefile->trace->my_arch_endian == e->tracefile->trace->system_description->endian ? 0:1; - if( f->field_type->type_class != LTT_INT) - g_error("The type of the field is not long int\n"); + g_assert( f->field_type->type_class == LTT_INT); if(f->field_size == 1){ gint8 x = *(gint8 *)(e->data + f->offset_root); @@ -563,9 +573,7 @@ float ltt_event_get_float(LttEvent *e, LttField *f) int revFlag = e->tracefile->trace->my_arch_endian == e->tracefile->trace->system_description->endian ? 0:1; - if(f->field_type->type_class != LTT_FLOAT || - (f->field_type->type_class == LTT_FLOAT && f->field_size != 4)) - g_error("The type of the field is not float\n"); + g_assert(f->field_type->type_class == LTT_FLOAT && f->field_size == 4); if(revFlag == 0) return *(float *)(e->data + f->offset_root); else{ @@ -581,9 +589,7 @@ double ltt_event_get_double(LttEvent *e, LttField *f) int revFlag = e->tracefile->trace->my_arch_endian == e->tracefile->trace->system_description->endian ? 0:1; - if(f->field_type->type_class != LTT_FLOAT || - (f->field_type->type_class == LTT_FLOAT && f->field_size != 8)) - g_error("The type of the field is not double\n"); + g_assert(f->field_type->type_class == LTT_FLOAT && f->field_size == 8); if(revFlag == 0) return *(double *)(e->data + f->offset_root); else{ @@ -601,7 +607,7 @@ double ltt_event_get_double(LttEvent *e, LttField *f) char *ltt_event_get_string(LttEvent *e, LttField *f) { - if(f->field_type->type_class != LTT_STRING) - g_error("The field contains no string\n"); + g_assert(f->field_type->type_class == LTT_STRING); + return (char*)g_strdup((char*)(e->data + f->offset_root)); } diff --git a/ltt/branches/poly/ltt/event.h b/ltt/branches/poly/ltt/event.h index 88c03624..2b2eab22 100644 --- a/ltt/branches/poly/ltt/event.h +++ b/ltt/branches/poly/ltt/event.h @@ -74,6 +74,10 @@ gint ltt_event_position_compare(const LttEventPosition *ep1, gint ltt_event_event_position_compare(const LttEvent *event, const LttEventPosition *ep); + +void ltt_event_position_copy(LttEventPosition *dest, + const LttEventPosition *src); + /* CPU id of the event */ unsigned ltt_event_cpu_id(LttEvent *e); diff --git a/ltt/branches/poly/ltt/trace.h b/ltt/branches/poly/ltt/trace.h index 42fff96f..ba66c33a 100644 --- a/ltt/branches/poly/ltt/trace.h +++ b/ltt/branches/poly/ltt/trace.h @@ -26,11 +26,18 @@ descriptions...). When a trace is closed, all the associated facilities, types and fields - are released as well. */ + are released as well. + + return value is NULL if there is an error when opening the trace. + + */ LttTrace *ltt_trace_open(const char *pathname); -/* copy reopens a trace */ +/* copy reopens a trace + * + * return value NULL if error while opening the trace + */ LttTrace *ltt_trace_copy(LttTrace *self); char * ltt_trace_name(LttTrace *t); @@ -128,7 +135,7 @@ LttTracefile * ltt_tracefile_open(LttTrace *t, char * tracefile_name); void ltt_tracefile_open_cpu(LttTrace *t, char * tracefile_name); -void ltt_tracefile_open_control(LttTrace *t, char * control_name); +gint ltt_tracefile_open_control(LttTrace *t, char * control_name); /* obtain the time of an event */ diff --git a/ltt/branches/poly/ltt/tracefile.c b/ltt/branches/poly/ltt/tracefile.c index 225f7eac..493ba559 100644 --- a/ltt/branches/poly/ltt/tracefile.c +++ b/ltt/branches/poly/ltt/tracefile.c @@ -70,8 +70,10 @@ static void parser_start_element (GMarkupParseContext *context, int i=0; LttSystemDescription* des = (LttSystemDescription* )user_data; if(strcmp("system", element_name)){ - g_warning("This is not system.xml file\n"); - exit(1); + *error = g_error_new(G_MARKUP_ERROR, + G_LOG_LEVEL_WARNING, + "This is not system.xml file"); + return; } while(attribute_names[i]){ @@ -113,8 +115,10 @@ static void parser_start_element (GMarkupParseContext *context, }else if(strcmp("ltt_block_size", attribute_names[i])==0){ des->ltt_block_size = atoi(attribute_values[i]); }else{ - g_warning("Not a valid attribute\n"); - exit(1); + *error = g_error_new(G_MARKUP_ERROR, + G_LOG_LEVEL_WARNING, + "Not a valid attribute"); + return; } i++; } @@ -161,12 +165,19 @@ LttTracefile* ltt_tracefile_open(LttTrace * t, char * fileName) tf->trace = t; tf->fd = open(fileName, O_RDONLY, 0); if(tf->fd < 0){ - g_error("Unable to open input data file %s\n", fileName); + g_warning("Unable to open input data file %s\n", fileName); + g_free(tf->name); + g_free(tf); + return NULL; } // Get the file's status if(fstat(tf->fd, &lTDFStat) < 0){ - g_error("Unable to get the status of the input data file %s\n", fileName); + g_warning("Unable to get the status of the input data file %s\n", fileName); + g_free(tf->name); + close(tf->fd); + g_free(tf); + return NULL; } // Is the file large enough to contain a trace @@ -207,7 +218,7 @@ void ltt_tracefile_open_cpu(LttTrace *t, char * tracefile_name) g_ptr_array_add(t->per_cpu_tracefiles, tf); } -void ltt_tracefile_open_control(LttTrace *t, char * control_name) +gint ltt_tracefile_open_control(LttTrace *t, char * control_name) { LttTracefile * tf; LttEvent * ev; @@ -218,7 +229,10 @@ void ltt_tracefile_open_control(LttTrace *t, char * control_name) int i; tf = ltt_tracefile_open(t,control_name); - if(!tf) return; + if(!tf) { + g_warning("ltt_tracefile_open_control : bad file descriptor"); + return -1; + } t->control_tracefile_number++; g_ptr_array_add(t->control_tracefiles,tf); @@ -226,7 +240,7 @@ void ltt_tracefile_open_control(LttTrace *t, char * control_name) if(strcmp(&control_name[strlen(control_name)-10],"facilities") ==0){ while(1){ ev = ltt_tracefile_read(tf); - if(!ev)return; // end of file + if(!ev)return 0; // end of file if(ev->event_id == TRACE_FACILITY_LOAD){ pos = ev->data; @@ -241,16 +255,22 @@ void ltt_tracefile_open_control(LttTrace *t, char * control_name) break; } } - if(i==t->facility_number) - g_error("Facility: %s, checksum: %d is not founded\n", + if(i==t->facility_number) { + g_warning("Facility: %s, checksum: %d is not found\n", fLoad.name,fLoad.checksum); + return -1; + } }else if(ev->event_id == TRACE_BLOCK_START){ continue; }else if(ev->event_id == TRACE_BLOCK_END){ break; - }else g_error("Not valid facilities trace file\n"); + }else { + g_warning("Not valid facilities trace file\n"); + return -1; + } } } + return 0; } /***************************************************************************** @@ -272,14 +292,14 @@ void ltt_tracefile_close(LttTracefile *t) /***************************************************************************** *Get system information ****************************************************************************/ -void getSystemInfo(LttSystemDescription* des, char * pathname) +gint getSystemInfo(LttSystemDescription* des, char * pathname) { FILE * fp; char buf[DIR_NAME_SIZE]; char description[4*DIR_NAME_SIZE]; GMarkupParseContext * context; - GError * error; + GError * error = NULL; GMarkupParser markup_parser = { parser_start_element, @@ -291,25 +311,33 @@ void getSystemInfo(LttSystemDescription* des, char * pathname) fp = fopen(pathname,"r"); if(!fp){ - g_error("Can not open file : %s\n", pathname); + g_warning("Can not open file : %s\n", pathname); + return -1; } context = g_markup_parse_context_new(&markup_parser, 0, des,NULL); while(fgets(buf,DIR_NAME_SIZE, fp) != NULL){ if(!g_markup_parse_context_parse(context, buf, DIR_NAME_SIZE, &error)){ - g_warning("Can not parse xml file: \n%s\n", error->message); - exit(1); + if(error != NULL) { + g_warning("Can not parse xml file: \n%s\n", error->message); + g_error_free(error); + } + g_markup_parse_context_free(context); + fclose(fp); + return -1; } } + g_markup_parse_context_free(context); fclose(fp); + return 0; } /***************************************************************************** *The following functions get facility/tracefile information ****************************************************************************/ -void getFacilityInfo(LttTrace *t, char* eventdefs) +gint getFacilityInfo(LttTrace *t, char* eventdefs) { DIR * dir; struct dirent *entry; @@ -320,7 +348,10 @@ void getFacilityInfo(LttTrace *t, char* eventdefs) char name[DIR_NAME_SIZE]; dir = opendir(eventdefs); - if(!dir) g_error("Can not open directory: %s\n", eventdefs); + if(!dir) { + g_warning("Can not open directory: %s\n", eventdefs); + return -1; + } while((entry = readdir(dir)) != NULL){ ptr = &entry->d_name[strlen(entry->d_name)-4]; @@ -338,16 +369,20 @@ void getFacilityInfo(LttTrace *t, char* eventdefs) setFieldsOffset(NULL, et, NULL, t); } } + return 0; } -void getControlFileInfo(LttTrace *t, char* control) +gint getControlFileInfo(LttTrace *t, char* control) { DIR * dir; struct dirent *entry; char name[DIR_NAME_SIZE]; dir = opendir(control); - if(!dir) g_error("Can not open directory: %s\n", control); + if(!dir) { + g_warning("Can not open directory: %s\n", control); + return -1; + } while((entry = readdir(dir)) != NULL){ if(strcmp(entry->d_name,"facilities") != 0 && @@ -356,19 +391,24 @@ void getControlFileInfo(LttTrace *t, char* control) strcpy(name,control); strcat(name,entry->d_name); - ltt_tracefile_open_control(t,name); + if(ltt_tracefile_open_control(t,name)) + return -1; } closedir(dir); + return 0; } -void getCpuFileInfo(LttTrace *t, char* cpu) +gint getCpuFileInfo(LttTrace *t, char* cpu) { DIR * dir; struct dirent *entry; char name[DIR_NAME_SIZE]; dir = opendir(cpu); - if(!dir) g_error("Can not open directory: %s\n", cpu); + if(!dir) { + g_warning("Can not open directory: %s\n", cpu); + return -1; + } while((entry = readdir(dir)) != NULL){ if(strcmp(entry->d_name,".") != 0 && @@ -380,6 +420,7 @@ void getCpuFileInfo(LttTrace *t, char* cpu) }else continue; } closedir(dir); + return 0; } /***************************************************************************** @@ -446,8 +487,8 @@ LttTrace *ltt_trace_open(const char *pathname) strcat(cpu,"cpu/"); //new trace - t = g_new(LttTrace, 1); sys_description = g_new(LttSystemDescription, 1); + t = g_new(LttTrace, 1); t->pathname = g_strdup(abs_path); t->facility_number = 0; t->control_tracefile_number = 0; @@ -461,16 +502,51 @@ LttTrace *ltt_trace_open(const char *pathname) //get system description strcpy(tmp,info); strcat(tmp,"system.xml"); - getSystemInfo(sys_description, tmp); + if(getSystemInfo(sys_description, tmp)) { + g_ptr_array_free(t->facilities, TRUE); + g_ptr_array_free(t->per_cpu_tracefiles, TRUE); + g_ptr_array_free(t->control_tracefiles, TRUE); + g_free(sys_description); + g_free(t->pathname); + g_free(t); + return NULL; + } + + //get facilities info - getFacilityInfo(t,eventdefs); + if(getFacilityInfo(t,eventdefs)) { + g_ptr_array_free(t->facilities, TRUE); + g_ptr_array_free(t->per_cpu_tracefiles, TRUE); + g_ptr_array_free(t->control_tracefiles, TRUE); + g_free(sys_description); + g_free(t->pathname); + g_free(t); + return NULL; + } //get control tracefile info - getControlFileInfo(t,control); + + if(getControlFileInfo(t,control)) { + g_ptr_array_free(t->facilities, TRUE); + g_ptr_array_free(t->per_cpu_tracefiles, TRUE); + g_ptr_array_free(t->control_tracefiles, TRUE); + g_free(sys_description); + g_free(t->pathname); + g_free(t); + return NULL; + } //get cpu tracefile info - getCpuFileInfo(t,cpu); + if(getCpuFileInfo(t,cpu)) { + g_ptr_array_free(t->facilities, TRUE); + g_ptr_array_free(t->per_cpu_tracefiles, TRUE); + g_ptr_array_free(t->control_tracefiles, TRUE); + g_free(sys_description); + g_free(t->pathname); + g_free(t); + return NULL; + } return t; } diff --git a/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/callbacks.c b/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/callbacks.c index 1871313f..3b0aad1c 100644 --- a/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/callbacks.c +++ b/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/callbacks.c @@ -1072,13 +1072,17 @@ void add_trace(GtkWidget * widget, gpointer user_data) trace_v = lttvwindowtraces_get_trace_by_name(abs_path); if(trace_v == NULL) { trace = ltt_trace_open(abs_path); - if(trace == NULL) g_critical("cannot open trace %s", abs_path); - trace_v = lttv_trace_new(trace); - lttvwindowtraces_add_trace(trace_v); + if(trace == NULL) { + g_warning("cannot open trace %s", abs_path); + } else { + trace_v = lttv_trace_new(trace); + lttvwindowtraces_add_trace(trace_v); + lttvwindow_add_trace(tab, trace_v); + } + } else { + lttvwindow_add_trace(tab, trace_v); } - lttvwindow_add_trace(tab, trace_v); - gtk_widget_destroy((GtkWidget*)file_selector); //update current tab @@ -1406,7 +1410,6 @@ void zoom(GtkWidget * widget, double size) else { /* Center the image on the current time */ - g_critical("update is HERE"); new_time_window.start_time = ltt_time_sub(current_time, ltt_time_div(new_time_window.time_width, 2.0)); /* If on borders, don't fall off */ diff --git a/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/init_module.c b/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/init_module.c index c7eb229e..4428cb4d 100644 --- a/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/init_module.c +++ b/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/init_module.c @@ -91,9 +91,12 @@ void lttv_trace_option(void *hook_data) g_init_trace = lttvwindowtraces_get_trace_by_name(abs_path); if(g_init_trace == NULL) { trace = ltt_trace_open(abs_path); - if(trace == NULL) g_critical("cannot open trace %s", abs_path); - g_init_trace = lttv_trace_new(trace); - lttvwindowtraces_add_trace(g_init_trace); + if(trace == NULL) { + g_warning("cannot open trace %s", abs_path); + } else { + g_init_trace = lttv_trace_new(trace); + lttvwindowtraces_add_trace(g_init_trace); + } } } diff --git a/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/lttvwindowtraces.c b/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/lttvwindowtraces.c index b6136df1..18dc3d3a 100644 --- a/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/lttvwindowtraces.c +++ b/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/lttvwindowtraces.c @@ -69,7 +69,6 @@ LttvTrace *lttvwindowtraces_get_trace_by_name(gchar *path) LttvTrace *trace_v = lttvwindowtraces_get_trace(i); LttTrace *trace; gchar *name; - g_assert(trace_v != NULL); trace = lttv_trace(trace_v);