X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=converter%2Fbabeltrace.c;h=a34af175f9e817545c3b9ef2cf2863aa487ae151;hb=7237592a76cceda97a1c79904fed583e215d3fa9;hp=fe7d39fa49b5b13d1fc7185c9f36e0a9c714ac8d;hpb=c462e188f3e7819c7bc74f671038cdbf36e8c3c0;p=babeltrace.git diff --git a/converter/babeltrace.c b/converter/babeltrace.c index fe7d39fa..a34af175 100644 --- a/converter/babeltrace.c +++ b/converter/babeltrace.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include /* TODO: fix object model for format-agnostic callbacks */ @@ -68,7 +69,7 @@ static char *opt_input_format, *opt_output_format; static GPtrArray *opt_input_paths; static char *opt_output_path; -static struct format *fmt_read; +static struct bt_format *fmt_read; static void strlower(char *str) @@ -109,7 +110,7 @@ enum { */ static struct poptOption long_options[] = { /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ - { "output", 'w', POPT_ARG_STRING, NULL, OPT_NONE, NULL, NULL }, + { "output", 'w', POPT_ARG_STRING, NULL, OPT_OUTPUT_PATH, NULL, NULL }, { "input-format", 'i', POPT_ARG_STRING, NULL, OPT_INPUT_FORMAT, NULL, NULL }, { "output-format", 'o', POPT_ARG_STRING, NULL, OPT_OUTPUT_FORMAT, NULL, NULL }, { "help", 'h', POPT_ARG_NONE, NULL, OPT_HELP, NULL, NULL }, @@ -204,7 +205,6 @@ static int get_names_args(poptContext *pc) opt_payload_field_names = 0; } else { fprintf(stderr, "[error] unknown field name type %s\n", str); - free(strlist); ret = -EINVAL; goto end; } @@ -461,7 +461,7 @@ static int traverse_trace_dir(const char *fpath, const struct stat *sb, */ int bt_context_add_traces_recursive(struct bt_context *ctx, const char *path, const char *format_str, - void (*packet_seek)(struct stream_pos *pos, + void (*packet_seek)(struct bt_stream_pos *pos, size_t offset, int whence)) { @@ -516,7 +516,68 @@ int bt_context_add_traces_recursive(struct bt_context *ctx, const char *path, return ret; } -int convert_trace(struct trace_descriptor *td_write, +static +int trace_pre_handler(struct bt_trace_descriptor *td_write, + struct bt_context *ctx) +{ + struct ctf_text_stream_pos *sout; + struct trace_collection *tc; + int ret, i; + + sout = container_of(td_write, struct ctf_text_stream_pos, + trace_descriptor); + + if (!sout->parent.pre_trace_cb) + return 0; + + tc = ctx->tc; + for (i = 0; i < tc->array->len; i++) { + struct bt_trace_descriptor *td = + g_ptr_array_index(tc->array, i); + + ret = sout->parent.pre_trace_cb(&sout->parent, td); + if (ret) { + fprintf(stderr, "[error] Writing to trace pre handler failed.\n"); + goto end; + } + } + ret = 0; +end: + return ret; +} + +static +int trace_post_handler(struct bt_trace_descriptor *td_write, + struct bt_context *ctx) +{ + struct ctf_text_stream_pos *sout; + struct trace_collection *tc; + int ret, i; + + sout = container_of(td_write, struct ctf_text_stream_pos, + trace_descriptor); + + if (!sout->parent.post_trace_cb) + return 0; + + tc = ctx->tc; + for (i = 0; i < tc->array->len; i++) { + struct bt_trace_descriptor *td = + g_ptr_array_index(tc->array, i); + + ret = sout->parent.post_trace_cb(&sout->parent, td); + if (ret) { + fprintf(stderr, "[error] Writing to trace post handler failed.\n"); + goto end; + } + } + ret = 0; +end: + return ret; +} + +static +int convert_trace(struct bt_trace_descriptor *td_write, struct bt_context *ctx) { struct bt_ctf_iter *iter; @@ -528,6 +589,9 @@ int convert_trace(struct trace_descriptor *td_write, sout = container_of(td_write, struct ctf_text_stream_pos, trace_descriptor); + if (!sout->parent.event_cb) + return 0; + begin_pos.type = BT_SEEK_BEGIN; iter = bt_ctf_iter_create(ctx, &begin_pos, NULL); if (!iter) { @@ -555,8 +619,8 @@ error_iter: int main(int argc, char **argv) { int ret, partial_error = 0, open_success = 0; - struct format *fmt_write; - struct trace_descriptor *td_write; + struct bt_format *fmt_write; + struct bt_trace_descriptor *td_write; struct bt_context *ctx; int i; @@ -587,7 +651,7 @@ int main(int argc, char **argv) } printf_verbose("Converting from format: %s\n", opt_input_format ? : "ctf "); - printf_verbose("Converting to directory: %s\n", + printf_verbose("Converting to target: %s\n", opt_output_path ? : ""); printf_verbose("Converting to format: %s\n", opt_output_format ? : "text "); @@ -607,7 +671,7 @@ int main(int argc, char **argv) } } fmt_read = bt_lookup_format(g_quark_from_static_string(opt_input_format)); - if (!fmt_read) { + if (!fmt_read || fmt_read->name != g_quark_from_static_string("ctf")) { fprintf(stderr, "[error] Format \"%s\" is not supported.\n\n", opt_input_format); partial_error = 1; @@ -661,12 +725,24 @@ int main(int argc, char **argv) if (partial_error) sleep(PARTIAL_ERROR_SLEEP); + ret = trace_pre_handler(td_write, ctx); + if (ret) { + fprintf(stderr, "Error in trace pre handle.\n\n"); + goto error_copy_trace; + } + ret = convert_trace(td_write, ctx); if (ret) { fprintf(stderr, "Error printing trace.\n\n"); goto error_copy_trace; } + ret = trace_post_handler(td_write, ctx); + if (ret) { + fprintf(stderr, "Error in trace post handle.\n\n"); + goto error_copy_trace; + } + fmt_write->close_trace(td_write); bt_context_put(ctx);