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>
47 #include <sys/types.h>
54 #include <babeltrace/ctf-ir/metadata.h> /* for clocks */
56 #define PARTIAL_ERROR_SLEEP 3 /* 3 seconds */
58 #define DEFAULT_FILE_ARRAY_SIZE 1
60 #define NET_URL_PREFIX "net://"
61 #define NET4_URL_PREFIX "net4://"
62 #define NET6_URL_PREFIX "net6://"
64 static char *opt_input_format
, *opt_output_format
;
67 * We are not freeing opt_input_paths ipath elements when exiting from
68 * main() for backward compatibility with libpop 0.13, which does not
69 * allocate copies for arguments returned by poptGetArg(), and for
70 * general compatibility with the documented behavior. This is known to
71 * cause a small memory leak with libpop 0.16.
73 static GPtrArray
*opt_input_paths
;
74 static char *opt_output_path
;
75 static int opt_stream_intersection
;
77 static struct bt_format
*fmt_read
;
79 void bt_dummy_hook(void);
80 void bt_lttng_live_hook(void);
81 void bt_ctf_hook(void);
82 void bt_ctf_text_hook(void);
83 void bt_ctf_metadata_hook(void);
86 void strlower(char *str
)
89 *str
= tolower((int) *str
);
112 OPT_CLOCK_FORCE_CORRELATE
,
113 OPT_STREAM_INTERSECTION
,
115 OPT_DEBUG_INFO_FULL_PATH
,
116 OPT_DEBUG_INFO_TARGET_PREFIX
,
120 * We are _not_ using POPT_ARG_STRING ability to store directly into
121 * variables, because we want to cast the return to non-const, which is
122 * not possible without using poptGetOptArg explicitly. This helps us
123 * controlling memory allocation correctly without making assumptions
124 * about undocumented behaviors. poptGetOptArg is documented as
125 * requiring the returned const char * to be freed by the caller.
127 static struct poptOption long_options
[] = {
128 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
129 { "output", 'w', POPT_ARG_STRING
, NULL
, OPT_OUTPUT_PATH
, NULL
, NULL
},
130 { "input-format", 'i', POPT_ARG_STRING
, NULL
, OPT_INPUT_FORMAT
, NULL
, NULL
},
131 { "output-format", 'o', POPT_ARG_STRING
, NULL
, OPT_OUTPUT_FORMAT
, NULL
, NULL
},
132 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
133 { "list", 'l', POPT_ARG_NONE
, NULL
, OPT_LIST
, NULL
, NULL
},
134 { "verbose", 'v', POPT_ARG_NONE
, NULL
, OPT_VERBOSE
, NULL
, NULL
},
135 { "debug", 'd', POPT_ARG_NONE
, NULL
, OPT_DEBUG
, NULL
, NULL
},
136 { "names", 'n', POPT_ARG_STRING
, NULL
, OPT_NAMES
, NULL
, NULL
},
137 { "fields", 'f', POPT_ARG_STRING
, NULL
, OPT_FIELDS
, NULL
, NULL
},
138 { "no-delta", 0, POPT_ARG_NONE
, NULL
, OPT_NO_DELTA
, NULL
, NULL
},
139 { "clock-offset", 0, POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET
, NULL
, NULL
},
140 { "clock-offset-ns", 0, POPT_ARG_STRING
, NULL
, OPT_CLOCK_OFFSET_NS
, NULL
, NULL
},
141 { "clock-cycles", 0, POPT_ARG_NONE
, NULL
, OPT_CLOCK_CYCLES
, NULL
, NULL
},
142 { "clock-seconds", 0, POPT_ARG_NONE
, NULL
, OPT_CLOCK_SECONDS
, NULL
, NULL
},
143 { "clock-date", 0, POPT_ARG_NONE
, NULL
, OPT_CLOCK_DATE
, NULL
, NULL
},
144 { "clock-gmt", 0, POPT_ARG_NONE
, NULL
, OPT_CLOCK_GMT
, NULL
, NULL
},
145 { "clock-force-correlate", 0, POPT_ARG_NONE
, NULL
, OPT_CLOCK_FORCE_CORRELATE
, NULL
, NULL
},
146 { "stream-intersection", 0, POPT_ARG_NONE
, NULL
, OPT_STREAM_INTERSECTION
, NULL
, NULL
},
147 #ifdef ENABLE_DEBUG_INFO
148 { "debug-info-dir", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_DIR
, NULL
, NULL
},
149 { "debug-info-full-path", 0, POPT_ARG_NONE
, NULL
, OPT_DEBUG_INFO_FULL_PATH
, NULL
, NULL
},
150 { "debug-info-target-prefix", 0, POPT_ARG_STRING
, NULL
, OPT_DEBUG_INFO_TARGET_PREFIX
, NULL
, NULL
},
152 { NULL
, 0, 0, NULL
, 0, NULL
, NULL
},
155 static void list_formats(FILE *fp
)
158 bt_fprintf_format_list(fp
);
161 static void usage(FILE *fp
)
163 fprintf(fp
, "BabelTrace Trace Viewer and Converter %s\n\n", VERSION
);
164 fprintf(fp
, "usage : babeltrace [OPTIONS] FILE...\n");
166 fprintf(fp
, " FILE Input trace file(s) and/or directory(ies)\n");
167 fprintf(fp
, " (space-separated)\n");
168 fprintf(fp
, " -w, --output OUTPUT Output trace path (default: stdout)\n");
170 fprintf(fp
, " -i, --input-format FORMAT Input trace format (default: ctf)\n");
171 fprintf(fp
, " -o, --output-format FORMAT Output trace format (default: text)\n");
173 fprintf(fp
, " -h, --help This help message\n");
174 fprintf(fp
, " -l, --list List available formats\n");
175 fprintf(fp
, " -v, --verbose Verbose mode\n");
176 fprintf(fp
, " (or set BABELTRACE_VERBOSE environment variable)\n");
177 fprintf(fp
, " -d, --debug Debug mode\n");
178 fprintf(fp
, " (or set BABELTRACE_DEBUG environment variable)\n");
179 fprintf(fp
, " --no-delta Do not print time delta between consecutive events\n");
180 fprintf(fp
, " -n, --names name1<,name2,...> Print field names:\n");
181 fprintf(fp
, " (payload OR args OR arg)\n");
182 fprintf(fp
, " none, all, scope, header, (context OR ctx)\n");
183 fprintf(fp
, " (default: payload,context)\n");
184 fprintf(fp
, " -f, --fields name1<,name2,...> Print additional fields:\n");
185 fprintf(fp
, " all, trace, trace:hostname, trace:domain,\n");
186 fprintf(fp
, " trace:procname, trace:vpid, loglevel, emf, callsite.\n");
187 fprintf(fp
, " (default: trace:hostname,trace:procname,trace:vpid)\n");
188 fprintf(fp
, " --clock-cycles Timestamp in cycles\n");
189 fprintf(fp
, " --clock-offset seconds Clock offset in seconds\n");
190 fprintf(fp
, " --clock-offset-ns ns Clock offset in nanoseconds\n");
191 fprintf(fp
, " --clock-seconds Print the timestamps as [sec.ns]\n");
192 fprintf(fp
, " (default is: [hh:mm:ss.ns])\n");
193 fprintf(fp
, " --clock-date Print clock date\n");
194 fprintf(fp
, " --clock-gmt Print clock in GMT time zone (default: local time zone)\n");
195 fprintf(fp
, " --clock-force-correlate Assume that clocks are inherently correlated\n");
196 fprintf(fp
, " across traces.\n");
197 fprintf(fp
, " --stream-intersection Only print events when all streams are active.\n");
198 #ifdef ENABLE_DEBUG_INFO
199 fprintf(fp
, " --debug-info-dir Directory in which to look for debugging information\n");
200 fprintf(fp
, " files. (default: /usr/lib/debug/)\n");
201 fprintf(fp
, " --debug-info-target-prefix Directory to use as a prefix for executable lookup\n");
202 fprintf(fp
, " --debug-info-full-path Show full debug info source and binary paths (if available)\n");
208 static int get_names_args(poptContext
*pc
)
210 char *str
, *strlist
, *strctx
;
213 opt_payload_field_names
= 0;
214 opt_context_field_names
= 0;
215 strlist
= (char *) poptGetOptArg(*pc
);
219 str
= strtok_r(strlist
, ",", &strctx
);
221 if (!strcmp(str
, "all"))
222 opt_all_field_names
= 1;
223 else if (!strcmp(str
, "scope"))
224 opt_scope_field_names
= 1;
225 else if (!strcmp(str
, "context") || !strcmp(str
, "ctx"))
226 opt_context_field_names
= 1;
227 else if (!strcmp(str
, "header"))
228 opt_header_field_names
= 1;
229 else if (!strcmp(str
, "payload") || !strcmp(str
, "args") || !strcmp(str
, "arg"))
230 opt_payload_field_names
= 1;
231 else if (!strcmp(str
, "none")) {
232 opt_all_field_names
= 0;
233 opt_scope_field_names
= 0;
234 opt_context_field_names
= 0;
235 opt_header_field_names
= 0;
236 opt_payload_field_names
= 0;
238 fprintf(stderr
, "[error] unknown field name type %s\n", str
);
242 } while ((str
= strtok_r(NULL
, ",", &strctx
)));
248 static int get_fields_args(poptContext
*pc
)
250 char *str
, *strlist
, *strctx
;
253 strlist
= (char *) poptGetOptArg(*pc
);
257 str
= strtok_r(strlist
, ",", &strctx
);
259 opt_trace_default_fields
= 0;
260 if (!strcmp(str
, "all"))
262 else if (!strcmp(str
, "trace"))
264 else if (!strcmp(str
, "trace:hostname"))
265 opt_trace_hostname_field
= 1;
266 else if (!strcmp(str
, "trace:domain"))
267 opt_trace_domain_field
= 1;
268 else if (!strcmp(str
, "trace:procname"))
269 opt_trace_procname_field
= 1;
270 else if (!strcmp(str
, "trace:vpid"))
271 opt_trace_vpid_field
= 1;
272 else if (!strcmp(str
, "loglevel"))
273 opt_loglevel_field
= 1;
274 else if (!strcmp(str
, "emf"))
276 else if (!strcmp(str
, "callsite"))
277 opt_callsite_field
= 1;
279 fprintf(stderr
, "[error] unknown field type %s\n", str
);
283 } while ((str
= strtok_r(NULL
, ",", &strctx
)));
290 * Return 0 if caller should continue, < 0 if caller should return
291 * error, > 0 if caller should exit without reporting error.
293 static int parse_options(int argc
, char **argv
)
301 return 1; /* exit cleanly */
304 pc
= poptGetContext(NULL
, argc
, (const char **) argv
, long_options
, 0);
305 poptReadDefaultConfig(pc
, 0);
308 opt_context_field_names
= 1;
309 opt_payload_field_names
= 1;
311 while ((opt
= poptGetNextOpt(pc
)) != -1) {
313 case OPT_OUTPUT_PATH
:
314 opt_output_path
= (char *) poptGetOptArg(pc
);
315 if (!opt_output_path
) {
320 case OPT_INPUT_FORMAT
:
321 opt_input_format
= (char *) poptGetOptArg(pc
);
322 if (!opt_input_format
) {
327 case OPT_OUTPUT_FORMAT
:
328 opt_output_format
= (char *) poptGetOptArg(pc
);
329 if (!opt_output_format
) {
336 ret
= 1; /* exit cleanly */
339 list_formats(stdout
);
343 babeltrace_verbose
= 1;
346 if (get_names_args(&pc
)) {
352 if (get_fields_args(&pc
)) {
358 babeltrace_debug
= 1;
363 case OPT_CLOCK_CYCLES
:
364 opt_clock_cycles
= 1;
366 case OPT_CLOCK_OFFSET
:
371 str
= (char *) poptGetOptArg(pc
);
373 fprintf(stderr
, "[error] Missing --clock-offset argument\n");
378 opt_clock_offset
= strtoll(str
, &endptr
, 0);
379 if (*endptr
!= '\0' || str
== endptr
|| errno
!= 0) {
380 fprintf(stderr
, "[error] Incorrect --clock-offset argument: %s\n", str
);
388 case OPT_CLOCK_SECONDS
:
389 opt_clock_seconds
= 1;
391 case OPT_CLOCK_OFFSET_NS
:
396 str
= (char *) poptGetOptArg(pc
);
398 fprintf(stderr
, "[error] Missing --clock-offset-ns argument\n");
403 opt_clock_offset_ns
= strtoll(str
, &endptr
, 0);
404 if (*endptr
!= '\0' || str
== endptr
|| errno
!= 0) {
405 fprintf(stderr
, "[error] Incorrect --clock-offset-ns argument: %s\n", str
);
420 case OPT_CLOCK_FORCE_CORRELATE
:
421 opt_clock_force_correlate
= 1;
423 case OPT_STREAM_INTERSECTION
:
424 opt_stream_intersection
= 1;
426 case OPT_DEBUG_INFO_DIR
:
427 opt_debug_info_dir
= (char *) poptGetOptArg(pc
);
428 if (!opt_debug_info_dir
) {
433 case OPT_DEBUG_INFO_FULL_PATH
:
434 opt_debug_info_full_path
= 1;
436 case OPT_DEBUG_INFO_TARGET_PREFIX
:
437 opt_debug_info_target_prefix
= (char *) poptGetOptArg(pc
);
438 if (!opt_debug_info_target_prefix
) {
450 ipath
= poptGetArg(pc
);
452 g_ptr_array_add(opt_input_paths
, (gpointer
) ipath
);
454 if (opt_input_paths
->len
== 0) {
466 static GPtrArray
*traversed_paths
= 0;
469 * traverse_trace_dir() is the callback function for File Tree Walk (nftw).
470 * it receives the path of the current entry (file, dir, link..etc) with
471 * a flag to indicate the type of the entry.
472 * if the entry being visited is a directory and contains a metadata file,
473 * then add the path to a global list to be processed later in
474 * add_traces_recursive.
476 static int traverse_trace_dir(const char *fpath
, const struct stat
*sb
,
477 int tflag
, struct FTW
*ftwbuf
)
485 dirfd
= open(fpath
, 0);
487 fprintf(stderr
, "[error] [Context] Unable to open trace "
488 "directory file descriptor.\n");
489 return 0; /* partial error */
491 metafd
= openat(dirfd
, "metadata", O_RDONLY
);
493 closeret
= close(dirfd
);
498 /* No meta data, just return */
503 closeret
= close(metafd
);
508 closeret
= close(dirfd
);
517 /* Add path to the global list */
518 if (traversed_paths
== NULL
) {
519 fprintf(stderr
, "[error] [Context] Invalid open path array.\n");
522 g_ptr_array_add(traversed_paths
, g_string_new(fpath
));
529 * bt_context_add_traces_recursive: Open a trace recursively
531 * Find each trace present in the subdirectory starting from the given
532 * path, and add them to the context. The packet_seek parameter can be
533 * NULL: this specify to use the default format packet_seek.
535 * Return: 0 on success, < 0 on failure, > 0 on partial failure.
536 * Unable to open toplevel: failure.
537 * Unable to open some subdirectory or file: warn and continue (partial
540 int bt_context_add_traces_recursive(struct bt_context
*ctx
, const char *path
,
541 const char *format_str
,
542 void (*packet_seek
)(struct bt_stream_pos
*pos
,
543 size_t offset
, int whence
))
545 int ret
= 0, trace_ids
= 0;
547 if ((strncmp(path
, NET4_URL_PREFIX
, sizeof(NET4_URL_PREFIX
) - 1)) == 0 ||
548 (strncmp(path
, NET6_URL_PREFIX
, sizeof(NET6_URL_PREFIX
) - 1)) == 0 ||
549 (strncmp(path
, NET_URL_PREFIX
, sizeof(NET_URL_PREFIX
) - 1)) == 0) {
550 ret
= bt_context_add_trace(ctx
,
551 path
, format_str
, packet_seek
, NULL
, NULL
);
553 fprintf(stderr
, "[warning] [Context] cannot open trace \"%s\" "
554 "for reading.\n", path
);
558 /* Should lock traversed_paths mutex here if used in multithread */
560 traversed_paths
= g_ptr_array_new();
561 ret
= nftw(path
, traverse_trace_dir
, 10, 0);
563 /* Process the array if ntfw did not return a fatal error */
567 for (i
= 0; i
< traversed_paths
->len
; i
++) {
568 GString
*trace_path
= g_ptr_array_index(traversed_paths
,
570 int trace_id
= bt_context_add_trace(ctx
,
577 fprintf(stderr
, "[warning] [Context] cannot open trace \"%s\" from %s "
578 "for reading.\n", trace_path
->str
, path
);
579 /* Allow to skip erroneous traces. */
580 ret
= 1; /* partial error */
584 g_string_free(trace_path
, TRUE
);
588 g_ptr_array_free(traversed_paths
, TRUE
);
589 traversed_paths
= NULL
;
591 /* Should unlock traversed paths mutex here if used in multithread */
594 * Return an error if no trace can be opened.
596 if (trace_ids
== 0) {
597 fprintf(stderr
, "[error] Cannot open any trace for reading.\n\n");
598 ret
= -ENOENT
; /* failure */
604 int trace_pre_handler(struct bt_trace_descriptor
*td_write
,
605 struct bt_context
*ctx
)
607 struct ctf_text_stream_pos
*sout
;
608 struct trace_collection
*tc
;
611 sout
= container_of(td_write
, struct ctf_text_stream_pos
,
614 if (!sout
->parent
.pre_trace_cb
)
618 for (i
= 0; i
< tc
->array
->len
; i
++) {
619 struct bt_trace_descriptor
*td
=
620 g_ptr_array_index(tc
->array
, i
);
622 ret
= sout
->parent
.pre_trace_cb(&sout
->parent
, td
);
624 fprintf(stderr
, "[error] Writing to trace pre handler failed.\n");
634 int trace_post_handler(struct bt_trace_descriptor
*td_write
,
635 struct bt_context
*ctx
)
637 struct ctf_text_stream_pos
*sout
;
638 struct trace_collection
*tc
;
641 sout
= container_of(td_write
, struct ctf_text_stream_pos
,
644 if (!sout
->parent
.post_trace_cb
)
648 for (i
= 0; i
< tc
->array
->len
; i
++) {
649 struct bt_trace_descriptor
*td
=
650 g_ptr_array_index(tc
->array
, i
);
652 ret
= sout
->parent
.post_trace_cb(&sout
->parent
, td
);
654 fprintf(stderr
, "[error] Writing to trace post handler failed.\n");
664 int convert_trace(struct bt_trace_descriptor
*td_write
,
665 struct bt_context
*ctx
)
667 struct bt_ctf_iter
*iter
;
668 struct ctf_text_stream_pos
*sout
;
669 struct bt_iter_pos
*begin_pos
= NULL
, *end_pos
= NULL
;
670 struct bt_ctf_event
*ctf_event
;
673 sout
= container_of(td_write
, struct ctf_text_stream_pos
,
676 if (!sout
->parent
.event_cb
) {
680 if (opt_stream_intersection
) {
681 iter
= bt_ctf_iter_create_intersect(ctx
, &begin_pos
, &end_pos
);
683 begin_pos
= bt_iter_create_time_pos(NULL
, 0);
684 begin_pos
->type
= BT_SEEK_BEGIN
;
685 iter
= bt_ctf_iter_create(ctx
, begin_pos
, NULL
);
691 while ((ctf_event
= bt_ctf_iter_read_event(iter
))) {
692 ret
= sout
->parent
.event_cb(&sout
->parent
, ctf_event
->parent
->stream
);
694 fprintf(stderr
, "[error] Writing event failed.\n");
697 ret
= bt_iter_next(bt_ctf_get_iter(iter
));
705 bt_ctf_iter_destroy(iter
);
707 bt_iter_free_pos(begin_pos
);
708 bt_iter_free_pos(end_pos
);
712 void call_plugins_hooks(void)
715 bt_lttng_live_hook();
718 bt_ctf_metadata_hook();
721 int main(int argc
, char **argv
)
723 int ret
, partial_error
= 0, open_success
= 0;
724 struct bt_format
*fmt_write
;
725 struct bt_trace_descriptor
*td_write
;
726 struct bt_context
*ctx
;
729 call_plugins_hooks();
731 opt_input_paths
= g_ptr_array_new();
733 ret
= parse_options(argc
, argv
);
735 fprintf(stderr
, "Error parsing options.\n\n");
737 g_ptr_array_free(opt_input_paths
, TRUE
);
739 } else if (ret
> 0) {
740 g_ptr_array_free(opt_input_paths
, TRUE
);
743 printf_verbose("Verbose mode active.\n");
744 printf_debug("Debug mode active.\n");
746 if (opt_input_format
)
747 strlower(opt_input_format
);
748 if (opt_output_format
)
749 strlower(opt_output_format
);
751 printf_verbose("Converting from directory(ies):\n");
752 for (i
= 0; i
< opt_input_paths
->len
; i
++) {
753 const char *ipath
= g_ptr_array_index(opt_input_paths
, i
);
754 printf_verbose(" %s\n", ipath
);
756 printf_verbose("Converting from format: %s\n",
757 opt_input_format
? : "ctf <default>");
758 printf_verbose("Converting to target: %s\n",
759 opt_output_path
? : "<stdout>");
760 printf_verbose("Converting to format: %s\n",
761 opt_output_format
? : "text <default>");
763 if (!opt_input_format
) {
764 opt_input_format
= strdup("ctf");
765 if (!opt_input_format
) {
770 if (!opt_output_format
) {
771 opt_output_format
= strdup("text");
772 if (!opt_output_format
) {
777 fmt_read
= bt_lookup_format(g_quark_from_static_string(opt_input_format
));
779 fprintf(stderr
, "[error] Format \"%s\" is not supported.\n\n",
784 fmt_write
= bt_lookup_format(g_quark_from_static_string(opt_output_format
));
786 fprintf(stderr
, "[error] format \"%s\" is not supported.\n\n",
792 ctx
= bt_context_create();
797 for (i
= 0; i
< opt_input_paths
->len
; i
++) {
798 const char *ipath
= g_ptr_array_index(opt_input_paths
, i
);
799 ret
= bt_context_add_traces_recursive(ctx
, ipath
,
800 opt_input_format
, NULL
);
802 fprintf(stderr
, "[error] opening trace \"%s\" for reading.\n\n",
804 } else if (ret
> 0) {
805 fprintf(stderr
, "[warning] errors occurred when opening trace \"%s\" for reading, continuing anyway.\n\n",
807 open_success
= 1; /* some traces were OK */
810 open_success
= 1; /* all traces were OK */
814 fprintf(stderr
, "[error] none of the specified trace paths could be opened.\n\n");
818 td_write
= fmt_write
->open_trace(opt_output_path
, O_RDWR
, NULL
, NULL
);
820 fprintf(stderr
, "Error opening trace \"%s\" for writing.\n\n",
821 opt_output_path
? : "<none>");
826 * Errors happened when opening traces, but we continue anyway.
827 * sleep to let user see the stderr output before stdout.
830 sleep(PARTIAL_ERROR_SLEEP
);
832 ret
= trace_pre_handler(td_write
, ctx
);
834 fprintf(stderr
, "Error in trace pre handle.\n\n");
835 goto error_copy_trace
;
838 /* For now, we support only CTF iterators */
839 if (fmt_read
->name
== g_quark_from_static_string("ctf")) {
840 ret
= convert_trace(td_write
, ctx
);
842 fprintf(stderr
, "Error printing trace.\n\n");
843 goto error_copy_trace
;
847 ret
= trace_post_handler(td_write
, ctx
);
849 fprintf(stderr
, "Error in trace post handle.\n\n");
850 goto error_copy_trace
;
853 fmt_write
->close_trace(td_write
);
856 printf_verbose("finished converting. Output written to:\n%s\n",
857 opt_output_path
? : "<stdout>");
862 fmt_write
->close_trace(td_write
);
868 /* teardown and exit */
870 free(opt_input_format
);
871 free(opt_output_format
);
872 free(opt_output_path
);
873 free(opt_debug_info_dir
);
874 free(opt_debug_info_target_prefix
);
875 g_ptr_array_free(opt_input_paths
, TRUE
);