X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=lib%2Fcontext.c;fp=lib%2Fcontext.c;h=3617bcd61447775ebb1313b030f59e7c1249d282;hp=45aab34bdfc71c1b78bc9c409d42e70230b307b3;hb=61cf588beae752e5ddfc60b6b5310f769ac9e852;hpb=128e68e8230a4001c4dbab6dfdcdf986c7c45113 diff --git a/lib/context.c b/lib/context.c index 45aab34b..3617bcd6 100644 --- a/lib/context.c +++ b/lib/context.c @@ -115,7 +115,7 @@ int bt_context_add_trace(struct bt_context *ctx, const char *path, fprintf(stderr, "[error] [Context] Creating trace handle %s .\n\n", path); ret = -1; - goto error; + goto error_close; } handle->format = fmt; handle->td = td; @@ -124,41 +124,67 @@ int bt_context_add_trace(struct bt_context *ctx, const char *path, handle->path[PATH_MAX - 1] = '\0'; } + ret = bt_trace_collection_add(ctx->tc, td); + if (ret != 0) + goto error_destroy_handle; + if (fmt->set_handle) fmt->set_handle(td, handle); if (fmt->set_context) fmt->set_context(td, ctx); - /* Add new handle to container */ - g_hash_table_insert(ctx->trace_handles, - (gpointer) (unsigned long) handle->id, - handle); - ret = bt_trace_collection_add(ctx->tc, td); - if (ret != 0) - goto error; - if (fmt->convert_index_timestamp) { ret = fmt->convert_index_timestamp(td); if (ret < 0) - goto error; + goto error_collection_del; + } + + if (fmt->timestamp_begin) { + ret = fmt->timestamp_begin(td, handle, BT_CLOCK_REAL, + &handle->real_timestamp_begin); + if (ret < 0 && ret != -ENOENT) { + ret = -1; + goto error_collection_del; + } + } + if (fmt->timestamp_end) { + ret = fmt->timestamp_end(td, handle, BT_CLOCK_REAL, + &handle->real_timestamp_end); + if (ret < 0 && ret != -ENOENT) { + ret = -1; + goto error_collection_del; + } + } + if (fmt->timestamp_begin) { + ret = fmt->timestamp_begin(td, handle, BT_CLOCK_CYCLES, + &handle->cycles_timestamp_begin); + if (ret < 0 && ret != -ENOENT) { + ret = -1; + goto error_collection_del; + } + } + if (fmt->timestamp_end) { + ret = fmt->timestamp_end(td, handle, BT_CLOCK_CYCLES, + &handle->cycles_timestamp_end); + if (ret < 0 && ret != -ENOENT) { + ret = -1; + goto error_collection_del; + } } - if (fmt->timestamp_begin) - handle->real_timestamp_begin = fmt->timestamp_begin(td, - handle, BT_CLOCK_REAL); - if (fmt->timestamp_end) - handle->real_timestamp_end = fmt->timestamp_end(td, handle, - BT_CLOCK_REAL); - if (fmt->timestamp_begin) - handle->cycles_timestamp_begin = fmt->timestamp_begin(td, - handle, BT_CLOCK_CYCLES); - if (fmt->timestamp_end) - handle->cycles_timestamp_end = fmt->timestamp_end(td, handle, - BT_CLOCK_CYCLES); + /* Add new handle to container */ + g_hash_table_insert(ctx->trace_handles, + (gpointer) (unsigned long) handle->id, + handle); return handle->id; -error: +error_collection_del: + /* Remove from containers */ + bt_trace_collection_remove(handle->td->ctx->tc, handle->td); +error_destroy_handle: + bt_trace_handle_destroy(handle); +error_close: closeret = fmt->close_trace(td); if (closeret) { fprintf(stderr, "Error in close_trace callback\n");