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
;
53 * We are _not_ using POPT_ARG_STRING's ability to store directly into
54 * variables, because we want to cast the return to non-const, which is
55 * not possible without using poptGetOptArg explicitly. This helps us
56 * controlling memory allocation correctly without making assumptions
57 * about undocumented behaviors. poptGetOptArg is documented as
58 * requiring the returned const char * to be freed by the caller.
60 static struct poptOption long_options
[] = {
61 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
62 { "plugin-path", 0, POPT_ARG_STRING
, NULL
, OPT_PLUGIN_PATH
, 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 { NULL
, 0, 0, NULL
, 0, NULL
, NULL
},
69 * Return 0 if caller should continue, < 0 if caller should return
70 * error, > 0 if caller should exit without reporting error.
72 static int parse_options(int argc
, char **argv
)
78 return 1; /* exit cleanly */
81 pc
= poptGetContext(NULL
, argc
, (const char **) argv
, long_options
, 0);
82 poptReadDefaultConfig(pc
, 0);
85 opt_context_field_names
= 1;
86 opt_payload_field_names
= 1;
88 while ((opt
= poptGetNextOpt(pc
)) != -1) {
91 ret
= 1; /* exit cleanly */
94 opt_plugin_path
= (char *) poptGetOptArg(pc
);
95 if (!opt_plugin_path
) {
101 babeltrace_verbose
= 1;
104 babeltrace_debug
= 1;
120 const char *component_type_str(enum bt_component_type type
)
123 case BT_COMPONENT_TYPE_SOURCE
:
125 case BT_COMPONENT_TYPE_SINK
:
127 case BT_COMPONENT_TYPE_FILTER
:
129 case BT_COMPONENT_TYPE_UNKNOWN
:
136 void print_detected_component_classes(struct bt_component_factory
*factory
)
140 if (!babeltrace_verbose
) {
144 count
= bt_component_factory_get_component_class_count(factory
);
146 fprintf(stderr
, "No component classes found. Please make sure your plug-in search path is set correctly.");
150 printf_verbose("Found %d component classes.\n", count
);
151 for (i
= 0; i
< count
; i
++) {
152 struct bt_component_class
*component_class
=
153 bt_component_factory_get_component_class_index(
155 struct bt_plugin
*plugin
= bt_component_class_get_plugin(
157 const char *plugin_name
= bt_plugin_get_name(plugin
);
158 const char *component_name
= bt_component_class_get_name(
160 const char *path
= bt_plugin_get_path(plugin
);
161 const char *author
= bt_plugin_get_author(plugin
);
162 const char *license
= bt_plugin_get_license(plugin
);
163 const char *plugin_description
= bt_plugin_get_description(
165 const char *component_description
=
166 bt_component_class_get_description(
168 enum bt_component_type type
= bt_component_class_get_type(
171 printf_verbose("[%s - %s (%s)]\n", plugin_name
, component_name
,
172 component_type_str(type
));
173 printf_verbose("\tpath: %s\n", path
);
174 printf_verbose("\tauthor: %s\n", author
);
175 printf_verbose("\tlicense: %s\n", license
);
176 printf_verbose("\tplugin description: %s\n",
177 plugin_description
? plugin_description
: "None");
178 printf_verbose("\tcomponent description: %s\n",
179 component_description
? component_description
: "None");
182 bt_put(component_class
);
187 void test_sink_notifications(struct bt_component
*sink
)
192 int main(int argc
, char **argv
)
195 struct bt_component_factory
*component_factory
= NULL
;
196 struct bt_component_class
*source_class
= NULL
;
197 struct bt_component_class
*sink_class
= NULL
;
198 struct bt_component
*source
= NULL
, *sink
= NULL
;
199 struct bt_value
*source_params
= NULL
, *sink_params
= NULL
;
201 ret
= parse_options(argc
, argv
);
203 fprintf(stderr
, "Error parsing options.\n\n");
205 } else if (ret
> 0) {
209 printf_verbose("Verbose mode active.\n");
210 printf_debug("Debug mode active.\n");
212 if (!opt_plugin_path
) {
213 fprintf(stderr
, "No plugin path specified, aborting...\n");
217 printf_verbose("Looking-up plugins at %s\n",
218 opt_plugin_path
? opt_plugin_path
: "Invalid");
219 component_factory
= bt_component_factory_create();
220 if (!component_factory
) {
221 fprintf(stderr
, "Failed to create component factory.\n");
226 ret
= bt_component_factory_load(component_factory
, opt_plugin_path
);
228 fprintf(stderr
, "Failed to load plugins.\n");
232 print_detected_component_classes(component_factory
);
234 sink_class
= bt_component_factory_get_component_class(component_factory
,
235 NULL
, BT_COMPONENT_TYPE_SINK
, "text");
237 fprintf(stderr
, "Could not find text output component class. Aborting...\n");
242 sink
= bt_component_create(sink_class
, "bt_text_output", sink_params
);
244 fprintf(stderr
, "Failed to instanciate text output. Aborting...\n");
249 test_sink_notifications(sink
);
252 /* teardown and exit */
254 BT_PUT(component_factory
);
256 BT_PUT(source_class
);
259 BT_PUT(source_params
);