| 1 | /* |
| 2 | * babeltrace.c |
| 3 | * |
| 4 | * Babeltrace Trace Converter |
| 5 | * |
| 6 | * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation |
| 7 | * |
| 8 | * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 9 | * |
| 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: |
| 16 | * |
| 17 | * The above copyright notice and this permission notice shall be included in |
| 18 | * all copies or substantial portions of the Software. |
| 19 | */ |
| 20 | |
| 21 | #define _GNU_SOURCE |
| 22 | #include <config.h> |
| 23 | #include <babeltrace/babeltrace.h> |
| 24 | #include <babeltrace/format.h> |
| 25 | #include <babeltrace/context.h> |
| 26 | #include <babeltrace/ctf/types.h> |
| 27 | #include <babeltrace/ctf/events.h> |
| 28 | /* TODO: fix object model for format-agnostic callbacks */ |
| 29 | #include <babeltrace/ctf/events-internal.h> |
| 30 | #include <babeltrace/ctf/iterator.h> |
| 31 | #include <babeltrace/ctf-text/types.h> |
| 32 | #include <babeltrace/iterator.h> |
| 33 | #include <popt.h> |
| 34 | #include <errno.h> |
| 35 | #include <stdlib.h> |
| 36 | #include <ctype.h> |
| 37 | #include <sys/stat.h> |
| 38 | #include <sys/types.h> |
| 39 | #include <fcntl.h> |
| 40 | #include <unistd.h> |
| 41 | #include <inttypes.h> |
| 42 | #include <fts.h> |
| 43 | |
| 44 | #include <babeltrace/ctf-ir/metadata.h> /* for clocks */ |
| 45 | |
| 46 | #define DEFAULT_FILE_ARRAY_SIZE 1 |
| 47 | static char *opt_input_format; |
| 48 | static char *opt_output_format; |
| 49 | |
| 50 | static const char *opt_input_path; |
| 51 | static const char *opt_output_path; |
| 52 | |
| 53 | static struct format *fmt_read; |
| 54 | |
| 55 | void strlower(char *str) |
| 56 | { |
| 57 | while (*str) { |
| 58 | *str = tolower(*str); |
| 59 | str++; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | enum { |
| 64 | OPT_NONE = 0, |
| 65 | OPT_HELP, |
| 66 | OPT_LIST, |
| 67 | OPT_VERBOSE, |
| 68 | OPT_DEBUG, |
| 69 | OPT_NAMES, |
| 70 | OPT_FIELDS, |
| 71 | OPT_NO_DELTA, |
| 72 | OPT_CLOCK_OFFSET, |
| 73 | OPT_CLOCK_RAW, |
| 74 | OPT_CLOCK_SECONDS, |
| 75 | OPT_CLOCK_DATE, |
| 76 | OPT_CLOCK_GMT, |
| 77 | OPT_CLOCK_FORCE_CORRELATE, |
| 78 | }; |
| 79 | |
| 80 | static struct poptOption long_options[] = { |
| 81 | /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ |
| 82 | { "input-format", 'i', POPT_ARG_STRING, &opt_input_format, OPT_NONE, NULL, NULL }, |
| 83 | { "output-format", 'o', POPT_ARG_STRING, &opt_output_format, OPT_NONE, NULL, NULL }, |
| 84 | { "help", 'h', POPT_ARG_NONE, NULL, OPT_HELP, NULL, NULL }, |
| 85 | { "list", 'l', POPT_ARG_NONE, NULL, OPT_LIST, NULL, NULL }, |
| 86 | { "verbose", 'v', POPT_ARG_NONE, NULL, OPT_VERBOSE, NULL, NULL }, |
| 87 | { "debug", 'd', POPT_ARG_NONE, NULL, OPT_DEBUG, NULL, NULL }, |
| 88 | { "names", 'n', POPT_ARG_STRING, NULL, OPT_NAMES, NULL, NULL }, |
| 89 | { "fields", 'f', POPT_ARG_STRING, NULL, OPT_FIELDS, NULL, NULL }, |
| 90 | { "no-delta", 0, POPT_ARG_NONE, NULL, OPT_NO_DELTA, NULL, NULL }, |
| 91 | { "clock-offset", 0, POPT_ARG_STRING, NULL, OPT_CLOCK_OFFSET, NULL, NULL }, |
| 92 | { "clock-raw", 0, POPT_ARG_NONE, NULL, OPT_CLOCK_RAW, NULL, NULL }, |
| 93 | { "clock-seconds", 0, POPT_ARG_NONE, NULL, OPT_CLOCK_SECONDS, NULL, NULL }, |
| 94 | { "clock-date", 0, POPT_ARG_NONE, NULL, OPT_CLOCK_DATE, NULL, NULL }, |
| 95 | { "clock-gmt", 0, POPT_ARG_NONE, NULL, OPT_CLOCK_GMT, NULL, NULL }, |
| 96 | { "clock-force-correlate", 0, POPT_ARG_NONE, NULL, OPT_CLOCK_FORCE_CORRELATE, NULL, NULL }, |
| 97 | { NULL, 0, 0, NULL, 0, NULL, NULL }, |
| 98 | }; |
| 99 | |
| 100 | static void list_formats(FILE *fp) |
| 101 | { |
| 102 | fprintf(fp, "\n"); |
| 103 | bt_fprintf_format_list(fp); |
| 104 | } |
| 105 | |
| 106 | static void usage(FILE *fp) |
| 107 | { |
| 108 | fprintf(fp, "BabelTrace Trace Viewer and Converter %s\n\n", VERSION); |
| 109 | fprintf(fp, "usage : babeltrace [OPTIONS] INPUT <OUTPUT>\n"); |
| 110 | fprintf(fp, "\n"); |
| 111 | fprintf(fp, " INPUT Input trace path\n"); |
| 112 | fprintf(fp, " OUTPUT Output trace path (default: stdout)\n"); |
| 113 | fprintf(fp, "\n"); |
| 114 | fprintf(fp, " -i, --input-format FORMAT Input trace format (default: ctf)\n"); |
| 115 | fprintf(fp, " -o, --output-format FORMAT Output trace format (default: text)\n"); |
| 116 | fprintf(fp, "\n"); |
| 117 | fprintf(fp, " -h, --help This help message\n"); |
| 118 | fprintf(fp, " -l, --list List available formats\n"); |
| 119 | fprintf(fp, " -v, --verbose Verbose mode\n"); |
| 120 | fprintf(fp, " (or set BABELTRACE_VERBOSE environment variable)\n"); |
| 121 | fprintf(fp, " -d, --debug Debug mode\n"); |
| 122 | fprintf(fp, " (or set BABELTRACE_DEBUG environment variable)\n"); |
| 123 | fprintf(fp, " --no-delta Do not print time delta between consecutive events\n"); |
| 124 | fprintf(fp, " -n, --names name1<,name2,...> Print field names:\n"); |
| 125 | fprintf(fp, " (payload OR args OR arg)\n"); |
| 126 | fprintf(fp, " none, all, scope, header, (context OR ctx)\n"); |
| 127 | fprintf(fp, " (default: payload,context)\n"); |
| 128 | fprintf(fp, " -f, --fields name1<,name2,...> Print additional fields:\n"); |
| 129 | fprintf(fp, " all, trace, trace:domain, trace:procname,\n"); |
| 130 | fprintf(fp, " trace:vpid, loglevel.\n"); |
| 131 | fprintf(fp, " --clock-raw Disregard internal clock offset (use raw value)\n"); |
| 132 | fprintf(fp, " --clock-offset seconds Clock offset in seconds\n"); |
| 133 | fprintf(fp, " --clock-seconds Print the timestamps as [sec.ns]\n"); |
| 134 | fprintf(fp, " (default is: [hh:mm:ss.ns])\n"); |
| 135 | fprintf(fp, " --clock-date Print clock date\n"); |
| 136 | fprintf(fp, " --clock-gmt Print clock in GMT time zone (default: local time zone)\n"); |
| 137 | fprintf(fp, " --clock-force-correlate Assume that clocks are inherently correlated\n"); |
| 138 | fprintf(fp, " across traces.\n"); |
| 139 | list_formats(fp); |
| 140 | fprintf(fp, "\n"); |
| 141 | } |
| 142 | |
| 143 | static int get_names_args(poptContext *pc) |
| 144 | { |
| 145 | char *str, *strlist, *strctx; |
| 146 | |
| 147 | opt_payload_field_names = 0; |
| 148 | opt_context_field_names = 0; |
| 149 | strlist = (char *) poptGetOptArg(*pc); |
| 150 | if (!strlist) { |
| 151 | return -EINVAL; |
| 152 | } |
| 153 | str = strtok_r(strlist, ",", &strctx); |
| 154 | do { |
| 155 | if (!strcmp(str, "all")) |
| 156 | opt_all_field_names = 1; |
| 157 | else if (!strcmp(str, "scope")) |
| 158 | opt_scope_field_names = 1; |
| 159 | else if (!strcmp(str, "context") || !strcmp(str, "ctx")) |
| 160 | opt_context_field_names = 1; |
| 161 | else if (!strcmp(str, "header")) |
| 162 | opt_header_field_names = 1; |
| 163 | else if (!strcmp(str, "payload") || !strcmp(str, "args") || !strcmp(str, "arg")) |
| 164 | opt_payload_field_names = 1; |
| 165 | else if (!strcmp(str, "none")) { |
| 166 | opt_all_field_names = 0; |
| 167 | opt_scope_field_names = 0; |
| 168 | opt_context_field_names = 0; |
| 169 | opt_header_field_names = 0; |
| 170 | opt_payload_field_names = 0; |
| 171 | } else { |
| 172 | fprintf(stderr, "[error] unknown field name type %s\n", str); |
| 173 | return -EINVAL; |
| 174 | } |
| 175 | } while ((str = strtok_r(NULL, ",", &strctx))); |
| 176 | return 0; |
| 177 | } |
| 178 | |
| 179 | static int get_fields_args(poptContext *pc) |
| 180 | { |
| 181 | char *str, *strlist, *strctx; |
| 182 | |
| 183 | strlist = (char *) poptGetOptArg(*pc); |
| 184 | if (!strlist) { |
| 185 | return -EINVAL; |
| 186 | } |
| 187 | str = strtok_r(strlist, ",", &strctx); |
| 188 | do { |
| 189 | if (!strcmp(str, "all")) |
| 190 | opt_all_fields = 1; |
| 191 | else if (!strcmp(str, "trace")) |
| 192 | opt_trace_field = 1; |
| 193 | else if (!strcmp(str, "trace:domain")) |
| 194 | opt_trace_domain_field = 1; |
| 195 | else if (!strcmp(str, "trace:procname")) |
| 196 | opt_trace_procname_field = 1; |
| 197 | else if (!strcmp(str, "trace:vpid")) |
| 198 | opt_trace_vpid_field = 1; |
| 199 | else if (!strcmp(str, "loglevel")) |
| 200 | opt_loglevel_field = 1; |
| 201 | else { |
| 202 | fprintf(stderr, "[error] unknown field type %s\n", str); |
| 203 | return -EINVAL; |
| 204 | } |
| 205 | } while ((str = strtok_r(NULL, ",", &strctx))); |
| 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | /* |
| 210 | * Return 0 if caller should continue, < 0 if caller should return |
| 211 | * error, > 0 if caller should exit without reporting error. |
| 212 | */ |
| 213 | static int parse_options(int argc, char **argv) |
| 214 | { |
| 215 | poptContext pc; |
| 216 | int opt, ret = 0; |
| 217 | |
| 218 | if (argc == 1) { |
| 219 | usage(stdout); |
| 220 | return 1; /* exit cleanly */ |
| 221 | } |
| 222 | |
| 223 | pc = poptGetContext(NULL, argc, (const char **) argv, long_options, 0); |
| 224 | poptReadDefaultConfig(pc, 0); |
| 225 | |
| 226 | /* set default */ |
| 227 | opt_context_field_names = 1; |
| 228 | opt_payload_field_names = 1; |
| 229 | |
| 230 | while ((opt = poptGetNextOpt(pc)) != -1) { |
| 231 | switch (opt) { |
| 232 | case OPT_HELP: |
| 233 | usage(stdout); |
| 234 | ret = 1; /* exit cleanly */ |
| 235 | goto end; |
| 236 | case OPT_LIST: |
| 237 | list_formats(stdout); |
| 238 | ret = 1; |
| 239 | goto end; |
| 240 | case OPT_VERBOSE: |
| 241 | babeltrace_verbose = 1; |
| 242 | break; |
| 243 | case OPT_NAMES: |
| 244 | if (get_names_args(&pc)) { |
| 245 | ret = -EINVAL; |
| 246 | goto end; |
| 247 | } |
| 248 | break; |
| 249 | case OPT_FIELDS: |
| 250 | if (get_fields_args(&pc)) { |
| 251 | ret = -EINVAL; |
| 252 | goto end; |
| 253 | } |
| 254 | break; |
| 255 | case OPT_DEBUG: |
| 256 | babeltrace_debug = 1; |
| 257 | break; |
| 258 | case OPT_NO_DELTA: |
| 259 | opt_delta_field = 0; |
| 260 | break; |
| 261 | case OPT_CLOCK_RAW: |
| 262 | opt_clock_raw = 1; |
| 263 | break; |
| 264 | case OPT_CLOCK_OFFSET: |
| 265 | { |
| 266 | char *str, *endptr; |
| 267 | |
| 268 | str = poptGetOptArg(pc); |
| 269 | if (!str) { |
| 270 | fprintf(stderr, "[error] Missing --clock-offset argument\n"); |
| 271 | ret = -EINVAL; |
| 272 | goto end; |
| 273 | } |
| 274 | errno = 0; |
| 275 | opt_clock_offset = strtoull(str, &endptr, 0); |
| 276 | if (*endptr != '\0' || str == endptr || errno != 0) { |
| 277 | fprintf(stderr, "[error] Incorrect --clock-offset argument: %s\n", str); |
| 278 | ret = -EINVAL; |
| 279 | goto end; |
| 280 | } |
| 281 | break; |
| 282 | } |
| 283 | case OPT_CLOCK_SECONDS: |
| 284 | opt_clock_seconds = 1; |
| 285 | break; |
| 286 | case OPT_CLOCK_DATE: |
| 287 | opt_clock_date = 1; |
| 288 | break; |
| 289 | case OPT_CLOCK_GMT: |
| 290 | opt_clock_gmt = 1; |
| 291 | break; |
| 292 | case OPT_CLOCK_FORCE_CORRELATE: |
| 293 | opt_clock_force_correlate = 1; |
| 294 | break; |
| 295 | |
| 296 | default: |
| 297 | ret = -EINVAL; |
| 298 | goto end; |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | opt_input_path = poptGetArg(pc); |
| 303 | if (!opt_input_path) { |
| 304 | ret = -EINVAL; |
| 305 | goto end; |
| 306 | } |
| 307 | opt_output_path = poptGetArg(pc); |
| 308 | |
| 309 | end: |
| 310 | if (pc) { |
| 311 | poptFreeContext(pc); |
| 312 | } |
| 313 | return ret; |
| 314 | } |
| 315 | |
| 316 | |
| 317 | /* |
| 318 | * bt_context_add_traces_recursive: Open a trace recursively |
| 319 | * |
| 320 | * Find each trace present in the subdirectory starting from the given |
| 321 | * path, and add them to the context. The packet_seek parameter can be |
| 322 | * NULL: this specify to use the default format packet_seek. |
| 323 | * |
| 324 | * Return: 0 on success, < 0 on failure, > 0 on partial failure. |
| 325 | * Unable to open toplevel: failure. |
| 326 | * Unable to open some subdirectory or file: warn and continue (partial |
| 327 | * failure); |
| 328 | */ |
| 329 | int bt_context_add_traces_recursive(struct bt_context *ctx, const char *path, |
| 330 | const char *format_str, |
| 331 | void (*packet_seek)(struct stream_pos *pos, |
| 332 | size_t offset, int whence)) |
| 333 | { |
| 334 | FTS *tree; |
| 335 | FTSENT *node; |
| 336 | GArray *trace_ids; |
| 337 | char lpath[PATH_MAX]; |
| 338 | char * const paths[2] = { lpath, NULL }; |
| 339 | int ret = 0; |
| 340 | |
| 341 | /* |
| 342 | * Need to copy path, because fts_open can change it. |
| 343 | * It is the pointer array, not the strings, that are constant. |
| 344 | */ |
| 345 | strncpy(lpath, path, PATH_MAX); |
| 346 | lpath[PATH_MAX - 1] = '\0'; |
| 347 | |
| 348 | tree = fts_open(paths, FTS_NOCHDIR | FTS_LOGICAL, 0); |
| 349 | if (tree == NULL) { |
| 350 | fprintf(stderr, "[error] [Context] Cannot traverse \"%s\" for reading.\n", |
| 351 | path); |
| 352 | return -EINVAL; |
| 353 | } |
| 354 | |
| 355 | trace_ids = g_array_new(FALSE, TRUE, sizeof(int)); |
| 356 | |
| 357 | while ((node = fts_read(tree))) { |
| 358 | int dirfd, metafd; |
| 359 | int closeret; |
| 360 | |
| 361 | if (!(node->fts_info & FTS_D)) |
| 362 | continue; |
| 363 | |
| 364 | dirfd = open(node->fts_accpath, 0); |
| 365 | if (dirfd < 0) { |
| 366 | fprintf(stderr, "[error] [Context] Unable to open trace " |
| 367 | "directory file descriptor.\n"); |
| 368 | ret = 1; /* partial error */ |
| 369 | goto error; |
| 370 | } |
| 371 | metafd = openat(dirfd, "metadata", O_RDONLY); |
| 372 | if (metafd < 0) { |
| 373 | closeret = close(dirfd); |
| 374 | if (closeret < 0) { |
| 375 | perror("close"); |
| 376 | ret = -1; /* failure */ |
| 377 | goto error; |
| 378 | } |
| 379 | continue; |
| 380 | } else { |
| 381 | int trace_id; |
| 382 | |
| 383 | closeret = close(metafd); |
| 384 | if (closeret < 0) { |
| 385 | perror("close"); |
| 386 | ret = -1; /* failure */ |
| 387 | goto error; |
| 388 | } |
| 389 | closeret = close(dirfd); |
| 390 | if (closeret < 0) { |
| 391 | perror("close"); |
| 392 | ret = -1; /* failure */ |
| 393 | goto error; |
| 394 | } |
| 395 | |
| 396 | trace_id = bt_context_add_trace(ctx, |
| 397 | node->fts_accpath, format_str, |
| 398 | packet_seek, NULL, NULL); |
| 399 | if (trace_id < 0) { |
| 400 | fprintf(stderr, "[warning] [Context] opening trace \"%s\" from %s " |
| 401 | "for reading.\n", node->fts_accpath, path); |
| 402 | /* Allow to skip erroneous traces. */ |
| 403 | ret = 1; /* partial error */ |
| 404 | continue; |
| 405 | } |
| 406 | g_array_append_val(trace_ids, trace_id); |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | error: |
| 411 | /* |
| 412 | * Return an error if no trace can be opened. |
| 413 | */ |
| 414 | if (trace_ids->len == 0) { |
| 415 | fprintf(stderr, "[error] Cannot open any trace for reading.\n\n"); |
| 416 | ret = -ENOENT; /* failure */ |
| 417 | } |
| 418 | g_array_free(trace_ids, TRUE); |
| 419 | return ret; |
| 420 | } |
| 421 | |
| 422 | |
| 423 | |
| 424 | int convert_trace(struct trace_descriptor *td_write, |
| 425 | struct bt_context *ctx) |
| 426 | { |
| 427 | struct bt_ctf_iter *iter; |
| 428 | struct ctf_text_stream_pos *sout; |
| 429 | struct bt_iter_pos begin_pos; |
| 430 | struct bt_ctf_event *ctf_event; |
| 431 | int ret; |
| 432 | |
| 433 | sout = container_of(td_write, struct ctf_text_stream_pos, |
| 434 | trace_descriptor); |
| 435 | |
| 436 | begin_pos.type = BT_SEEK_BEGIN; |
| 437 | iter = bt_ctf_iter_create(ctx, &begin_pos, NULL); |
| 438 | if (!iter) { |
| 439 | ret = -1; |
| 440 | goto error_iter; |
| 441 | } |
| 442 | while ((ctf_event = bt_ctf_iter_read_event(iter))) { |
| 443 | ret = sout->parent.event_cb(&sout->parent, ctf_event->parent->stream); |
| 444 | if (ret) { |
| 445 | fprintf(stderr, "[error] Writing event failed.\n"); |
| 446 | goto end; |
| 447 | } |
| 448 | ret = bt_iter_next(bt_ctf_get_iter(iter)); |
| 449 | if (ret < 0) |
| 450 | goto end; |
| 451 | } |
| 452 | ret = 0; |
| 453 | |
| 454 | end: |
| 455 | bt_ctf_iter_destroy(iter); |
| 456 | error_iter: |
| 457 | return ret; |
| 458 | } |
| 459 | |
| 460 | int main(int argc, char **argv) |
| 461 | { |
| 462 | int ret, partial_error = 0; |
| 463 | struct format *fmt_write; |
| 464 | struct trace_descriptor *td_write; |
| 465 | struct bt_context *ctx; |
| 466 | |
| 467 | ret = parse_options(argc, argv); |
| 468 | if (ret < 0) { |
| 469 | fprintf(stderr, "Error parsing options.\n\n"); |
| 470 | usage(stderr); |
| 471 | exit(EXIT_FAILURE); |
| 472 | } else if (ret > 0) { |
| 473 | exit(EXIT_SUCCESS); |
| 474 | } |
| 475 | printf_verbose("Verbose mode active.\n"); |
| 476 | printf_debug("Debug mode active.\n"); |
| 477 | |
| 478 | if (opt_input_format) |
| 479 | strlower(opt_input_format); |
| 480 | if (opt_output_format) |
| 481 | strlower(opt_output_format); |
| 482 | |
| 483 | printf_verbose("Converting from directory: %s\n", opt_input_path); |
| 484 | printf_verbose("Converting from format: %s\n", |
| 485 | opt_input_format ? : "ctf <default>"); |
| 486 | printf_verbose("Converting to directory: %s\n", |
| 487 | opt_output_path ? : "<stdout>"); |
| 488 | printf_verbose("Converting to format: %s\n", |
| 489 | opt_output_format ? : "text <default>"); |
| 490 | |
| 491 | if (!opt_input_format) |
| 492 | opt_input_format = "ctf"; |
| 493 | if (!opt_output_format) |
| 494 | opt_output_format = "text"; |
| 495 | fmt_read = bt_lookup_format(g_quark_from_static_string(opt_input_format)); |
| 496 | if (!fmt_read) { |
| 497 | fprintf(stderr, "[error] Format \"%s\" is not supported.\n\n", |
| 498 | opt_input_format); |
| 499 | exit(EXIT_FAILURE); |
| 500 | } |
| 501 | fmt_write = bt_lookup_format(g_quark_from_static_string(opt_output_format)); |
| 502 | if (!fmt_write) { |
| 503 | fprintf(stderr, "[error] format \"%s\" is not supported.\n\n", |
| 504 | opt_output_format); |
| 505 | exit(EXIT_FAILURE); |
| 506 | } |
| 507 | |
| 508 | ctx = bt_context_create(); |
| 509 | |
| 510 | ret = bt_context_add_traces_recursive(ctx, opt_input_path, |
| 511 | opt_input_format, NULL); |
| 512 | if (ret < 0) { |
| 513 | fprintf(stderr, "[error] opening trace \"%s\" for reading.\n\n", |
| 514 | opt_input_path); |
| 515 | goto error_td_read; |
| 516 | } else if (ret > 0) { |
| 517 | fprintf(stderr, "[warning] errors occurred when opening trace \"%s\" for reading, continuing anyway.\n\n", |
| 518 | opt_input_path); |
| 519 | partial_error = 1; |
| 520 | } |
| 521 | |
| 522 | td_write = fmt_write->open_trace(opt_output_path, O_RDWR, NULL, NULL); |
| 523 | if (!td_write) { |
| 524 | fprintf(stderr, "Error opening trace \"%s\" for writing.\n\n", |
| 525 | opt_output_path ? : "<none>"); |
| 526 | goto error_td_write; |
| 527 | } |
| 528 | |
| 529 | ret = convert_trace(td_write, ctx); |
| 530 | if (ret) { |
| 531 | fprintf(stderr, "Error printing trace.\n\n"); |
| 532 | goto error_copy_trace; |
| 533 | } |
| 534 | |
| 535 | fmt_write->close_trace(td_write); |
| 536 | |
| 537 | bt_context_put(ctx); |
| 538 | printf_verbose("finished converting. Output written to:\n%s\n", |
| 539 | opt_output_path ? : "<stdout>"); |
| 540 | if (partial_error) |
| 541 | exit(EXIT_FAILURE); |
| 542 | else |
| 543 | exit(EXIT_SUCCESS); |
| 544 | |
| 545 | /* Error handling */ |
| 546 | error_copy_trace: |
| 547 | fmt_write->close_trace(td_write); |
| 548 | error_td_write: |
| 549 | bt_context_put(ctx); |
| 550 | error_td_read: |
| 551 | exit(EXIT_FAILURE); |
| 552 | } |