4 * Babeltrace Trace Converter
6 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
19 #include <babeltrace/babeltrace.h>
20 #include <babeltrace/format.h>
26 #include <sys/types.h>
29 static char *opt_input_format
;
30 static char *opt_output_format
;
32 static const char *opt_input_path
;
33 static const char *opt_output_path
;
35 int babeltrace_verbose
, babeltrace_debug
;
38 void strlower(char *str
)
55 static struct poptOption long_options
[] = {
56 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
57 { "input-format", 'i', POPT_ARG_STRING
, &opt_input_format
, OPT_NONE
, NULL
, NULL
},
58 { "output-format", 'o', POPT_ARG_STRING
, &opt_output_format
, OPT_NONE
, NULL
, NULL
},
59 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
60 { "list", 'l', POPT_ARG_NONE
, NULL
, OPT_LIST
, NULL
, NULL
},
61 { "verbose", 'v', POPT_ARG_NONE
, NULL
, OPT_VERBOSE
, NULL
, NULL
},
62 { "debug", 'd', POPT_ARG_NONE
, NULL
, OPT_DEBUG
, NULL
, NULL
},
63 { "names", 'n', POPT_ARG_NONE
, NULL
, OPT_NAMES
, NULL
, NULL
},
64 { NULL
, 0, 0, NULL
, 0, NULL
, NULL
},
67 static void list_formats(FILE *fp
)
70 bt_fprintf_format_list(fp
);
73 static void usage(FILE *fp
)
75 fprintf(fp
, "BabelTrace Trace Converter %u.%u\n\n",
76 BABELTRACE_VERSION_MAJOR
,
77 BABELTRACE_VERSION_MINOR
);
78 fprintf(fp
, "usage : babeltrace [OPTIONS] INPUT <OUTPUT>\n");
80 fprintf(fp
, " INPUT Input trace path\n");
81 fprintf(fp
, " OUTPUT Output trace path (default: stdout)\n");
83 fprintf(fp
, " -i, --input-format FORMAT Input trace format (default: ctf)\n");
84 fprintf(fp
, " -o, --output-format FORMAT Output trace format (default: text)\n");
86 fprintf(fp
, " -h, --help This help message\n");
87 fprintf(fp
, " -l, --list List available formats\n");
88 fprintf(fp
, " -v, --verbose Verbose mode\n");
89 fprintf(fp
, " -d, --debug Debug mode\n");
90 fprintf(fp
, " -n, --names Print field names\n");
96 * Return 0 if caller should continue, < 0 if caller should return
97 * error, > 0 if caller should exit without reporting error.
99 static int parse_options(int argc
, char **argv
)
106 return 1; /* exit cleanly */
109 pc
= poptGetContext(NULL
, argc
, (const char **) argv
, long_options
, 0);
110 poptReadDefaultConfig(pc
, 0);
112 while ((opt
= poptGetNextOpt(pc
)) != -1) {
116 ret
= 1; /* exit cleanly */
119 list_formats(stdout
);
123 babeltrace_verbose
= 1;
126 babeltrace_debug
= 1;
137 opt_input_path
= poptGetArg(pc
);
138 if (!opt_input_path
) {
142 opt_output_path
= poptGetArg(pc
);
150 int main(int argc
, char **argv
)
153 struct format
*fmt_read
, *fmt_write
;
154 struct trace_descriptor
*td_read
, *td_write
;
156 ret
= parse_options(argc
, argv
);
158 fprintf(stdout
, "Error parsing options.\n\n");
161 } else if (ret
> 0) {
164 printf_verbose("Verbose mode active.\n");
165 printf_debug("Debug mode active.\n");
167 if (opt_input_format
)
168 strlower(opt_input_format
);
169 if (opt_output_format
)
170 strlower(opt_output_format
);
172 printf_verbose("Converting from file: %s\n", opt_input_path
);
173 printf_verbose("Converting from format: %s\n",
174 opt_input_format
? : "ctf <default>");
175 printf_verbose("Converting to file: %s\n",
176 opt_output_path
? : "<stdout>");
177 printf_verbose("Converting to format: %s\n",
178 opt_output_format
? : "text <default>");
180 if (!opt_input_format
)
181 opt_input_format
= "ctf";
182 if (!opt_output_format
)
183 opt_output_format
= "text";
184 fmt_read
= bt_lookup_format(g_quark_from_static_string(opt_input_format
));
186 fprintf(stdout
, "[error] Format \"%s\" is not supported.\n\n",
190 if (!opt_output_format
)
191 opt_output_format
= "ctf";
192 fmt_write
= bt_lookup_format(g_quark_from_static_string(opt_output_format
));
194 fprintf(stdout
, "[error] format \"%s\" is not supported.\n\n",
199 td_read
= fmt_read
->open_trace(opt_input_path
, O_RDONLY
);
201 fprintf(stdout
, "[error] opening trace \"%s\" for reading.\n\n",
206 td_write
= fmt_write
->open_trace(opt_output_path
, O_RDWR
);
208 fprintf(stdout
, "Error opening trace \"%s\" for writing.\n\n",
209 opt_output_path
? : "<none>");
213 ret
= convert_trace(td_write
, td_read
);
215 fprintf(stdout
, "Error printing trace.\n\n");
216 goto error_copy_trace
;
219 fmt_write
->close_trace(td_write
);
220 fmt_read
->close_trace(td_read
);
225 fmt_write
->close_trace(td_write
);
227 fmt_read
->close_trace(td_read
);
This page took 0.059053 seconds and 4 git commands to generate.