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/plugin/component-factory.h>
31 #include <babeltrace/plugin/plugin.h>
32 #include <babeltrace/plugin/component-class.h>
33 #include <babeltrace/ref.h>
34 #include <babeltrace/values.h>
36 #include <babeltrace/ctf-ir/metadata.h> /* for clocks */
42 static char *opt_plugin_path
;
43 static char *opt_input_path
;
55 * We are _not_ using POPT_ARG_STRING's ability to store directly into
56 * variables, because we want to cast the return to non-const, which is
57 * not possible without using poptGetOptArg explicitly. This helps us
58 * controlling memory allocation correctly without making assumptions
59 * about undocumented behaviors. poptGetOptArg is documented as
60 * requiring the returned const char * to be freed by the caller.
62 static struct poptOption long_options
[] = {
63 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
64 { "plugin-path", 0, POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, NULL
, NULL
},
65 { "input-path", 0, POPT_ARG_STRING
, NULL
, OPT_INPUT_PATH
, NULL
, NULL
},
66 { "verbose", 'v', POPT_ARG_NONE
, NULL
, OPT_VERBOSE
, NULL
, NULL
},
67 { "debug", 'd', POPT_ARG_NONE
, NULL
, OPT_DEBUG
, NULL
, NULL
},
68 { NULL
, 0, 0, NULL
, 0, NULL
, NULL
},
72 * Return 0 if caller should continue, < 0 if caller should return
73 * error, > 0 if caller should exit without reporting error.
75 static int parse_options(int argc
, char **argv
)
81 return 1; /* exit cleanly */
84 pc
= poptGetContext(NULL
, argc
, (const char **) argv
, long_options
, 0);
85 poptReadDefaultConfig(pc
, 0);
88 opt_context_field_names
= 1;
89 opt_payload_field_names
= 1;
91 while ((opt
= poptGetNextOpt(pc
)) != -1) {
94 ret
= 1; /* exit cleanly */
97 opt_plugin_path
= (char *) poptGetOptArg(pc
);
98 if (!opt_plugin_path
) {
104 babeltrace_verbose
= 1;
107 babeltrace_debug
= 1;
110 opt_input_path
= (char *) poptGetOptArg(pc
);
111 if (!opt_input_path
) {
130 const char *component_type_str(enum bt_component_type type
)
133 case BT_COMPONENT_TYPE_SOURCE
:
135 case BT_COMPONENT_TYPE_SINK
:
137 case BT_COMPONENT_TYPE_FILTER
:
139 case BT_COMPONENT_TYPE_UNKNOWN
:
146 void print_found_component_classes(struct bt_component_factory
*factory
)
150 if (!babeltrace_verbose
) {
154 count
= bt_component_factory_get_component_class_count(factory
);
156 fprintf(stderr
, "No component classes found. Please make sure your plug-in search path is set correctly.");
160 printf_verbose("Found %d component classes.\n", count
);
161 for (i
= 0; i
< count
; i
++) {
162 struct bt_component_class
*component_class
=
163 bt_component_factory_get_component_class_index(
165 struct bt_plugin
*plugin
= bt_component_class_get_plugin(
167 const char *plugin_name
= bt_plugin_get_name(plugin
);
168 const char *component_name
= bt_component_class_get_name(
170 const char *path
= bt_plugin_get_path(plugin
);
171 const char *author
= bt_plugin_get_author(plugin
);
172 const char *license
= bt_plugin_get_license(plugin
);
173 const char *plugin_description
= bt_plugin_get_description(
175 const char *component_description
=
176 bt_component_class_get_description(
178 enum bt_component_type type
= bt_component_class_get_type(
181 printf_verbose("[%s - %s (%s)]\n", plugin_name
, component_name
,
182 component_type_str(type
));
183 printf_verbose("\tpath: %s\n", path
);
184 printf_verbose("\tauthor: %s\n", author
);
185 printf_verbose("\tlicense: %s\n", license
);
186 printf_verbose("\tplugin description: %s\n",
187 plugin_description
? plugin_description
: "None");
188 printf_verbose("\tcomponent description: %s\n",
189 component_description
? component_description
: "None");
192 bt_put(component_class
);
196 int main(int argc
, char **argv
)
199 enum bt_value_status value_status
;
200 struct bt_component_factory
*component_factory
= NULL
;
201 struct bt_component_class
*source_class
= NULL
, *sink_class
= NULL
;
202 struct bt_component
*source
= NULL
, *sink
= NULL
;
203 struct bt_value
*source_params
= NULL
, *sink_params
= NULL
;
205 ret
= parse_options(argc
, argv
);
207 fprintf(stderr
, "Error parsing options.\n\n");
209 } else if (ret
> 0) {
213 source_params
= bt_value_map_create();
214 if (!source_params
) {
215 fprintf(stderr
, "Failed to create source parameters map, aborting...\n");
220 value_status
= bt_value_map_insert_string(source_params
, "path",
222 if (value_status
!= BT_VALUE_STATUS_OK
) {
227 printf_verbose("Verbose mode active.\n");
228 printf_debug("Debug mode active.\n");
230 if (!opt_plugin_path
) {
231 fprintf(stderr
, "No plugin path specified, aborting...\n");
235 printf_verbose("Looking-up plugins at %s\n",
236 opt_plugin_path
? opt_plugin_path
: "Invalid");
237 component_factory
= bt_component_factory_create();
238 if (!component_factory
) {
239 fprintf(stderr
, "Failed to create component factory.\n");
244 ret
= bt_component_factory_load_recursive(component_factory
, opt_plugin_path
);
246 fprintf(stderr
, "Failed to load plugins.\n");
250 print_found_component_classes(component_factory
);
252 source_class
= bt_component_factory_get_component_class(
253 component_factory
, "ctf", BT_COMPONENT_TYPE_SOURCE
,
256 fprintf(stderr
, "Could not find ctf-fs output component class. Aborting...\n");
261 sink_class
= bt_component_factory_get_component_class(component_factory
,
262 "text", BT_COMPONENT_TYPE_SINK
, "text");
264 fprintf(stderr
, "Could not find text output component class. Aborting...\n");
269 source
= bt_component_create(source_class
, "ctf-fs", source_params
);
271 fprintf(stderr
, "Failed to instantiate source component. Aborting...\n");
276 sink
= bt_component_create(sink_class
, "bt_text_output", sink_params
);
278 fprintf(stderr
, "Failed to instantiate output component. Aborting...\n");
283 /* teardown and exit */
285 BT_PUT(component_factory
);
287 BT_PUT(source_class
);
290 BT_PUT(source_params
);