From: compudj Date: Tue, 23 Aug 2005 15:18:45 +0000 (+0000) Subject: add trace verification at opening X-Git-Tag: v0.12.20~2430 X-Git-Url: http://git.lttng.org./?a=commitdiff_plain;h=b56dcdf2c3128db9165e0de6476ca5b799338486;hp=23bb9b6b5c24b17e7d96d5216fe7e5a8d7731d45;p=lttv.git add trace verification at opening git-svn-id: http://ltt.polymtl.ca/svn@1059 04897980-b3bd-0310-b5e0-8ef037075253 --- diff --git a/ltt/branches/poly/ltt/ltt-private.h b/ltt/branches/poly/ltt/ltt-private.h index 4040433d..929e54ae 100644 --- a/ltt/branches/poly/ltt/ltt-private.h +++ b/ltt/branches/poly/ltt/ltt-private.h @@ -345,7 +345,8 @@ struct _LttTrace{ GArray *facilities_by_num; /* fac_id as index in array */ GData *facilities_by_name; /* fac name (GQuark) as index */ /* Points to array of fac_id of all the - * facilities that has this name. */ + * facilities that has this name. */ + guint num_cpu; guint32 arch_type; guint32 arch_variant; diff --git a/ltt/branches/poly/ltt/trace.h b/ltt/branches/poly/ltt/trace.h index 7736d8f3..509a3886 100644 --- a/ltt/branches/poly/ltt/trace.h +++ b/ltt/branches/poly/ltt/trace.h @@ -47,6 +47,7 @@ GQuark ltt_trace_name(const LttTrace *t); void ltt_trace_close(LttTrace *t); +guint ltt_trace_get_num_cpu(LttTrace *t); LttSystemDescription *ltt_trace_system_description(LttTrace *t); diff --git a/ltt/branches/poly/ltt/tracefile.c b/ltt/branches/poly/ltt/tracefile.c index fc1f4583..6fe13f1d 100644 --- a/ltt/branches/poly/ltt/tracefile.c +++ b/ltt/branches/poly/ltt/tracefile.c @@ -185,6 +185,11 @@ LttFacility *ltt_trace_get_facility_by_num(LttTrace *t, } +guint ltt_trace_get_num_cpu(LttTrace *t) +{ + return t->num_cpu; +} + /***************************************************************************** *Function name @@ -966,8 +971,14 @@ LttTrace *ltt_trace_open(const gchar *pathname) LttTrace * t; LttTracefile *tf; GArray *group; - int i; + int i, ret; struct ltt_block_start_header *header; + DIR *dir; + struct dirent *entry; + guint control_found = 0; + guint eventdefs_found = 0; + struct stat stat_buf; + gchar path[PATH_MAX]; t = g_new(LttTrace, 1); if(!t) goto alloc_error; @@ -975,11 +986,40 @@ LttTrace *ltt_trace_open(const gchar *pathname) get_absolute_pathname(pathname, abs_path); t->pathname = g_quark_from_string(abs_path); - /* Open all the tracefiles */ g_datalist_init(&t->tracefiles); + + /* Test to see if it looks like a trace */ + dir = opendir(abs_path); + if(dir == NULL) { + perror(abs_path); + goto open_error; + } + while((entry = readdir(dir)) != NULL) { + strcpy(path, abs_path); + strcat(path, "/"); + strcat(path, entry->d_name); + ret = stat(path, &stat_buf); + if(ret == -1) { + perror(path); + continue; + } + if(S_ISDIR(stat_buf.st_mode)) { + if(strcmp(entry->d_name, "control") == 0) { + control_found = 1; + } + if(strcmp(entry->d_name, "eventdefs") == 0) { + eventdefs_found = 1; + } + } + } + closedir(dir); + + if(!control_found || !eventdefs_found) goto find_error; + + /* Open all the tracefiles */ if(open_tracefiles(t, abs_path, "")) { g_warning("Error opening tracefile %s", abs_path); - goto open_error; + goto find_error; } /* Prepare the facilities containers : array and mapping */ @@ -1012,7 +1052,8 @@ LttTrace *ltt_trace_open(const gchar *pathname) t->has_heartbeat = header->trace.has_heartbeat; t->has_alignment = header->trace.has_alignment; t->has_tsc = header->trace.has_tsc; - + + t->num_cpu = group->len; for(i=0; ilen; i++) { tf = &g_array_index (group, LttTracefile, i); @@ -1026,8 +1067,9 @@ LttTrace *ltt_trace_open(const gchar *pathname) facilities_error: g_datalist_clear(&t->facilities_by_name); g_array_free(t->facilities_by_num, TRUE); -open_error: +find_error: g_datalist_clear(&t->tracefiles); +open_error: g_free(t); alloc_error: return NULL;