4 * Babeltrace Trace Converter
6 * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
8 * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 #include <babeltrace/babeltrace.h>
30 #include <babeltrace/format.h>
31 #include <babeltrace/context.h>
32 #include <babeltrace/context-internal.h>
33 #include <babeltrace/ctf/types.h>
34 #include <babeltrace/ctf/events.h>
35 /* TODO: fix object model for format-agnostic callbacks */
36 #include <babeltrace/ctf/events-internal.h>
37 #include <babeltrace/ctf/iterator.h>
38 #include <babeltrace/ctf-text/types.h>
39 #include <babeltrace/debug-info.h>
41 #include <babeltrace/iterator.h>
42 #include <babeltrace/plugin/component-factory.h>
48 #include <sys/types.h>
55 #include <babeltrace/ctf-ir/metadata.h> /* for clocks */
57 #define PARTIAL_ERROR_SLEEP 3 /* 3 seconds */
59 #define DEFAULT_FILE_ARRAY_SIZE 1
61 #define NET_URL_PREFIX "net://"
62 #define NET4_URL_PREFIX "net4://"
63 #define NET6_URL_PREFIX "net6://"
65 static char *opt_input_format
, *opt_output_format
;
68 * We are not freeing opt_input_paths ipath elements when exiting from
69 * main() for backward compatibility with libpop 0.13, which does not
70 * allocate copies for arguments returned by poptGetArg(), and for
71 * general compatibility with the documented behavior. This is known to
72 * cause a small memory leak with libpop 0.16.
74 static GPtrArray
*opt_input_paths
;
75 static char *opt_output_path
;
76 static int opt_stream_intersection
;
77 static char *opt_plugin_path
;
79 static struct bt_format
*fmt_read
;
81 void bt_dummy_hook(void);
82 void bt_lttng_live_hook(void);
83 void bt_ctf_hook(void);
84 void bt_ctf_text_hook(void);
85 void bt_ctf_metadata_hook(void);
88 void strlower(char *str
)
91 *str
= tolower((int) *str
);
115 OPT_CLOCK_FORCE_CORRELATE
,
116 OPT_STREAM_INTERSECTION
,
118 OPT_DEBUG_INFO_FULL_PATH
,
119 OPT_DEBUG_INFO_TARGET_PREFIX
,
123 * We are _not_ using POPT_ARG_STRING's ability to store directly into
124 * variables, because we want to cast the return to non-const, which is
125 * not possible without using poptGetOptArg explicitly. This helps us
126 * controlling memory allocation correctly without making assumptions
127 * about undocumented behaviors. poptGetOptArg is documented as
128 * requiring the returned const char * to be freed by the caller.
130 static struct poptOption long_options
[] = {
131 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
132 { "output", 'w', POPT_ARG_STRING
, NULL
, OPT_OUTPUT_PATH
, NULL
, NULL
},
133 { "input-format", 'i', POPT_ARG_STRING
, NULL
, OPT_INPUT_FORMAT
, NULL
, NULL
},
134 { "output-format", 'o', POPT_ARG_STRING
, NULL
, OPT_OUTPUT_FORMAT
, NULL
, NULL
},
135 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
136 { "list", 'l', POPT_ARG_NONE
, NULL
, OPT_LIST
, NULL
, NULL
},
137 { "plugin-path", 0, POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
138 { "verbose", 'v', POPT_ARG_NONE
, NULL
, OPT_VERBOSE
, NULL
, NULL
},
139 { "debug", 'd', POPT_ARG_NONE
, NULL
, OPT_DEBUG
, NULL
, NULL
},
140 { "names", 'n', POPT_ARG_STRING
, NULL
, OPT_NAMES
, NULL
, NULL
},
141 { "fields", 'f', POPT_ARG_STRING
, NULL
, OPT_FIELDS
, NULL
, NULL
},
142 { "no-delta", 0, POPT_ARG_NONE
, NULL
, OPT_NO_DELTA
, NULL
, NULL
},
143 { "clock-offset", 0, POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET
, NULL
, NULL
},
144 { "clock-offset-ns", 0, POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET_NS
, NULL
, NULL
},
145 { "clock-cycles", 0, POPT_ARG_NONE
, NULL
, OPT_CLOCK_CYCLES
, NULL
, NULL
},
146 { "clock-seconds", 0, POPT_ARG_NONE
, NULL
, OPT_CLOCK_SECONDS
, NULL
, NULL
},
147 { "clock-date", 0, POPT_ARG_NONE
, NULL
, OPT_CLOCK_DATE
, NULL
, NULL
},
148 { "clock-gmt", 0, POPT_ARG_NONE
, NULL
, OPT_CLOCK_GMT
, NULL
, NULL
},
149 { "clock-force-correlate", 0, POPT_ARG_NONE
, NULL
, OPT_CLOCK_FORCE_CORRELATE
, NULL
, NULL
},
150 { "stream-intersection", 0, POPT_ARG_NONE
, NULL
, OPT_STREAM_INTERSECTION
, NULL
, NULL
},
151 #ifdef ENABLE_DEBUG_INFO
152 { "debug-info-dir", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_DIR
, NULL
, NULL
},
153 { "debug-info-full-path", 0, POPT_ARG_NONE
, NULL
, OPT_DEBUG_INFO_FULL_PATH
, NULL
, NULL
},
154 { "debug-info-target-prefix", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_TARGET_PREFIX
, NULL
, NULL
},
156 { NULL
, 0, 0, NULL
, 0, NULL
, NULL
},
159 static void list_formats(FILE *fp
)
162 bt_fprintf_format_list(fp
);
165 static void usage(FILE *fp
)
167 fprintf(fp
, "BabelTrace Trace Viewer and Converter %s\n\n", VERSION
);
168 fprintf(fp
, "usage : babeltrace [OPTIONS] FILE...\n");
170 fprintf(fp
, " FILE Input trace file(s) and/or directory(ies)\n");
171 fprintf(fp
, " (space-separated)\n");
172 fprintf(fp
, " -w, --output OUTPUT Output trace path (default: stdout)\n");
174 fprintf(fp
, " -i, --input-format FORMAT Input trace format (default: ctf)\n");
175 fprintf(fp
, " -o, --output-format FORMAT Output trace format (default: text)\n");
177 fprintf(fp
, " -h, --help This help message\n");
178 fprintf(fp
, " -l, --list List available formats\n");
179 fprintf(fp
, " --plugin-path Supplementary plug-in path\n");
180 fprintf(fp
, " -v, --verbose Verbose mode\n");
181 fprintf(fp
, " (or set BABELTRACE_VERBOSE environment variable)\n");
182 fprintf(fp
, " -d, --debug Debug mode\n");
183 fprintf(fp
, " (or set BABELTRACE_DEBUG environment variable)\n");
184 fprintf(fp
, " --no-delta Do not print time delta between consecutive events\n");
185 fprintf(fp
, " -n, --names name1<,name2,...> Print field names:\n");
186 fprintf(fp
, " (payload OR args OR arg)\n");
187 fprintf(fp
, " none, all, scope, header, (context OR ctx)\n");
188 fprintf(fp
, " (default: payload,context)\n");
189 fprintf(fp
, " -f, --fields name1<,name2,...> Print additional fields:\n");
190 fprintf(fp
, " all, trace, trace:hostname, trace:domain,\n");
191 fprintf(fp
, " trace:procname, trace:vpid, loglevel, emf, callsite.\n");
192 fprintf(fp
, " (default: trace:hostname,trace:procname,trace:vpid)\n");
193 fprintf(fp
, " --clock-cycles Timestamp in cycles\n");
194 fprintf(fp
, " --clock-offset seconds Clock offset in seconds\n");
195 fprintf(fp
, " --clock-offset-ns ns Clock offset in nanoseconds\n");
196 fprintf(fp
, " --clock-seconds Print the timestamps as [sec.ns]\n");
197 fprintf(fp
, " (default is: [hh:mm:ss.ns])\n");
198 fprintf(fp
, " --clock-date Print clock date\n");
199 fprintf(fp
, " --clock-gmt Print clock in GMT time zone (default: local time zone)\n");
200 fprintf(fp
, " --clock-force-correlate Assume that clocks are inherently correlated\n");
201 fprintf(fp
, " across traces.\n");
202 fprintf(fp
, " --stream-intersection Only print events when all streams are active.\n");
203 #ifdef ENABLE_DEBUG_INFO
204 fprintf(fp
, " --debug-info-dir Directory in which to look for debugging information\n");
205 fprintf(fp
, " files. (default: /usr/lib/debug/)\n");
206 fprintf(fp
, " --debug-info-target-prefix Directory to use as a prefix for executable lookup\n");
207 fprintf(fp
, " --debug-info-full-path Show full debug info source and binary paths (if available)\n");
213 static int get_names_args(poptContext
*pc
)
215 char *str
, *strlist
, *strctx
;
218 opt_payload_field_names
= 0;
219 opt_context_field_names
= 0;
220 strlist
= (char *) poptGetOptArg(*pc
);
224 str
= strtok_r(strlist
, ",", &strctx
);
226 if (!strcmp(str
, "all"))
227 opt_all_field_names
= 1;
228 else if (!strcmp(str
, "scope"))
229 opt_scope_field_names
= 1;
230 else if (!strcmp(str
, "context") || !strcmp(str
, "ctx"))
231 opt_context_field_names
= 1;
232 else if (!strcmp(str
, "header"))
233 opt_header_field_names
= 1;
234 else if (!strcmp(str
, "payload") || !strcmp(str
, "args") || !strcmp(str
, "arg"))
235 opt_payload_field_names
= 1;
236 else if (!strcmp(str
, "none")) {
237 opt_all_field_names
= 0;
238 opt_scope_field_names
= 0;
239 opt_context_field_names
= 0;
240 opt_header_field_names
= 0;
241 opt_payload_field_names
= 0;
243 fprintf(stderr
, "[error] unknown field name type %s\n", str
);
247 } while ((str
= strtok_r(NULL
, ",", &strctx
)));
253 static int get_fields_args(poptContext
*pc
)
255 char *str
, *strlist
, *strctx
;
258 strlist
= (char *) poptGetOptArg(*pc
);
262 str
= strtok_r(strlist
, ",", &strctx
);
264 opt_trace_default_fields
= 0;
265 if (!strcmp(str
, "all"))
267 else if (!strcmp(str
, "trace"))
269 else if (!strcmp(str
, "trace:hostname"))
270 opt_trace_hostname_field
= 1;
271 else if (!strcmp(str
, "trace:domain"))
272 opt_trace_domain_field
= 1;
273 else if (!strcmp(str
, "trace:procname"))
274 opt_trace_procname_field
= 1;
275 else if (!strcmp(str
, "trace:vpid"))
276 opt_trace_vpid_field
= 1;
277 else if (!strcmp(str
, "loglevel"))
278 opt_loglevel_field
= 1;
279 else if (!strcmp(str
, "emf"))
281 else if (!strcmp(str
, "callsite"))
282 opt_callsite_field
= 1;
284 fprintf(stderr
, "[error] unknown field type %s\n", str
);
288 } while ((str
= strtok_r(NULL
, ",", &strctx
)));
295 * Return 0 if caller should continue, < 0 if caller should return
296 * error, > 0 if caller should exit without reporting error.
298 static int parse_options(int argc
, char **argv
)
306 return 1; /* exit cleanly */
309 pc
= poptGetContext(NULL
, argc
, (const char **) argv
, long_options
, 0);
310 poptReadDefaultConfig(pc
, 0);
313 opt_context_field_names
= 1;
314 opt_payload_field_names
= 1;
316 while ((opt
= poptGetNextOpt(pc
)) != -1) {
318 case OPT_OUTPUT_PATH
:
319 opt_output_path
= (char *) poptGetOptArg(pc
);
320 if (!opt_output_path
) {
325 case OPT_INPUT_FORMAT
:
326 opt_input_format
= (char *) poptGetOptArg(pc
);
327 if (!opt_input_format
) {
332 case OPT_OUTPUT_FORMAT
:
333 opt_output_format
= (char *) poptGetOptArg(pc
);
334 if (!opt_output_format
) {
341 ret
= 1; /* exit cleanly */
344 list_formats(stdout
);
347 case OPT_PLUGIN_PATH
:
348 opt_plugin_path
= (char *) poptGetOptArg(pc
);
349 if (!opt_plugin_path
) {
355 babeltrace_verbose
= 1;
358 if (get_names_args(&pc
)) {
364 if (get_fields_args(&pc
)) {
370 babeltrace_debug
= 1;
375 case OPT_CLOCK_CYCLES
:
376 opt_clock_cycles
= 1;
378 case OPT_CLOCK_OFFSET
:
383 str
= (char *) poptGetOptArg(pc
);
385 fprintf(stderr
, "[error] Missing --clock-offset argument\n");
390 opt_clock_offset
= strtoll(str
, &endptr
, 0);
391 if (*endptr
!= '\0' || str
== endptr
|| errno
!= 0) {
392 fprintf(stderr
, "[error] Incorrect --clock-offset argument: %s\n", str
);
400 case OPT_CLOCK_SECONDS
:
401 opt_clock_seconds
= 1;
403 case OPT_CLOCK_OFFSET_NS
:
408 str
= (char *) poptGetOptArg(pc
);
410 fprintf(stderr
, "[error] Missing --clock-offset-ns argument\n");
415 opt_clock_offset_ns
= strtoll(str
, &endptr
, 0);
416 if (*endptr
!= '\0' || str
== endptr
|| errno
!= 0) {
417 fprintf(stderr
, "[error] Incorrect --clock-offset-ns argument: %s\n", str
);
432 case OPT_CLOCK_FORCE_CORRELATE
:
433 opt_clock_force_correlate
= 1;
435 case OPT_STREAM_INTERSECTION
:
436 opt_stream_intersection
= 1;
438 case OPT_DEBUG_INFO_DIR
:
439 opt_debug_info_dir
= (char *) poptGetOptArg(pc
);
440 if (!opt_debug_info_dir
) {
445 case OPT_DEBUG_INFO_FULL_PATH
:
446 opt_debug_info_full_path
= 1;
448 case OPT_DEBUG_INFO_TARGET_PREFIX
:
449 opt_debug_info_target_prefix
= (char *) poptGetOptArg(pc
);
450 if (!opt_debug_info_target_prefix
) {
462 ipath
= poptGetArg(pc
);
464 g_ptr_array_add(opt_input_paths
, (gpointer
) ipath
);
474 static GPtrArray
*traversed_paths
= 0;
477 * traverse_trace_dir() is the callback function for File Tree Walk (nftw).
478 * it receives the path of the current entry (file, dir, link..etc) with
479 * a flag to indicate the type of the entry.
480 * if the entry being visited is a directory and contains a metadata file,
481 * then add the path to a global list to be processed later in
482 * add_traces_recursive.
484 static int traverse_trace_dir(const char *fpath
, const struct stat
*sb
,
485 int tflag
, struct FTW
*ftwbuf
)
493 dirfd
= open(fpath
, 0);
495 fprintf(stderr
, "[error] [Context] Unable to open trace "
496 "directory file descriptor.\n");
497 return 0; /* partial error */
499 metafd
= openat(dirfd
, "metadata", O_RDONLY
);
501 closeret
= close(dirfd
);
506 /* No meta data, just return */
511 closeret
= close(metafd
);
516 closeret
= close(dirfd
);
525 /* Add path to the global list */
526 if (traversed_paths
== NULL
) {
527 fprintf(stderr
, "[error] [Context] Invalid open path array.\n");
530 g_ptr_array_add(traversed_paths
, g_string_new(fpath
));
537 * bt_context_add_traces_recursive: Open a trace recursively
539 * Find each trace present in the subdirectory starting from the given
540 * path, and add them to the context. The packet_seek parameter can be
541 * NULL: this specify to use the default format packet_seek.
543 * Return: 0 on success, < 0 on failure, > 0 on partial failure.
544 * Unable to open toplevel: failure.
545 * Unable to open some subdirectory or file: warn and continue (partial
548 int bt_context_add_traces_recursive(struct bt_context
*ctx
, const char *path
,
549 const char *format_str
,
550 void (*packet_seek
)(struct bt_stream_pos
*pos
,
551 size_t offset
, int whence
))
553 int ret
= 0, trace_ids
= 0;
555 if ((strncmp(path
, NET4_URL_PREFIX
, sizeof(NET4_URL_PREFIX
) - 1)) == 0 ||
556 (strncmp(path
, NET6_URL_PREFIX
, sizeof(NET6_URL_PREFIX
) - 1)) == 0 ||
557 (strncmp(path
, NET_URL_PREFIX
, sizeof(NET_URL_PREFIX
) - 1)) == 0) {
558 ret
= bt_context_add_trace(ctx
,
559 path
, format_str
, packet_seek
, NULL
, NULL
);
561 fprintf(stderr
, "[warning] [Context] cannot open trace \"%s\" "
562 "for reading.\n", path
);
566 /* Should lock traversed_paths mutex here if used in multithread */
568 traversed_paths
= g_ptr_array_new();
569 ret
= nftw(path
, traverse_trace_dir
, 10, 0);
571 /* Process the array if ntfw did not return a fatal error */
575 for (i
= 0; i
< traversed_paths
->len
; i
++) {
576 GString
*trace_path
= g_ptr_array_index(traversed_paths
,
578 int trace_id
= bt_context_add_trace(ctx
,
585 fprintf(stderr
, "[warning] [Context] cannot open trace \"%s\" from %s "
586 "for reading.\n", trace_path
->str
, path
);
587 /* Allow to skip erroneous traces. */
588 ret
= 1; /* partial error */
592 g_string_free(trace_path
, TRUE
);
596 g_ptr_array_free(traversed_paths
, TRUE
);
597 traversed_paths
= NULL
;
599 /* Should unlock traversed paths mutex here if used in multithread */
602 * Return an error if no trace can be opened.
604 if (trace_ids
== 0) {
605 fprintf(stderr
, "[error] Cannot open any trace for reading.\n\n");
606 ret
= -ENOENT
; /* failure */
612 int trace_pre_handler(struct bt_trace_descriptor
*td_write
,
613 struct bt_context
*ctx
)
615 struct ctf_text_stream_pos
*sout
;
616 struct trace_collection
*tc
;
619 sout
= container_of(td_write
, struct ctf_text_stream_pos
,
622 if (!sout
->parent
.pre_trace_cb
)
626 for (i
= 0; i
< tc
->array
->len
; i
++) {
627 struct bt_trace_descriptor
*td
=
628 g_ptr_array_index(tc
->array
, i
);
630 ret
= sout
->parent
.pre_trace_cb(&sout
->parent
, td
);
632 fprintf(stderr
, "[error] Writing to trace pre handler failed.\n");
642 int trace_post_handler(struct bt_trace_descriptor
*td_write
,
643 struct bt_context
*ctx
)
645 struct ctf_text_stream_pos
*sout
;
646 struct trace_collection
*tc
;
649 sout
= container_of(td_write
, struct ctf_text_stream_pos
,
652 if (!sout
->parent
.post_trace_cb
)
656 for (i
= 0; i
< tc
->array
->len
; i
++) {
657 struct bt_trace_descriptor
*td
=
658 g_ptr_array_index(tc
->array
, i
);
660 ret
= sout
->parent
.post_trace_cb(&sout
->parent
, td
);
662 fprintf(stderr
, "[error] Writing to trace post handler failed.\n");
672 int convert_trace(struct bt_trace_descriptor
*td_write
,
673 struct bt_context
*ctx
)
675 struct bt_ctf_iter
*iter
;
676 struct ctf_text_stream_pos
*sout
;
677 struct bt_iter_pos
*begin_pos
= NULL
, *end_pos
= NULL
;
678 struct bt_ctf_event
*ctf_event
;
681 sout
= container_of(td_write
, struct ctf_text_stream_pos
,
684 if (!sout
->parent
.event_cb
) {
688 if (opt_stream_intersection
) {
689 iter
= bt_ctf_iter_create_intersect(ctx
, &begin_pos
, &end_pos
);
691 begin_pos
= bt_iter_create_time_pos(NULL
, 0);
692 begin_pos
->type
= BT_SEEK_BEGIN
;
693 iter
= bt_ctf_iter_create(ctx
, begin_pos
, NULL
);
699 while ((ctf_event
= bt_ctf_iter_read_event(iter
))) {
700 ret
= sout
->parent
.event_cb(&sout
->parent
, ctf_event
->parent
->stream
);
702 fprintf(stderr
, "[error] Writing event failed.\n");
705 ret
= bt_iter_next(bt_ctf_get_iter(iter
));
713 bt_ctf_iter_destroy(iter
);
715 bt_iter_free_pos(begin_pos
);
716 bt_iter_free_pos(end_pos
);
720 void call_plugins_hooks(void)
723 bt_lttng_live_hook();
726 bt_ctf_metadata_hook();
729 int main(int argc
, char **argv
)
731 int ret
, partial_error
= 0, open_success
= 0;
732 struct bt_format
*fmt_write
;
733 struct bt_trace_descriptor
*td_write
;
734 struct bt_context
*ctx
;
735 struct bt_component_factory
*component_factory
;
738 call_plugins_hooks();
740 opt_input_paths
= g_ptr_array_new();
742 ret
= parse_options(argc
, argv
);
744 fprintf(stderr
, "Error parsing options.\n\n");
746 g_ptr_array_free(opt_input_paths
, TRUE
);
748 } else if (ret
> 0) {
749 g_ptr_array_free(opt_input_paths
, TRUE
);
752 printf_verbose("Verbose mode active.\n");
753 printf_debug("Debug mode active.\n");
755 if (!opt_plugin_path
) {
756 fprintf(stderr
, "No plugin path specified, aborting...\n");
760 printf_verbose("Looking-up plugins at %s",
761 opt_plugin_path
? opt_plugin_path
: "Invalid");
762 component_factory
= bt_component_factory_create();
763 if (!component_factory
) {
764 fprintf(stderr
, "Failed to create component factory.\n");
769 ret
= bt_component_factory_load(component_factory
, opt_plugin_path
);
771 fprintf(stderr
, "Failed to load plugins.\n");
775 if (opt_input_paths
->len
== 0) {
780 if (opt_input_format
)
781 strlower(opt_input_format
);
782 if (opt_output_format
)
783 strlower(opt_output_format
);
785 printf_verbose("Converting from directory(ies):\n");
786 for (i
= 0; i
< opt_input_paths
->len
; i
++) {
787 const char *ipath
= g_ptr_array_index(opt_input_paths
, i
);
788 printf_verbose(" %s\n", ipath
);
790 printf_verbose("Converting from format: %s\n",
791 opt_input_format
? : "ctf <default>");
792 printf_verbose("Converting to target: %s\n",
793 opt_output_path
? : "<stdout>");
794 printf_verbose("Converting to format: %s\n",
795 opt_output_format
? : "text <default>");
797 if (!opt_input_format
) {
798 opt_input_format
= strdup("ctf");
799 if (!opt_input_format
) {
804 if (!opt_output_format
) {
805 opt_output_format
= strdup("text");
806 if (!opt_output_format
) {
811 fmt_read
= bt_lookup_format(g_quark_from_static_string(opt_input_format
));
813 fprintf(stderr
, "[error] Format \"%s\" is not supported.\n\n",
818 fmt_write
= bt_lookup_format(g_quark_from_static_string(opt_output_format
));
820 fprintf(stderr
, "[error] format \"%s\" is not supported.\n\n",
826 ctx
= bt_context_create();
831 for (i
= 0; i
< opt_input_paths
->len
; i
++) {
832 const char *ipath
= g_ptr_array_index(opt_input_paths
, i
);
833 ret
= bt_context_add_traces_recursive(ctx
, ipath
,
834 opt_input_format
, NULL
);
836 fprintf(stderr
, "[error] opening trace \"%s\" for reading.\n\n",
838 } else if (ret
> 0) {
839 fprintf(stderr
, "[warning] errors occurred when opening trace \"%s\" for reading, continuing anyway.\n\n",
841 open_success
= 1; /* some traces were OK */
844 open_success
= 1; /* all traces were OK */
848 fprintf(stderr
, "[error] none of the specified trace paths could be opened.\n\n");
852 td_write
= fmt_write
->open_trace(opt_output_path
, O_RDWR
, NULL
, NULL
);
854 fprintf(stderr
, "Error opening trace \"%s\" for writing.\n\n",
855 opt_output_path
? : "<none>");
860 * Errors happened when opening traces, but we continue anyway.
861 * sleep to let user see the stderr output before stdout.
864 sleep(PARTIAL_ERROR_SLEEP
);
866 ret
= trace_pre_handler(td_write
, ctx
);
868 fprintf(stderr
, "Error in trace pre handle.\n\n");
869 goto error_copy_trace
;
872 /* For now, we support only CTF iterators */
873 if (fmt_read
->name
== g_quark_from_static_string("ctf")) {
874 ret
= convert_trace(td_write
, ctx
);
876 fprintf(stderr
, "Error printing trace.\n\n");
877 goto error_copy_trace
;
881 ret
= trace_post_handler(td_write
, ctx
);
883 fprintf(stderr
, "Error in trace post handle.\n\n");
884 goto error_copy_trace
;
887 fmt_write
->close_trace(td_write
);
890 printf_verbose("finished converting. Output written to:\n%s\n",
891 opt_output_path
? : "<stdout>");
896 fmt_write
->close_trace(td_write
);
902 /* teardown and exit */
904 free(opt_input_format
);
905 free(opt_output_format
);
906 free(opt_output_path
);
907 free(opt_debug_info_dir
);
908 free(opt_debug_info_target_prefix
);
909 g_ptr_array_free(opt_input_paths
, TRUE
);