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.
21 #include <babeltrace/babeltrace.h>
22 #include <babeltrace/format.h>
28 #include <sys/types.h>
31 static char *opt_input_format
;
32 static char *opt_output_format
;
34 static const char *opt_input_path
;
35 static const char *opt_output_path
;
37 int babeltrace_verbose
, babeltrace_debug
;
40 void strlower(char *str
)
57 static struct poptOption long_options
[] = {
58 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
59 { "input-format", 'i', POPT_ARG_STRING
, &opt_input_format
, OPT_NONE
, NULL
, NULL
},
60 { "output-format", 'o', POPT_ARG_STRING
, &opt_output_format
, OPT_NONE
, NULL
, NULL
},
61 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
62 { "list", 'l', POPT_ARG_NONE
, NULL
, OPT_LIST
, NULL
, NULL
},
63 { "verbose", 'v', POPT_ARG_NONE
, NULL
, OPT_VERBOSE
, NULL
, NULL
},
64 { "debug", 'd', POPT_ARG_NONE
, NULL
, OPT_DEBUG
, NULL
, NULL
},
65 { "names", 'n', POPT_ARG_NONE
, NULL
, OPT_NAMES
, NULL
, NULL
},
66 { NULL
, 0, 0, NULL
, 0, NULL
, NULL
},
69 static void list_formats(FILE *fp
)
72 bt_fprintf_format_list(fp
);
75 static void usage(FILE *fp
)
77 fprintf(fp
, "BabelTrace Trace Converter %u.%u\n\n",
78 BABELTRACE_VERSION_MAJOR
,
79 BABELTRACE_VERSION_MINOR
);
80 fprintf(fp
, "usage : babeltrace [OPTIONS] INPUT <OUTPUT>\n");
82 fprintf(fp
, " INPUT Input trace path\n");
83 fprintf(fp
, " OUTPUT Output trace path (default: stdout)\n");
85 fprintf(fp
, " -i, --input-format FORMAT Input trace format (default: ctf)\n");
86 fprintf(fp
, " -o, --output-format FORMAT Output trace format (default: text)\n");
88 fprintf(fp
, " -h, --help This help message\n");
89 fprintf(fp
, " -l, --list List available formats\n");
90 fprintf(fp
, " -v, --verbose Verbose mode\n");
91 fprintf(fp
, " -d, --debug Debug mode\n");
92 fprintf(fp
, " -n, --names Print field names\n");
98 * Return 0 if caller should continue, < 0 if caller should return
99 * error, > 0 if caller should exit without reporting error.
101 static int parse_options(int argc
, char **argv
)
108 return 1; /* exit cleanly */
111 pc
= poptGetContext(NULL
, argc
, (const char **) argv
, long_options
, 0);
112 poptReadDefaultConfig(pc
, 0);
114 while ((opt
= poptGetNextOpt(pc
)) != -1) {
118 ret
= 1; /* exit cleanly */
121 list_formats(stdout
);
125 babeltrace_verbose
= 1;
128 babeltrace_debug
= 1;
139 opt_input_path
= poptGetArg(pc
);
140 if (!opt_input_path
) {
144 opt_output_path
= poptGetArg(pc
);
152 int main(int argc
, char **argv
)
155 struct format
*fmt_read
, *fmt_write
;
156 struct trace_descriptor
*td_read
, *td_write
;
158 ret
= parse_options(argc
, argv
);
160 fprintf(stdout
, "Error parsing options.\n\n");
163 } else if (ret
> 0) {
166 printf_verbose("Verbose mode active.\n");
167 printf_debug("Debug mode active.\n");
169 if (opt_input_format
)
170 strlower(opt_input_format
);
171 if (opt_output_format
)
172 strlower(opt_output_format
);
174 printf_verbose("Converting from file: %s\n", opt_input_path
);
175 printf_verbose("Converting from format: %s\n",
176 opt_input_format
? : "ctf <default>");
177 printf_verbose("Converting to file: %s\n",
178 opt_output_path
? : "<stdout>");
179 printf_verbose("Converting to format: %s\n",
180 opt_output_format
? : "text <default>");
182 if (!opt_input_format
)
183 opt_input_format
= "ctf";
184 if (!opt_output_format
)
185 opt_output_format
= "text";
186 fmt_read
= bt_lookup_format(g_quark_from_static_string(opt_input_format
));
188 fprintf(stdout
, "[error] Format \"%s\" is not supported.\n\n",
192 if (!opt_output_format
)
193 opt_output_format
= "ctf";
194 fmt_write
= bt_lookup_format(g_quark_from_static_string(opt_output_format
));
196 fprintf(stdout
, "[error] format \"%s\" is not supported.\n\n",
201 td_read
= fmt_read
->open_trace(opt_input_path
, O_RDONLY
);
203 fprintf(stdout
, "[error] opening trace \"%s\" for reading.\n\n",
208 td_write
= fmt_write
->open_trace(opt_output_path
, O_RDWR
);
210 fprintf(stdout
, "Error opening trace \"%s\" for writing.\n\n",
211 opt_output_path
? : "<none>");
215 ret
= convert_trace(td_write
, td_read
);
217 fprintf(stdout
, "Error printing trace.\n\n");
218 goto error_copy_trace
;
221 fmt_write
->close_trace(td_write
);
222 fmt_read
->close_trace(td_read
);
227 fmt_write
->close_trace(td_write
);
229 fmt_read
->close_trace(td_read
);
This page took 0.038707 seconds and 5 git commands to generate.