X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=lttv%2Flttv%2Ftraceset.c;h=8d39e948cd21eb0332cf4d559631c16f2138aaf1;hb=b9ce0bad7daf7c0a2333c91fdb1e35d602afe17f;hp=370fa61b3f4bae152c0f0e808042466967a844cb;hpb=9b55aba047555ab16b23b0d94002826c204bb715;p=lttv.git diff --git a/lttv/lttv/traceset.c b/lttv/lttv/traceset.c index 370fa61b..8d39e948 100644 --- a/lttv/lttv/traceset.c +++ b/lttv/lttv/traceset.c @@ -12,8 +12,8 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H @@ -54,12 +54,10 @@ LttvTraceset *lttv_traceset_new(void) ts = g_new(LttvTraceset, 1); ts->filename = NULL; + ts->common_path = NULL; ts->traces = g_ptr_array_new(); ts->context = bt_context_create(); ts->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); - //TODO remove this when we have really mecanism - //s->tmpState = g_new(LttvTraceState *, 1); - //lttv_trace_state_init(s->tmpState,0); /*Initialize iterator to the beginning of the traces*/ begin_pos.type = BT_SEEK_BEGIN; @@ -148,6 +146,7 @@ static LttvTrace *lttv_trace_create(LttvTraceset *ts, const char *path) new_trace->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); new_trace->id = id; new_trace->ref_count = 0; + new_trace->short_name[0] = '\0'; new_trace->traceset = ts; new_trace->state = g_new(LttvTraceState,1); lttv_trace_state_init(new_trace->state,new_trace); @@ -156,6 +155,29 @@ static LttvTrace *lttv_trace_create(LttvTraceset *ts, const char *path) g_ptr_array_set_size(ts->state_trace_handle_index,id+1); g_ptr_array_index(ts->state_trace_handle_index,id) = new_trace->state; + /* Find common path */ + if (ts->common_path == NULL) { + ts->common_path = strdup(path); + } else { + /* TODO ybrosseau 2013-05-24: consider put that in a function */ + int i,j; + for (i = 0; + ts->common_path != '\0'; + i++) { + if (path[i] != ts->common_path[i]) { + /* The common path has changed, redo the other traces */ + for(j = 0; j < ts->traces->len; j++) { + LttvTrace *t = g_ptr_array_index(ts->traces, j); + strncpy(t->short_name, t->full_path+i, TRACE_NAME_SIZE); + } + + break; + } + } + strncpy(new_trace->short_name, path+i, TRACE_NAME_SIZE); + } + new_trace->full_path = strdup(path); + return new_trace; } @@ -186,6 +208,7 @@ LttvTraceset *lttv_traceset_copy(LttvTraceset *s_orig) s = g_new(LttvTraceset, 1); s->filename = NULL; + s->common_path = strdup(s_orig->common_path); s->traces = g_ptr_array_new(); s->state_trace_handle_index = g_ptr_array_new(); for(i=0;itraces->len;i++) @@ -245,6 +268,7 @@ void lttv_traceset_destroy(LttvTraceset *s) if(lttv_trace_get_ref_number(trace) == 0) lttv_trace_destroy(trace); } + free(s->common_path); g_ptr_array_free(s->traces, TRUE); bt_context_put(s->context); g_object_unref(s->a); @@ -268,6 +292,7 @@ LttvHooks *lttv_traceset_get_hooks(LttvTraceset *s) void lttv_trace_destroy(LttvTrace *t) { + free(t->full_path); g_object_unref(t->a); g_free(t); } @@ -278,6 +303,31 @@ void lttv_traceset_add(LttvTraceset *s, LttvTrace *t) g_ptr_array_add(s->traces, t); } +int lttv_traceset_get_trace_index_from_event(LttvEvent *event) +{ + LttvTraceset *ts = event->state->trace->traceset; + + return lttv_traceset_get_trace_index_from_handle_id(ts, bt_ctf_event_get_handle_id(event->bt_event)); +} + +int lttv_traceset_get_trace_index_from_handle_id(LttvTraceset *ts, int handle_id) +{ + int i; + + /* TODO ybrosseau 2013-05-22: use a map to speedup the lookup */ + + for(i = 0; i < ts->traces->len; i++) { + LttvTrace *t = g_ptr_array_index(ts->traces, i); + if (t && t->id == handle_id) { + return i; + } + } + + /* Handle id not found */ + return -1; + +} + int lttv_traceset_add_path(LttvTraceset *ts, char *trace_path) { int ret = -1; @@ -414,7 +464,7 @@ guint lttv_trace_get_num_cpu(LttvTrace *t) return 24; } -LttvTracesetPosition *lttv_traceset_create_current_position(LttvTraceset *traceset) +LttvTracesetPosition *lttv_traceset_create_current_position(const LttvTraceset *traceset) { LttvTracesetPosition *traceset_pos;