Commit | Line | Data |
---|---|---|
34ac0e6c | 1 | /* |
64fa3fec MD |
2 | * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation |
3 | * | |
4 | * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
34ac0e6c MD |
5 | * |
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
7 | * of this software and associated documentation files (the "Software"), to deal | |
8 | * in the Software without restriction, including without limitation the rights | |
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
10 | * copies of the Software, and to permit persons to whom the Software is | |
11 | * furnished to do so, subject to the following conditions: | |
12 | * | |
13 | * The above copyright notice and this permission notice shall be included in | |
14 | * all copies or substantial portions of the Software. | |
c462e188 MD |
15 | * |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
22 | * SOFTWARE. | |
34ac0e6c | 23 | */ |
4c8bfb7e | 24 | |
ea9f8b29 PP |
25 | #define BT_LOG_TAG "CLI" |
26 | #include "logging.h" | |
27 | ||
71c5da58 | 28 | #include <babeltrace2/babeltrace.h> |
57952005 | 29 | #include "common/common.h" |
a8ff38ef | 30 | #include <unistd.h> |
34ac0e6c | 31 | #include <stdlib.h> |
7f26a816 PP |
32 | #include <popt.h> |
33 | #include <string.h> | |
34 | #include <stdio.h> | |
33b34c43 | 35 | #include <glib.h> |
dc3fffef | 36 | #include <inttypes.h> |
7cdc2bab | 37 | #include <unistd.h> |
5401f780 | 38 | #include <signal.h> |
142ac9b0 MJ |
39 | #include "babeltrace2-cfg.h" |
40 | #include "babeltrace2-cfg-cli-args.h" | |
41 | #include "babeltrace2-cfg-cli-args-default.h" | |
9009cc24 PP |
42 | |
43 | #define ENV_BABELTRACE_WARN_COMMAND_NAME_DIRECTORY_CLASH "BABELTRACE_CLI_WARN_COMMAND_NAME_DIRECTORY_CLASH" | |
c6d4d1ae | 44 | #define ENV_BABELTRACE_CLI_LOG_LEVEL "BABELTRACE_CLI_LOG_LEVEL" |
b5fe3e00 | 45 | #define NSEC_PER_SEC 1000000000LL |
34ac0e6c | 46 | |
fc11b6a6 PP |
47 | /* |
48 | * Known environment variable names for the log levels of the project's | |
49 | * modules. | |
50 | */ | |
51 | static const char* log_level_env_var_names[] = { | |
92c579f5 | 52 | "BABELTRACE_FLT_LTTNG_UTILS_DEBUG_INFO_LOG_LEVEL", |
92c579f5 | 53 | "BABELTRACE_FLT_UTILS_TRIMMER_LOG_LEVEL", |
49a5e325 PP |
54 | "BABELTRACE_PLUGIN_CTF_BFCR_LOG_LEVEL", |
55 | "BABELTRACE_PLUGIN_CTF_METADATA_LOG_LEVEL", | |
56 | "BABELTRACE_PLUGIN_CTF_MSG_ITER_LOG_LEVEL", | |
57 | "BABELTRACE_PLUGIN_CTF_UTILS_LOG_LEVEL", | |
a5959ce7 | 58 | "BABELTRACE_PYTHON_BT2_LOG_LEVEL", |
49a5e325 | 59 | "BABELTRACE_SINK_CTF_FS_LOG_LEVEL", |
a0bcd369 | 60 | "BABELTRACE_SINK_TEXT_DETAILS_LOG_LEVEL", |
49a5e325 PP |
61 | "BABELTRACE_SRC_CTF_FS_LOG_LEVEL", |
62 | "BABELTRACE_SRC_CTF_LTTNG_LIVE_LOG_LEVEL", | |
fc11b6a6 PP |
63 | NULL, |
64 | }; | |
65 | ||
5401f780 | 66 | /* Application's processing graph (weak) */ |
8eee8ea2 PP |
67 | static bt_graph *the_graph; |
68 | static bt_query_executor *the_query_executor; | |
5401f780 PP |
69 | static bool canceled = false; |
70 | ||
33b34c43 PP |
71 | GPtrArray *loaded_plugins; |
72 | ||
3265acbc | 73 | #ifdef __MINGW32__ |
8d750b42 | 74 | |
3265acbc MJ |
75 | #include <windows.h> |
76 | ||
77 | static | |
78 | BOOL WINAPI signal_handler(DWORD signal) { | |
79 | if (the_graph) { | |
7b53201c | 80 | bt_graph_cancel(the_graph); |
3265acbc MJ |
81 | } |
82 | ||
83 | canceled = true; | |
84 | ||
85 | return TRUE; | |
86 | } | |
87 | ||
5401f780 | 88 | static |
3265acbc MJ |
89 | void set_signal_handler(void) |
90 | { | |
91 | if (!SetConsoleCtrlHandler(signal_handler, TRUE)) { | |
a684a357 | 92 | BT_LOGE("Failed to set the Ctrl+C handler."); |
3265acbc MJ |
93 | } |
94 | } | |
8d750b42 | 95 | |
3265acbc | 96 | #else /* __MINGW32__ */ |
8d750b42 | 97 | |
3265acbc MJ |
98 | static |
99 | void signal_handler(int signum) | |
5401f780 PP |
100 | { |
101 | if (signum != SIGINT) { | |
102 | return; | |
103 | } | |
104 | ||
105 | if (the_graph) { | |
7b53201c | 106 | bt_graph_cancel(the_graph); |
5401f780 PP |
107 | } |
108 | ||
1286dcbb | 109 | if (the_query_executor) { |
7b53201c | 110 | bt_query_executor_cancel(the_query_executor); |
1286dcbb PP |
111 | } |
112 | ||
5401f780 PP |
113 | canceled = true; |
114 | } | |
115 | ||
3265acbc MJ |
116 | static |
117 | void set_signal_handler(void) | |
118 | { | |
119 | struct sigaction new_action, old_action; | |
120 | ||
121 | new_action.sa_handler = signal_handler; | |
122 | sigemptyset(&new_action.sa_mask); | |
123 | new_action.sa_flags = 0; | |
124 | sigaction(SIGINT, NULL, &old_action); | |
125 | ||
126 | if (old_action.sa_handler != SIG_IGN) { | |
127 | sigaction(SIGINT, &new_action, NULL); | |
128 | } | |
129 | } | |
8d750b42 | 130 | |
3265acbc MJ |
131 | #endif /* __MINGW32__ */ |
132 | ||
33b34c43 | 133 | static |
9009cc24 | 134 | void init_static_data(void) |
33b34c43 | 135 | { |
4b70020d PP |
136 | loaded_plugins = g_ptr_array_new_with_free_func( |
137 | (GDestroyNotify) bt_object_put_ref); | |
33b34c43 PP |
138 | } |
139 | ||
140 | static | |
9009cc24 | 141 | void fini_static_data(void) |
33b34c43 PP |
142 | { |
143 | g_ptr_array_free(loaded_plugins, TRUE); | |
144 | } | |
145 | ||
1286dcbb PP |
146 | static |
147 | int create_the_query_executor(void) | |
148 | { | |
149 | int ret = 0; | |
150 | ||
7b53201c | 151 | the_query_executor = bt_query_executor_create(); |
1286dcbb PP |
152 | if (!the_query_executor) { |
153 | BT_LOGE_STR("Cannot create a query executor."); | |
154 | ret = -1; | |
155 | } | |
156 | ||
157 | return ret; | |
158 | } | |
159 | ||
160 | static | |
161 | void destroy_the_query_executor(void) | |
162 | { | |
8c6884d9 | 163 | BT_QUERY_EXECUTOR_PUT_REF_AND_RESET(the_query_executor); |
1286dcbb PP |
164 | } |
165 | ||
166 | static | |
83da519a PP |
167 | int query(struct bt_config *cfg, const bt_component_class *comp_cls, |
168 | const char *obj, const bt_value *params, | |
169 | const bt_value **user_result, const char **fail_reason) | |
1286dcbb | 170 | { |
8eee8ea2 | 171 | const bt_value *result = NULL; |
ee78f405 | 172 | bt_query_executor_status status; |
1286dcbb PP |
173 | *fail_reason = "unknown error"; |
174 | int ret = 0; | |
175 | ||
8b45963b PP |
176 | BT_ASSERT(fail_reason); |
177 | BT_ASSERT(user_result); | |
1286dcbb PP |
178 | ret = create_the_query_executor(); |
179 | if (ret) { | |
180 | /* create_the_query_executor() logs errors */ | |
181 | goto end; | |
182 | } | |
183 | ||
184 | if (canceled) { | |
185 | BT_LOGI("Canceled by user before executing the query: " | |
186 | "comp-cls-addr=%p, comp-cls-name=\"%s\", " | |
187 | "query-obj=\"%s\"", comp_cls, | |
188 | bt_component_class_get_name(comp_cls), obj); | |
189 | *fail_reason = "canceled by user"; | |
190 | goto error; | |
191 | } | |
192 | ||
193 | while (true) { | |
7b53201c | 194 | status = bt_query_executor_query(the_query_executor, |
83da519a | 195 | comp_cls, obj, params, cfg->log_level, &result); |
1286dcbb | 196 | switch (status) { |
79400927 | 197 | case BT_QUERY_EXECUTOR_STATUS_OK: |
1286dcbb | 198 | goto ok; |
79400927 | 199 | case BT_QUERY_EXECUTOR_STATUS_AGAIN: |
1286dcbb PP |
200 | { |
201 | const uint64_t sleep_time_us = 100000; | |
202 | ||
203 | /* Wait 100 ms and retry */ | |
a684a357 | 204 | BT_LOGD("Got BT_QUERY_EXECUTOR_STATUS_AGAIN: sleeping: " |
1286dcbb PP |
205 | "time-us=%" PRIu64, sleep_time_us); |
206 | ||
207 | if (usleep(sleep_time_us)) { | |
7b53201c | 208 | if (bt_query_executor_is_canceled(the_query_executor)) { |
1286dcbb PP |
209 | BT_LOGI("Query was canceled by user: " |
210 | "comp-cls-addr=%p, comp-cls-name=\"%s\", " | |
211 | "query-obj=\"%s\"", comp_cls, | |
212 | bt_component_class_get_name(comp_cls), | |
213 | obj); | |
214 | *fail_reason = "canceled by user"; | |
215 | goto error; | |
216 | } | |
217 | } | |
218 | ||
219 | continue; | |
220 | } | |
79400927 | 221 | case BT_QUERY_EXECUTOR_STATUS_CANCELED: |
1286dcbb PP |
222 | *fail_reason = "canceled by user"; |
223 | goto error; | |
79400927 | 224 | case BT_QUERY_EXECUTOR_STATUS_ERROR: |
1286dcbb | 225 | goto error; |
79400927 | 226 | case BT_QUERY_EXECUTOR_STATUS_INVALID_OBJECT: |
1286dcbb PP |
227 | *fail_reason = "invalid or unknown query object"; |
228 | goto error; | |
79400927 | 229 | case BT_QUERY_EXECUTOR_STATUS_INVALID_PARAMS: |
1286dcbb PP |
230 | *fail_reason = "invalid query parameters"; |
231 | goto error; | |
79400927 PP |
232 | case BT_QUERY_EXECUTOR_STATUS_UNSUPPORTED: |
233 | *fail_reason = "unsupported action"; | |
234 | goto error; | |
235 | case BT_QUERY_EXECUTOR_STATUS_NOMEM: | |
1286dcbb PP |
236 | *fail_reason = "not enough memory"; |
237 | goto error; | |
238 | default: | |
239 | BT_LOGF("Unknown query status: status=%d", status); | |
240 | abort(); | |
241 | } | |
242 | } | |
243 | ||
244 | ok: | |
245 | *user_result = result; | |
246 | result = NULL; | |
247 | goto end; | |
248 | ||
249 | error: | |
250 | ret = -1; | |
251 | ||
252 | end: | |
253 | destroy_the_query_executor(); | |
8c6884d9 | 254 | bt_value_put_ref(result); |
1286dcbb PP |
255 | return ret; |
256 | } | |
257 | ||
33b34c43 | 258 | static |
8eee8ea2 | 259 | const bt_plugin *find_plugin(const char *name) |
33b34c43 PP |
260 | { |
261 | int i; | |
8eee8ea2 | 262 | const bt_plugin *plugin = NULL; |
33b34c43 | 263 | |
8b45963b | 264 | BT_ASSERT(name); |
a684a357 | 265 | BT_LOGI("Finding plugin: name=\"%s\"", name); |
7213a328 | 266 | |
33b34c43 PP |
267 | for (i = 0; i < loaded_plugins->len; i++) { |
268 | plugin = g_ptr_array_index(loaded_plugins, i); | |
269 | ||
270 | if (strcmp(name, bt_plugin_get_name(plugin)) == 0) { | |
271 | break; | |
272 | } | |
273 | ||
274 | plugin = NULL; | |
275 | } | |
276 | ||
a684a357 PP |
277 | if (plugin) { |
278 | BT_LOGI("Found plugin: name=\"%s\", plugin-addr=%p", | |
279 | name, plugin); | |
280 | } else { | |
281 | BT_LOGI("Cannot find plugin: name=\"%s\"", name); | |
7213a328 PP |
282 | } |
283 | ||
8c6884d9 | 284 | bt_plugin_get_ref(plugin); |
4b70020d | 285 | return plugin; |
33b34c43 PP |
286 | } |
287 | ||
7b53201c | 288 | typedef const void *(*plugin_borrow_comp_cls_func_t)( |
8eee8ea2 | 289 | const bt_plugin *, const char *); |
834e9996 | 290 | |
33b34c43 | 291 | static |
7b53201c | 292 | const void *find_component_class_from_plugin(const char *plugin_name, |
33b34c43 | 293 | const char *comp_class_name, |
834e9996 | 294 | plugin_borrow_comp_cls_func_t plugin_borrow_comp_cls_func) |
33b34c43 | 295 | { |
7b53201c | 296 | const void *comp_class = NULL; |
8eee8ea2 | 297 | const bt_plugin *plugin; |
7213a328 | 298 | |
a684a357 | 299 | BT_LOGI("Finding component class: plugin-name=\"%s\", " |
834e9996 | 300 | "comp-cls-name=\"%s\"", plugin_name, comp_class_name); |
7213a328 PP |
301 | |
302 | plugin = find_plugin(plugin_name); | |
33b34c43 PP |
303 | if (!plugin) { |
304 | goto end; | |
305 | } | |
306 | ||
4b70020d PP |
307 | comp_class = plugin_borrow_comp_cls_func(plugin, comp_class_name); |
308 | bt_object_get_ref(comp_class); | |
8c6884d9 | 309 | BT_PLUGIN_PUT_REF_AND_RESET(plugin); |
7213a328 | 310 | |
33b34c43 | 311 | end: |
a684a357 PP |
312 | if (comp_class) { |
313 | BT_LOGI("Found component class: plugin-name=\"%s\", " | |
314 | "comp-cls-name=\"%s\"", plugin_name, comp_class_name); | |
315 | } else { | |
316 | BT_LOGI("Cannot find source component class: " | |
317 | "plugin-name=\"%s\", comp-cls-name=\"%s\"", | |
318 | plugin_name, comp_class_name); | |
7213a328 PP |
319 | } |
320 | ||
33b34c43 PP |
321 | return comp_class; |
322 | } | |
6c2f3ee5 | 323 | |
834e9996 | 324 | static |
8eee8ea2 | 325 | const bt_component_class_source *find_source_component_class( |
834e9996 PP |
326 | const char *plugin_name, const char *comp_class_name) |
327 | { | |
7b53201c PP |
328 | return (const void *) find_component_class_from_plugin( |
329 | plugin_name, comp_class_name, | |
834e9996 | 330 | (plugin_borrow_comp_cls_func_t) |
3a2cb327 | 331 | bt_plugin_borrow_source_component_class_by_name_const); |
834e9996 PP |
332 | } |
333 | ||
334 | static | |
8eee8ea2 | 335 | const bt_component_class_filter *find_filter_component_class( |
834e9996 PP |
336 | const char *plugin_name, const char *comp_class_name) |
337 | { | |
7b53201c PP |
338 | return (const void *) find_component_class_from_plugin( |
339 | plugin_name, comp_class_name, | |
834e9996 | 340 | (plugin_borrow_comp_cls_func_t) |
3a2cb327 | 341 | bt_plugin_borrow_filter_component_class_by_name_const); |
834e9996 PP |
342 | } |
343 | ||
344 | static | |
8eee8ea2 | 345 | const bt_component_class_sink *find_sink_component_class( |
834e9996 PP |
346 | const char *plugin_name, const char *comp_class_name) |
347 | { | |
7b53201c | 348 | return (const void *) find_component_class_from_plugin(plugin_name, |
834e9996 PP |
349 | comp_class_name, |
350 | (plugin_borrow_comp_cls_func_t) | |
3a2cb327 | 351 | bt_plugin_borrow_sink_component_class_by_name_const); |
834e9996 PP |
352 | } |
353 | ||
354 | static | |
8eee8ea2 | 355 | const bt_component_class *find_component_class(const char *plugin_name, |
834e9996 | 356 | const char *comp_class_name, |
ee78f405 | 357 | bt_component_class_type comp_class_type) |
834e9996 | 358 | { |
8eee8ea2 | 359 | const bt_component_class *comp_cls = NULL; |
834e9996 PP |
360 | |
361 | switch (comp_class_type) { | |
362 | case BT_COMPONENT_CLASS_TYPE_SOURCE: | |
7b53201c | 363 | comp_cls = bt_component_class_source_as_component_class_const(find_source_component_class(plugin_name, comp_class_name)); |
834e9996 PP |
364 | break; |
365 | case BT_COMPONENT_CLASS_TYPE_FILTER: | |
7b53201c | 366 | comp_cls = bt_component_class_filter_as_component_class_const(find_filter_component_class(plugin_name, comp_class_name)); |
834e9996 PP |
367 | break; |
368 | case BT_COMPONENT_CLASS_TYPE_SINK: | |
7b53201c | 369 | comp_cls = bt_component_class_sink_as_component_class_const(find_sink_component_class(plugin_name, comp_class_name)); |
834e9996 PP |
370 | break; |
371 | default: | |
372 | abort(); | |
373 | } | |
374 | ||
375 | return comp_cls; | |
376 | } | |
377 | ||
c42c79ea | 378 | static |
7213a328 | 379 | void print_indent(FILE *fp, size_t indent) |
c42c79ea PP |
380 | { |
381 | size_t i; | |
382 | ||
383 | for (i = 0; i < indent; i++) { | |
7213a328 | 384 | fprintf(fp, " "); |
c42c79ea PP |
385 | } |
386 | } | |
387 | ||
87796884 | 388 | static |
ee78f405 | 389 | const char *component_type_str(bt_component_class_type type) |
87796884 PP |
390 | { |
391 | switch (type) { | |
392 | case BT_COMPONENT_CLASS_TYPE_SOURCE: | |
393 | return "source"; | |
394 | case BT_COMPONENT_CLASS_TYPE_SINK: | |
395 | return "sink"; | |
396 | case BT_COMPONENT_CLASS_TYPE_FILTER: | |
397 | return "filter"; | |
87796884 | 398 | default: |
fd5f8053 | 399 | return "(unknown)"; |
87796884 PP |
400 | } |
401 | } | |
402 | ||
9009cc24 PP |
403 | static |
404 | void print_plugin_comp_cls_opt(FILE *fh, const char *plugin_name, | |
ee78f405 | 405 | const char *comp_cls_name, bt_component_class_type type) |
87796884 | 406 | { |
9009cc24 PP |
407 | GString *shell_plugin_name = NULL; |
408 | GString *shell_comp_cls_name = NULL; | |
87796884 | 409 | |
9009cc24 | 410 | shell_plugin_name = bt_common_shell_quote(plugin_name, false); |
87796884 PP |
411 | if (!shell_plugin_name) { |
412 | goto end; | |
413 | } | |
414 | ||
9009cc24 | 415 | shell_comp_cls_name = bt_common_shell_quote(comp_cls_name, false); |
87796884 PP |
416 | if (!shell_comp_cls_name) { |
417 | goto end; | |
418 | } | |
419 | ||
fd5f8053 | 420 | fprintf(fh, "'%s%s%s%s.%s%s%s.%s%s%s'", |
87796884 PP |
421 | bt_common_color_bold(), |
422 | bt_common_color_fg_cyan(), | |
423 | component_type_str(type), | |
87796884 | 424 | bt_common_color_fg_default(), |
87796884 | 425 | bt_common_color_fg_blue(), |
9009cc24 | 426 | shell_plugin_name->str, |
87796884 PP |
427 | bt_common_color_fg_default(), |
428 | bt_common_color_fg_yellow(), | |
9009cc24 | 429 | shell_comp_cls_name->str, |
87796884 PP |
430 | bt_common_color_reset()); |
431 | ||
432 | end: | |
9009cc24 PP |
433 | if (shell_plugin_name) { |
434 | g_string_free(shell_plugin_name, TRUE); | |
435 | } | |
436 | ||
437 | if (shell_comp_cls_name) { | |
438 | g_string_free(shell_comp_cls_name, TRUE); | |
439 | } | |
87796884 PP |
440 | } |
441 | ||
c42c79ea | 442 | static |
8eee8ea2 | 443 | void print_value(FILE *, const bt_value *, size_t); |
c42c79ea | 444 | |
c1081aa6 | 445 | static |
8eee8ea2 | 446 | void print_value_rec(FILE *, const bt_value *, size_t); |
7213a328 PP |
447 | |
448 | struct print_map_value_data { | |
449 | size_t indent; | |
450 | FILE *fp; | |
451 | }; | |
c1081aa6 | 452 | |
c42c79ea | 453 | static |
8eee8ea2 | 454 | bt_bool print_map_value(const char *key, const bt_value *object, |
ce141536 | 455 | void *data) |
c42c79ea | 456 | { |
7213a328 | 457 | struct print_map_value_data *print_map_value_data = data; |
290725f7 | 458 | |
7213a328 PP |
459 | print_indent(print_map_value_data->fp, print_map_value_data->indent); |
460 | fprintf(print_map_value_data->fp, "%s: ", key); | |
8b45963b | 461 | BT_ASSERT(object); |
290725f7 PP |
462 | |
463 | if (bt_value_is_array(object) && | |
464 | bt_value_array_is_empty(object)) { | |
7213a328 | 465 | fprintf(print_map_value_data->fp, "[ ]\n"); |
290725f7 PP |
466 | return true; |
467 | } | |
468 | ||
469 | if (bt_value_is_map(object) && | |
470 | bt_value_map_is_empty(object)) { | |
7213a328 | 471 | fprintf(print_map_value_data->fp, "{ }\n"); |
290725f7 PP |
472 | return true; |
473 | } | |
c42c79ea | 474 | |
290725f7 PP |
475 | if (bt_value_is_array(object) || |
476 | bt_value_is_map(object)) { | |
7213a328 | 477 | fprintf(print_map_value_data->fp, "\n"); |
290725f7 | 478 | } |
c42c79ea | 479 | |
7213a328 PP |
480 | print_value_rec(print_map_value_data->fp, object, |
481 | print_map_value_data->indent + 2); | |
c55a9f58 | 482 | return BT_TRUE; |
c42c79ea PP |
483 | } |
484 | ||
485 | static | |
8eee8ea2 | 486 | void print_value_rec(FILE *fp, const bt_value *value, size_t indent) |
c42c79ea | 487 | { |
c55a9f58 | 488 | bt_bool bool_val; |
c42c79ea | 489 | int64_t int_val; |
68d9d039 | 490 | uint64_t uint_val; |
c42c79ea PP |
491 | double dbl_val; |
492 | const char *str_val; | |
493 | int size; | |
494 | int i; | |
495 | ||
496 | if (!value) { | |
497 | return; | |
498 | } | |
499 | ||
c42c79ea PP |
500 | switch (bt_value_get_type(value)) { |
501 | case BT_VALUE_TYPE_NULL: | |
7213a328 | 502 | fprintf(fp, "%snull%s\n", bt_common_color_bold(), |
c1081aa6 | 503 | bt_common_color_reset()); |
c42c79ea PP |
504 | break; |
505 | case BT_VALUE_TYPE_BOOL: | |
b5cdc106 | 506 | bool_val = bt_value_bool_get(value); |
7213a328 | 507 | fprintf(fp, "%s%s%s%s\n", bt_common_color_bold(), |
c1081aa6 PP |
508 | bt_common_color_fg_cyan(), bool_val ? "yes" : "no", |
509 | bt_common_color_reset()); | |
c42c79ea | 510 | break; |
68d9d039 PP |
511 | case BT_VALUE_TYPE_UNSIGNED_INTEGER: |
512 | uint_val = bt_value_unsigned_integer_get(value); | |
513 | fprintf(fp, "%s%s%" PRIu64 "%s\n", bt_common_color_bold(), | |
514 | bt_common_color_fg_red(), uint_val, | |
515 | bt_common_color_reset()); | |
516 | break; | |
517 | case BT_VALUE_TYPE_SIGNED_INTEGER: | |
518 | int_val = bt_value_signed_integer_get(value); | |
7213a328 | 519 | fprintf(fp, "%s%s%" PRId64 "%s\n", bt_common_color_bold(), |
c1081aa6 PP |
520 | bt_common_color_fg_red(), int_val, |
521 | bt_common_color_reset()); | |
c42c79ea | 522 | break; |
944421ed | 523 | case BT_VALUE_TYPE_REAL: |
b5cdc106 | 524 | dbl_val = bt_value_real_get(value); |
7213a328 | 525 | fprintf(fp, "%s%s%lf%s\n", bt_common_color_bold(), |
c1081aa6 PP |
526 | bt_common_color_fg_red(), dbl_val, |
527 | bt_common_color_reset()); | |
c42c79ea PP |
528 | break; |
529 | case BT_VALUE_TYPE_STRING: | |
b5cdc106 | 530 | str_val = bt_value_string_get(value); |
7213a328 | 531 | fprintf(fp, "%s%s%s%s\n", bt_common_color_bold(), |
c1081aa6 PP |
532 | bt_common_color_fg_green(), str_val, |
533 | bt_common_color_reset()); | |
c42c79ea PP |
534 | break; |
535 | case BT_VALUE_TYPE_ARRAY: | |
44514773 | 536 | size = bt_value_array_get_size(value); |
1ea987e2 MD |
537 | if (size < 0) { |
538 | goto error; | |
539 | } | |
290725f7 PP |
540 | |
541 | if (size == 0) { | |
7213a328 PP |
542 | print_indent(fp, indent); |
543 | fprintf(fp, "[ ]\n"); | |
290725f7 PP |
544 | break; |
545 | } | |
c42c79ea PP |
546 | |
547 | for (i = 0; i < size; i++) { | |
8eee8ea2 | 548 | const bt_value *element = |
ce141536 | 549 | bt_value_array_borrow_element_by_index_const( |
44514773 | 550 | value, i); |
c42c79ea | 551 | |
1ea987e2 MD |
552 | if (!element) { |
553 | goto error; | |
554 | } | |
7213a328 PP |
555 | print_indent(fp, indent); |
556 | fprintf(fp, "- "); | |
290725f7 PP |
557 | |
558 | if (bt_value_is_array(element) && | |
559 | bt_value_array_is_empty(element)) { | |
7213a328 | 560 | fprintf(fp, "[ ]\n"); |
290725f7 PP |
561 | continue; |
562 | } | |
563 | ||
564 | if (bt_value_is_map(element) && | |
565 | bt_value_map_is_empty(element)) { | |
7213a328 | 566 | fprintf(fp, "{ }\n"); |
290725f7 PP |
567 | continue; |
568 | } | |
569 | ||
570 | if (bt_value_is_array(element) || | |
571 | bt_value_is_map(element)) { | |
7213a328 | 572 | fprintf(fp, "\n"); |
290725f7 PP |
573 | } |
574 | ||
7213a328 | 575 | print_value_rec(fp, element, indent + 2); |
c42c79ea | 576 | } |
c42c79ea PP |
577 | break; |
578 | case BT_VALUE_TYPE_MAP: | |
7213a328 PP |
579 | { |
580 | struct print_map_value_data data = { | |
581 | .indent = indent, | |
582 | .fp = fp, | |
583 | }; | |
584 | ||
c42c79ea | 585 | if (bt_value_map_is_empty(value)) { |
7213a328 PP |
586 | print_indent(fp, indent); |
587 | fprintf(fp, "{ }\n"); | |
290725f7 | 588 | break; |
c42c79ea PP |
589 | } |
590 | ||
ce141536 | 591 | bt_value_map_foreach_entry_const(value, print_map_value, &data); |
c42c79ea | 592 | break; |
7213a328 | 593 | } |
c42c79ea | 594 | default: |
0fbb9a9f | 595 | abort(); |
c42c79ea | 596 | } |
1ea987e2 MD |
597 | return; |
598 | ||
599 | error: | |
600 | BT_LOGE("Error printing value of type %s.", | |
17582c6d | 601 | bt_common_value_type_string(bt_value_get_type(value))); |
c42c79ea PP |
602 | } |
603 | ||
c1081aa6 | 604 | static |
8eee8ea2 | 605 | void print_value(FILE *fp, const bt_value *value, size_t indent) |
c1081aa6 PP |
606 | { |
607 | if (!bt_value_is_array(value) && !bt_value_is_map(value)) { | |
7213a328 | 608 | print_indent(fp, indent); |
c1081aa6 PP |
609 | } |
610 | ||
7213a328 | 611 | print_value_rec(fp, value, indent); |
c1081aa6 PP |
612 | } |
613 | ||
c42c79ea PP |
614 | static |
615 | void print_bt_config_component(struct bt_config_component *bt_config_component) | |
616 | { | |
7213a328 PP |
617 | fprintf(stderr, " "); |
618 | print_plugin_comp_cls_opt(stderr, bt_config_component->plugin_name->str, | |
db0f160a | 619 | bt_config_component->comp_cls_name->str, |
87796884 | 620 | bt_config_component->type); |
7213a328 | 621 | fprintf(stderr, ":\n"); |
3b6cfcc5 PP |
622 | |
623 | if (bt_config_component->instance_name->len > 0) { | |
7213a328 | 624 | fprintf(stderr, " Name: %s\n", |
3b6cfcc5 PP |
625 | bt_config_component->instance_name->str); |
626 | } | |
627 | ||
7213a328 | 628 | fprintf(stderr, " Parameters:\n"); |
ce141536 | 629 | print_value(stderr, bt_config_component->params, 8); |
c42c79ea PP |
630 | } |
631 | ||
632 | static | |
633 | void print_bt_config_components(GPtrArray *array) | |
634 | { | |
635 | size_t i; | |
636 | ||
637 | for (i = 0; i < array->len; i++) { | |
638 | struct bt_config_component *cfg_component = | |
e5bc7f81 | 639 | bt_config_get_component(array, i); |
c42c79ea | 640 | print_bt_config_component(cfg_component); |
8138bfe1 | 641 | BT_OBJECT_PUT_REF_AND_RESET(cfg_component); |
c42c79ea PP |
642 | } |
643 | } | |
644 | ||
290725f7 | 645 | static |
8eee8ea2 | 646 | void print_plugin_paths(const bt_value *plugin_paths) |
290725f7 | 647 | { |
7213a328 PP |
648 | fprintf(stderr, " Plugin paths:\n"); |
649 | print_value(stderr, plugin_paths, 4); | |
290725f7 PP |
650 | } |
651 | ||
652 | static | |
db0f160a | 653 | void print_cfg_run(struct bt_config *cfg) |
290725f7 | 654 | { |
ebba3338 PP |
655 | size_t i; |
656 | ||
ce141536 | 657 | print_plugin_paths(cfg->plugin_paths); |
7213a328 | 658 | fprintf(stderr, " Source component instances:\n"); |
db0f160a | 659 | print_bt_config_components(cfg->cmd_data.run.sources); |
ebba3338 | 660 | |
db0f160a | 661 | if (cfg->cmd_data.run.filters->len > 0) { |
7213a328 | 662 | fprintf(stderr, " Filter component instances:\n"); |
db0f160a | 663 | print_bt_config_components(cfg->cmd_data.run.filters); |
ebba3338 PP |
664 | } |
665 | ||
7213a328 | 666 | fprintf(stderr, " Sink component instances:\n"); |
db0f160a | 667 | print_bt_config_components(cfg->cmd_data.run.sinks); |
7213a328 | 668 | fprintf(stderr, " Connections:\n"); |
ebba3338 | 669 | |
db0f160a | 670 | for (i = 0; i < cfg->cmd_data.run.connections->len; i++) { |
ebba3338 | 671 | struct bt_config_connection *cfg_connection = |
db0f160a | 672 | g_ptr_array_index(cfg->cmd_data.run.connections, |
ebba3338 PP |
673 | i); |
674 | ||
7213a328 | 675 | fprintf(stderr, " %s%s%s -> %s%s%s\n", |
9009cc24 PP |
676 | cfg_connection->upstream_comp_name->str, |
677 | cfg_connection->upstream_port_glob->len > 0 ? "." : "", | |
678 | cfg_connection->upstream_port_glob->str, | |
679 | cfg_connection->downstream_comp_name->str, | |
680 | cfg_connection->downstream_port_glob->len > 0 ? "." : "", | |
681 | cfg_connection->downstream_port_glob->str); | |
ebba3338 | 682 | } |
290725f7 PP |
683 | } |
684 | ||
685 | static | |
686 | void print_cfg_list_plugins(struct bt_config *cfg) | |
687 | { | |
ce141536 | 688 | print_plugin_paths(cfg->plugin_paths); |
290725f7 PP |
689 | } |
690 | ||
c1081aa6 PP |
691 | static |
692 | void print_cfg_help(struct bt_config *cfg) | |
693 | { | |
ce141536 | 694 | print_plugin_paths(cfg->plugin_paths); |
db0f160a PP |
695 | } |
696 | ||
697 | static | |
698 | void print_cfg_print_ctf_metadata(struct bt_config *cfg) | |
699 | { | |
ce141536 | 700 | print_plugin_paths(cfg->plugin_paths); |
7213a328 PP |
701 | fprintf(stderr, " Path: %s\n", |
702 | cfg->cmd_data.print_ctf_metadata.path->str); | |
db0f160a PP |
703 | } |
704 | ||
705 | static | |
706 | void print_cfg_print_lttng_live_sessions(struct bt_config *cfg) | |
707 | { | |
ce141536 | 708 | print_plugin_paths(cfg->plugin_paths); |
7213a328 PP |
709 | fprintf(stderr, " URL: %s\n", |
710 | cfg->cmd_data.print_lttng_live_sessions.url->str); | |
c1081aa6 PP |
711 | } |
712 | ||
713 | static | |
a67681c1 | 714 | void print_cfg_query(struct bt_config *cfg) |
c1081aa6 | 715 | { |
ce141536 | 716 | print_plugin_paths(cfg->plugin_paths); |
7213a328 PP |
717 | fprintf(stderr, " Object: `%s`\n", cfg->cmd_data.query.object->str); |
718 | fprintf(stderr, " Component class:\n"); | |
a67681c1 | 719 | print_bt_config_component(cfg->cmd_data.query.cfg_component); |
c1081aa6 PP |
720 | } |
721 | ||
c42c79ea PP |
722 | static |
723 | void print_cfg(struct bt_config *cfg) | |
724 | { | |
7213a328 | 725 | if (!BT_LOG_ON_INFO) { |
00447e45 PP |
726 | return; |
727 | } | |
728 | ||
a684a357 PP |
729 | BT_LOGI_STR("CLI configuration:"); |
730 | BT_LOGI(" Debug mode: %s\n", cfg->debug ? "yes" : "no"); | |
731 | BT_LOGI(" Verbose mode: %s\n", cfg->verbose ? "yes" : "no"); | |
290725f7 PP |
732 | |
733 | switch (cfg->command) { | |
db0f160a PP |
734 | case BT_CONFIG_COMMAND_RUN: |
735 | print_cfg_run(cfg); | |
290725f7 PP |
736 | break; |
737 | case BT_CONFIG_COMMAND_LIST_PLUGINS: | |
738 | print_cfg_list_plugins(cfg); | |
c1081aa6 PP |
739 | break; |
740 | case BT_CONFIG_COMMAND_HELP: | |
741 | print_cfg_help(cfg); | |
742 | break; | |
a67681c1 PP |
743 | case BT_CONFIG_COMMAND_QUERY: |
744 | print_cfg_query(cfg); | |
290725f7 | 745 | break; |
db0f160a PP |
746 | case BT_CONFIG_COMMAND_PRINT_CTF_METADATA: |
747 | print_cfg_print_ctf_metadata(cfg); | |
748 | break; | |
749 | case BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS: | |
750 | print_cfg_print_lttng_live_sessions(cfg); | |
751 | break; | |
290725f7 | 752 | default: |
0fbb9a9f | 753 | abort(); |
290725f7 | 754 | } |
c42c79ea PP |
755 | } |
756 | ||
33b34c43 | 757 | static |
8eee8ea2 | 758 | void add_to_loaded_plugins(const bt_plugin_set *plugin_set) |
98ecef32 | 759 | { |
544d0515 PP |
760 | int64_t i; |
761 | int64_t count; | |
a8ff38ef PP |
762 | |
763 | count = bt_plugin_set_get_plugin_count(plugin_set); | |
8b45963b | 764 | BT_ASSERT(count >= 0); |
a8ff38ef PP |
765 | |
766 | for (i = 0; i < count; i++) { | |
8eee8ea2 | 767 | const bt_plugin *plugin = |
3a2cb327 | 768 | bt_plugin_set_borrow_plugin_by_index_const(plugin_set, i); |
8eee8ea2 | 769 | const bt_plugin *loaded_plugin = |
834e9996 | 770 | find_plugin(bt_plugin_get_name(plugin)); |
33b34c43 | 771 | |
8b45963b | 772 | BT_ASSERT(plugin); |
a8ff38ef | 773 | |
33b34c43 | 774 | if (loaded_plugin) { |
7213a328 PP |
775 | BT_LOGI("Not using plugin: another one already exists with the same name: " |
776 | "plugin-name=\"%s\", plugin-path=\"%s\", " | |
777 | "existing-plugin-path=\"%s\"", | |
778 | bt_plugin_get_name(plugin), | |
779 | bt_plugin_get_path(plugin), | |
780 | bt_plugin_get_path(loaded_plugin)); | |
8c6884d9 | 781 | bt_plugin_put_ref(loaded_plugin); |
33b34c43 | 782 | } else { |
a8ff38ef | 783 | /* Add to global array. */ |
7213a328 PP |
784 | BT_LOGD("Adding plugin to loaded plugins: plugin-path=\"%s\"", |
785 | bt_plugin_get_name(plugin)); | |
8c6884d9 | 786 | bt_plugin_get_ref(plugin); |
3a2cb327 | 787 | g_ptr_array_add(loaded_plugins, (void *) plugin); |
33b34c43 | 788 | } |
33b34c43 PP |
789 | } |
790 | } | |
791 | ||
792 | static | |
8eee8ea2 | 793 | int load_dynamic_plugins(const bt_value *plugin_paths) |
33b34c43 PP |
794 | { |
795 | int nr_paths, i, ret = 0; | |
98ecef32 | 796 | |
44514773 | 797 | nr_paths = bt_value_array_get_size(plugin_paths); |
98ecef32 | 798 | if (nr_paths < 0) { |
7213a328 | 799 | BT_LOGE_STR("Cannot load dynamic plugins: no plugin path."); |
33b34c43 PP |
800 | ret = -1; |
801 | goto end; | |
98ecef32 | 802 | } |
33b34c43 | 803 | |
a684a357 | 804 | BT_LOGI_STR("Loading dynamic plugins."); |
7213a328 | 805 | |
98ecef32 | 806 | for (i = 0; i < nr_paths; i++) { |
8eee8ea2 | 807 | const bt_value *plugin_path_value = NULL; |
98ecef32 | 808 | const char *plugin_path; |
8eee8ea2 | 809 | const bt_plugin_set *plugin_set; |
98ecef32 | 810 | |
ce141536 PP |
811 | plugin_path_value = |
812 | bt_value_array_borrow_element_by_index_const( | |
813 | plugin_paths, i); | |
b5cdc106 | 814 | plugin_path = bt_value_string_get(plugin_path_value); |
50ad9320 PP |
815 | |
816 | /* | |
817 | * Skip this if the directory does not exist because | |
781ae911 | 818 | * bt_plugin_find_all_from_dir() expects an existing |
50ad9320 PP |
819 | * directory. |
820 | */ | |
821 | if (!g_file_test(plugin_path, G_FILE_TEST_IS_DIR)) { | |
a684a357 | 822 | BT_LOGI("Skipping nonexistent directory path: " |
50ad9320 | 823 | "path=\"%s\"", plugin_path); |
50ad9320 PP |
824 | continue; |
825 | } | |
826 | ||
781ae911 | 827 | plugin_set = bt_plugin_find_all_from_dir(plugin_path, false); |
a8ff38ef | 828 | if (!plugin_set) { |
a684a357 PP |
829 | BT_LOGI("Unable to load dynamic plugins from directory: " |
830 | "path=\"%s\"", plugin_path); | |
33b34c43 | 831 | continue; |
98ecef32 | 832 | } |
33b34c43 | 833 | |
a8ff38ef | 834 | add_to_loaded_plugins(plugin_set); |
8c6884d9 | 835 | bt_plugin_set_put_ref(plugin_set); |
98ecef32 | 836 | } |
33b34c43 PP |
837 | end: |
838 | return ret; | |
839 | } | |
840 | ||
841 | static | |
842 | int load_static_plugins(void) | |
843 | { | |
844 | int ret = 0; | |
8eee8ea2 | 845 | const bt_plugin_set *plugin_set; |
33b34c43 | 846 | |
7213a328 | 847 | BT_LOGI("Loading static plugins."); |
781ae911 | 848 | plugin_set = bt_plugin_find_all_from_static(); |
a8ff38ef | 849 | if (!plugin_set) { |
7213a328 | 850 | BT_LOGE("Unable to load static plugins."); |
33b34c43 PP |
851 | ret = -1; |
852 | goto end; | |
853 | } | |
854 | ||
a8ff38ef | 855 | add_to_loaded_plugins(plugin_set); |
8c6884d9 | 856 | bt_plugin_set_put_ref(plugin_set); |
33b34c43 PP |
857 | end: |
858 | return ret; | |
98ecef32 MD |
859 | } |
860 | ||
9009cc24 | 861 | static |
8eee8ea2 | 862 | int load_all_plugins(const bt_value *plugin_paths) |
290725f7 PP |
863 | { |
864 | int ret = 0; | |
33b34c43 | 865 | |
290725f7 | 866 | if (load_dynamic_plugins(plugin_paths)) { |
290725f7 | 867 | ret = -1; |
c1870f57 JG |
868 | goto end; |
869 | } | |
870 | ||
290725f7 | 871 | if (load_static_plugins()) { |
290725f7 | 872 | ret = -1; |
c1870f57 JG |
873 | goto end; |
874 | } | |
875 | ||
7213a328 PP |
876 | BT_LOGI("Loaded all plugins: count=%u", loaded_plugins->len); |
877 | ||
290725f7 PP |
878 | end: |
879 | return ret; | |
880 | } | |
881 | ||
9009cc24 | 882 | static |
8eee8ea2 | 883 | void print_plugin_info(const bt_plugin *plugin) |
22e22462 PP |
884 | { |
885 | unsigned int major, minor, patch; | |
886 | const char *extra; | |
ee78f405 | 887 | bt_property_availability version_avail; |
22e22462 PP |
888 | const char *plugin_name; |
889 | const char *path; | |
890 | const char *author; | |
891 | const char *license; | |
892 | const char *plugin_description; | |
893 | ||
894 | plugin_name = bt_plugin_get_name(plugin); | |
895 | path = bt_plugin_get_path(plugin); | |
896 | author = bt_plugin_get_author(plugin); | |
897 | license = bt_plugin_get_license(plugin); | |
898 | plugin_description = bt_plugin_get_description(plugin); | |
0ae03127 | 899 | version_avail = bt_plugin_get_version(plugin, &major, &minor, |
22e22462 PP |
900 | &patch, &extra); |
901 | printf("%s%s%s%s:\n", bt_common_color_bold(), | |
902 | bt_common_color_fg_blue(), plugin_name, | |
903 | bt_common_color_reset()); | |
474f3246 MJ |
904 | if (path) { |
905 | printf(" %sPath%s: %s\n", bt_common_color_bold(), | |
906 | bt_common_color_reset(), path); | |
907 | } else { | |
908 | puts(" Built-in"); | |
909 | } | |
22e22462 | 910 | |
0ae03127 | 911 | if (version_avail == BT_PROPERTY_AVAILABILITY_AVAILABLE) { |
22e22462 PP |
912 | printf(" %sVersion%s: %u.%u.%u", |
913 | bt_common_color_bold(), bt_common_color_reset(), | |
914 | major, minor, patch); | |
915 | ||
916 | if (extra) { | |
917 | printf("%s", extra); | |
918 | } | |
919 | ||
920 | printf("\n"); | |
921 | } | |
922 | ||
923 | printf(" %sDescription%s: %s\n", bt_common_color_bold(), | |
924 | bt_common_color_reset(), | |
925 | plugin_description ? plugin_description : "(None)"); | |
926 | printf(" %sAuthor%s: %s\n", bt_common_color_bold(), | |
927 | bt_common_color_reset(), author ? author : "(Unknown)"); | |
928 | printf(" %sLicense%s: %s\n", bt_common_color_bold(), | |
929 | bt_common_color_reset(), | |
930 | license ? license : "(Unknown)"); | |
931 | } | |
932 | ||
9009cc24 PP |
933 | static |
934 | int cmd_query(struct bt_config *cfg) | |
63ce0e1d | 935 | { |
db95fa29 | 936 | int ret = 0; |
8eee8ea2 PP |
937 | const bt_component_class *comp_cls = NULL; |
938 | const bt_value *results = NULL; | |
1286dcbb | 939 | const char *fail_reason = NULL; |
63ce0e1d | 940 | |
834e9996 PP |
941 | comp_cls = find_component_class( |
942 | cfg->cmd_data.query.cfg_component->plugin_name->str, | |
db0f160a | 943 | cfg->cmd_data.query.cfg_component->comp_cls_name->str, |
a67681c1 | 944 | cfg->cmd_data.query.cfg_component->type); |
63ce0e1d | 945 | if (!comp_cls) { |
7213a328 PP |
946 | BT_LOGE("Cannot find component class: plugin-name=\"%s\", " |
947 | "comp-cls-name=\"%s\", comp-cls-type=%d", | |
948 | cfg->cmd_data.query.cfg_component->plugin_name->str, | |
949 | cfg->cmd_data.query.cfg_component->comp_cls_name->str, | |
950 | cfg->cmd_data.query.cfg_component->type); | |
63ce0e1d PP |
951 | fprintf(stderr, "%s%sCannot find component class %s", |
952 | bt_common_color_bold(), | |
953 | bt_common_color_fg_red(), | |
954 | bt_common_color_reset()); | |
955 | print_plugin_comp_cls_opt(stderr, | |
a67681c1 | 956 | cfg->cmd_data.query.cfg_component->plugin_name->str, |
db0f160a | 957 | cfg->cmd_data.query.cfg_component->comp_cls_name->str, |
a67681c1 | 958 | cfg->cmd_data.query.cfg_component->type); |
63ce0e1d PP |
959 | fprintf(stderr, "\n"); |
960 | ret = -1; | |
961 | goto end; | |
962 | } | |
963 | ||
83da519a | 964 | ret = query(cfg, comp_cls, cfg->cmd_data.query.object->str, |
ce141536 | 965 | cfg->cmd_data.query.cfg_component->params, |
17582c6d | 966 | &results, &fail_reason); |
1286dcbb PP |
967 | if (ret) { |
968 | goto failed; | |
63ce0e1d PP |
969 | } |
970 | ||
7213a328 | 971 | print_value(stdout, results, 0); |
1286dcbb PP |
972 | goto end; |
973 | ||
974 | failed: | |
975 | BT_LOGE("Failed to query component class: %s: plugin-name=\"%s\", " | |
976 | "comp-cls-name=\"%s\", comp-cls-type=%d " | |
977 | "object=\"%s\"", fail_reason, | |
978 | cfg->cmd_data.query.cfg_component->plugin_name->str, | |
979 | cfg->cmd_data.query.cfg_component->comp_cls_name->str, | |
980 | cfg->cmd_data.query.cfg_component->type, | |
981 | cfg->cmd_data.query.object->str); | |
982 | fprintf(stderr, "%s%sFailed to query info to %s", | |
983 | bt_common_color_bold(), | |
984 | bt_common_color_fg_red(), | |
985 | bt_common_color_reset()); | |
986 | print_plugin_comp_cls_opt(stderr, | |
987 | cfg->cmd_data.query.cfg_component->plugin_name->str, | |
988 | cfg->cmd_data.query.cfg_component->comp_cls_name->str, | |
989 | cfg->cmd_data.query.cfg_component->type); | |
990 | fprintf(stderr, "%s%s with object `%s`: %s%s\n", | |
991 | bt_common_color_bold(), | |
992 | bt_common_color_fg_red(), | |
993 | cfg->cmd_data.query.object->str, | |
994 | fail_reason, | |
995 | bt_common_color_reset()); | |
996 | ret = -1; | |
63ce0e1d PP |
997 | |
998 | end: | |
8c6884d9 PP |
999 | bt_component_class_put_ref(comp_cls); |
1000 | bt_value_put_ref(results); | |
63ce0e1d PP |
1001 | return ret; |
1002 | } | |
1003 | ||
834e9996 PP |
1004 | static |
1005 | void print_component_class_help(const char *plugin_name, | |
8eee8ea2 | 1006 | const bt_component_class *comp_cls) |
834e9996 PP |
1007 | { |
1008 | const char *comp_class_name = | |
1009 | bt_component_class_get_name(comp_cls); | |
1010 | const char *comp_class_description = | |
1011 | bt_component_class_get_description(comp_cls); | |
1012 | const char *comp_class_help = | |
1013 | bt_component_class_get_help(comp_cls); | |
ee78f405 | 1014 | bt_component_class_type type = |
834e9996 PP |
1015 | bt_component_class_get_type(comp_cls); |
1016 | ||
1017 | print_plugin_comp_cls_opt(stdout, plugin_name, comp_class_name, type); | |
1018 | printf("\n"); | |
1019 | printf(" %sDescription%s: %s\n", bt_common_color_bold(), | |
1020 | bt_common_color_reset(), | |
1021 | comp_class_description ? comp_class_description : "(None)"); | |
1022 | ||
1023 | if (comp_class_help) { | |
1024 | printf("\n%s\n", comp_class_help); | |
1025 | } | |
1026 | } | |
1027 | ||
9009cc24 PP |
1028 | static |
1029 | int cmd_help(struct bt_config *cfg) | |
22e22462 | 1030 | { |
db95fa29 | 1031 | int ret = 0; |
8eee8ea2 PP |
1032 | const bt_plugin *plugin = NULL; |
1033 | const bt_component_class *needed_comp_cls = NULL; | |
22e22462 | 1034 | |
90de159b | 1035 | plugin = find_plugin(cfg->cmd_data.help.cfg_component->plugin_name->str); |
22e22462 | 1036 | if (!plugin) { |
7213a328 PP |
1037 | BT_LOGE("Cannot find plugin: plugin-name=\"%s\"", |
1038 | cfg->cmd_data.help.cfg_component->plugin_name->str); | |
22e22462 PP |
1039 | fprintf(stderr, "%s%sCannot find plugin %s%s%s\n", |
1040 | bt_common_color_bold(), bt_common_color_fg_red(), | |
1041 | bt_common_color_fg_blue(), | |
90de159b | 1042 | cfg->cmd_data.help.cfg_component->plugin_name->str, |
22e22462 PP |
1043 | bt_common_color_reset()); |
1044 | ret = -1; | |
1045 | goto end; | |
1046 | } | |
1047 | ||
1048 | print_plugin_info(plugin); | |
834e9996 PP |
1049 | printf(" %sSource component classes%s: %d\n", |
1050 | bt_common_color_bold(), | |
1051 | bt_common_color_reset(), | |
1052 | (int) bt_plugin_get_source_component_class_count(plugin)); | |
1053 | printf(" %sFilter component classes%s: %d\n", | |
22e22462 PP |
1054 | bt_common_color_bold(), |
1055 | bt_common_color_reset(), | |
834e9996 PP |
1056 | (int) bt_plugin_get_filter_component_class_count(plugin)); |
1057 | printf(" %sSink component classes%s: %d\n", | |
1058 | bt_common_color_bold(), | |
1059 | bt_common_color_reset(), | |
1060 | (int) bt_plugin_get_sink_component_class_count(plugin)); | |
22e22462 | 1061 | |
834e9996 PP |
1062 | if (strlen(cfg->cmd_data.help.cfg_component->comp_cls_name->str) == 0) { |
1063 | /* Plugin help only */ | |
1064 | goto end; | |
1065 | } | |
22e22462 | 1066 | |
834e9996 PP |
1067 | needed_comp_cls = find_component_class( |
1068 | cfg->cmd_data.help.cfg_component->plugin_name->str, | |
1069 | cfg->cmd_data.help.cfg_component->comp_cls_name->str, | |
1070 | cfg->cmd_data.help.cfg_component->type); | |
1071 | if (!needed_comp_cls) { | |
1072 | BT_LOGE("Cannot find component class: plugin-name=\"%s\", " | |
1073 | "comp-cls-name=\"%s\", comp-cls-type=%d", | |
1074 | cfg->cmd_data.help.cfg_component->plugin_name->str, | |
1075 | cfg->cmd_data.help.cfg_component->comp_cls_name->str, | |
1076 | cfg->cmd_data.help.cfg_component->type); | |
1077 | fprintf(stderr, "\n%s%sCannot find component class %s", | |
1078 | bt_common_color_bold(), | |
1079 | bt_common_color_fg_red(), | |
1080 | bt_common_color_reset()); | |
1081 | print_plugin_comp_cls_opt(stderr, | |
1082 | cfg->cmd_data.help.cfg_component->plugin_name->str, | |
1083 | cfg->cmd_data.help.cfg_component->comp_cls_name->str, | |
1084 | cfg->cmd_data.help.cfg_component->type); | |
1085 | fprintf(stderr, "\n"); | |
1086 | ret = -1; | |
1087 | goto end; | |
1088 | } | |
22e22462 | 1089 | |
834e9996 PP |
1090 | printf("\n"); |
1091 | print_component_class_help( | |
1092 | cfg->cmd_data.help.cfg_component->plugin_name->str, | |
1093 | needed_comp_cls); | |
1094 | ||
1095 | end: | |
8c6884d9 PP |
1096 | bt_component_class_put_ref(needed_comp_cls); |
1097 | bt_plugin_put_ref(plugin); | |
834e9996 PP |
1098 | return ret; |
1099 | } | |
1100 | ||
8eee8ea2 | 1101 | typedef void *(* plugin_borrow_comp_cls_by_index_func_t)(const bt_plugin *, |
834e9996 | 1102 | uint64_t); |
8eee8ea2 | 1103 | typedef const bt_component_class *(* spec_comp_cls_borrow_comp_cls_func_t)( |
834e9996 PP |
1104 | void *); |
1105 | ||
8eee8ea2 | 1106 | void cmd_list_plugins_print_component_classes(const bt_plugin *plugin, |
834e9996 PP |
1107 | const char *cc_type_name, uint64_t count, |
1108 | plugin_borrow_comp_cls_by_index_func_t borrow_comp_cls_by_index_func, | |
1109 | spec_comp_cls_borrow_comp_cls_func_t spec_comp_cls_borrow_comp_cls_func) | |
1110 | { | |
1111 | uint64_t i; | |
22e22462 | 1112 | |
834e9996 | 1113 | if (count == 0) { |
7034d373 | 1114 | printf(" %s%s component classes%s: (none)\n", |
834e9996 | 1115 | bt_common_color_bold(), |
7034d373 | 1116 | cc_type_name, |
834e9996 PP |
1117 | bt_common_color_reset()); |
1118 | goto end; | |
1119 | } else { | |
7034d373 | 1120 | printf(" %s%s component classes%s:\n", |
834e9996 | 1121 | bt_common_color_bold(), |
7034d373 | 1122 | cc_type_name, |
834e9996 | 1123 | bt_common_color_reset()); |
22e22462 PP |
1124 | } |
1125 | ||
834e9996 | 1126 | for (i = 0; i < count; i++) { |
8eee8ea2 | 1127 | const bt_component_class *comp_class = |
834e9996 PP |
1128 | spec_comp_cls_borrow_comp_cls_func( |
1129 | borrow_comp_cls_by_index_func(plugin, i)); | |
22e22462 | 1130 | const char *comp_class_name = |
834e9996 | 1131 | bt_component_class_get_name(comp_class); |
22e22462 | 1132 | const char *comp_class_description = |
834e9996 | 1133 | bt_component_class_get_description(comp_class); |
ee78f405 | 1134 | bt_component_class_type type = |
834e9996 | 1135 | bt_component_class_get_type(comp_class); |
22e22462 | 1136 | |
834e9996 | 1137 | printf(" "); |
22e22462 | 1138 | print_plugin_comp_cls_opt(stdout, |
834e9996 | 1139 | bt_plugin_get_name(plugin), comp_class_name, |
22e22462 | 1140 | type); |
22e22462 | 1141 | |
834e9996 PP |
1142 | if (comp_class_description) { |
1143 | printf(": %s", comp_class_description); | |
22e22462 PP |
1144 | } |
1145 | ||
834e9996 | 1146 | printf("\n"); |
22e22462 PP |
1147 | } |
1148 | ||
1149 | end: | |
834e9996 | 1150 | return; |
22e22462 PP |
1151 | } |
1152 | ||
9009cc24 PP |
1153 | static |
1154 | int cmd_list_plugins(struct bt_config *cfg) | |
290725f7 | 1155 | { |
7213a328 | 1156 | int ret = 0; |
290725f7 PP |
1157 | int plugins_count, component_classes_count = 0, i; |
1158 | ||
22e22462 | 1159 | printf("From the following plugin paths:\n\n"); |
ce141536 | 1160 | print_value(stdout, cfg->plugin_paths, 2); |
22e22462 | 1161 | printf("\n"); |
290725f7 PP |
1162 | plugins_count = loaded_plugins->len; |
1163 | if (plugins_count == 0) { | |
7213a328 | 1164 | printf("No plugins found.\n"); |
56a1cced JG |
1165 | goto end; |
1166 | } | |
1167 | ||
290725f7 | 1168 | for (i = 0; i < plugins_count; i++) { |
8eee8ea2 | 1169 | const bt_plugin *plugin = g_ptr_array_index(loaded_plugins, i); |
290725f7 | 1170 | |
834e9996 PP |
1171 | component_classes_count += |
1172 | bt_plugin_get_source_component_class_count(plugin) + | |
1173 | bt_plugin_get_filter_component_class_count(plugin) + | |
1174 | bt_plugin_get_sink_component_class_count(plugin); | |
290725f7 | 1175 | } |
33bceaf8 | 1176 | |
290725f7 PP |
1177 | printf("Found %s%d%s component classes in %s%d%s plugins.\n", |
1178 | bt_common_color_bold(), | |
1179 | component_classes_count, | |
1180 | bt_common_color_reset(), | |
1181 | bt_common_color_bold(), | |
1182 | plugins_count, | |
1183 | bt_common_color_reset()); | |
1184 | ||
1185 | for (i = 0; i < plugins_count; i++) { | |
8eee8ea2 | 1186 | const bt_plugin *plugin = g_ptr_array_index(loaded_plugins, i); |
290725f7 | 1187 | |
22e22462 PP |
1188 | printf("\n"); |
1189 | print_plugin_info(plugin); | |
834e9996 PP |
1190 | cmd_list_plugins_print_component_classes(plugin, "Source", |
1191 | bt_plugin_get_source_component_class_count(plugin), | |
1192 | (plugin_borrow_comp_cls_by_index_func_t) | |
d8bd6ac7 | 1193 | bt_plugin_borrow_source_component_class_by_index_const, |
834e9996 | 1194 | (spec_comp_cls_borrow_comp_cls_func_t) |
bb61965b | 1195 | bt_component_class_source_as_component_class); |
834e9996 PP |
1196 | cmd_list_plugins_print_component_classes(plugin, "Filter", |
1197 | bt_plugin_get_filter_component_class_count(plugin), | |
1198 | (plugin_borrow_comp_cls_by_index_func_t) | |
d8bd6ac7 | 1199 | bt_plugin_borrow_filter_component_class_by_index_const, |
834e9996 | 1200 | (spec_comp_cls_borrow_comp_cls_func_t) |
bb61965b | 1201 | bt_component_class_filter_as_component_class); |
834e9996 PP |
1202 | cmd_list_plugins_print_component_classes(plugin, "Sink", |
1203 | bt_plugin_get_sink_component_class_count(plugin), | |
1204 | (plugin_borrow_comp_cls_by_index_func_t) | |
d8bd6ac7 | 1205 | bt_plugin_borrow_sink_component_class_by_index_const, |
834e9996 | 1206 | (spec_comp_cls_borrow_comp_cls_func_t) |
bb61965b | 1207 | bt_component_class_sink_as_component_class); |
290725f7 PP |
1208 | } |
1209 | ||
1210 | end: | |
1211 | return ret; | |
1212 | } | |
1213 | ||
9009cc24 PP |
1214 | static |
1215 | int cmd_print_lttng_live_sessions(struct bt_config *cfg) | |
db0f160a | 1216 | { |
96e8c7e1 | 1217 | int ret = 0; |
8eee8ea2 PP |
1218 | const bt_component_class *comp_cls = NULL; |
1219 | const bt_value *results = NULL; | |
1220 | bt_value *params = NULL; | |
1221 | const bt_value *map = NULL; | |
1222 | const bt_value *v = NULL; | |
96e8c7e1 MD |
1223 | static const char * const plugin_name = "ctf"; |
1224 | static const char * const comp_cls_name = "lttng-live"; | |
ee78f405 | 1225 | static const bt_component_class_type comp_cls_type = |
96e8c7e1 MD |
1226 | BT_COMPONENT_CLASS_TYPE_SOURCE; |
1227 | int64_t array_size, i; | |
1286dcbb | 1228 | const char *fail_reason = NULL; |
a107deea | 1229 | FILE *out_stream = stdout; |
96e8c7e1 | 1230 | |
8b45963b | 1231 | BT_ASSERT(cfg->cmd_data.print_lttng_live_sessions.url); |
96e8c7e1 MD |
1232 | comp_cls = find_component_class(plugin_name, comp_cls_name, |
1233 | comp_cls_type); | |
1234 | if (!comp_cls) { | |
1235 | BT_LOGE("Cannot find component class: plugin-name=\"%s\", " | |
1236 | "comp-cls-name=\"%s\", comp-cls-type=%d", | |
1237 | plugin_name, comp_cls_name, | |
1238 | BT_COMPONENT_CLASS_TYPE_SOURCE); | |
1239 | fprintf(stderr, "%s%sCannot find component class %s", | |
1240 | bt_common_color_bold(), | |
1241 | bt_common_color_fg_red(), | |
1242 | bt_common_color_reset()); | |
1243 | print_plugin_comp_cls_opt(stderr, plugin_name, | |
1244 | comp_cls_name, comp_cls_type); | |
1245 | fprintf(stderr, "\n"); | |
1246 | goto error; | |
1247 | } | |
1248 | ||
ce141536 | 1249 | params = bt_value_map_create(); |
96e8c7e1 MD |
1250 | if (!params) { |
1251 | goto error; | |
1252 | } | |
1253 | ||
ce141536 | 1254 | ret = bt_value_map_insert_string_entry(params, "url", |
96e8c7e1 MD |
1255 | cfg->cmd_data.print_lttng_live_sessions.url->str); |
1256 | if (ret) { | |
1257 | goto error; | |
1258 | } | |
1259 | ||
83da519a | 1260 | ret = query(cfg, comp_cls, "sessions", params, |
ce141536 | 1261 | &results, &fail_reason); |
1286dcbb PP |
1262 | if (ret) { |
1263 | goto failed; | |
96e8c7e1 MD |
1264 | } |
1265 | ||
8b45963b PP |
1266 | BT_ASSERT(results); |
1267 | ||
96e8c7e1 MD |
1268 | if (!bt_value_is_array(results)) { |
1269 | BT_LOGE_STR("Expecting an array for sessions query."); | |
1270 | fprintf(stderr, "%s%sUnexpected type returned by session query%s\n", | |
1271 | bt_common_color_bold(), | |
1272 | bt_common_color_fg_red(), | |
1273 | bt_common_color_reset()); | |
1274 | goto error; | |
1275 | } | |
1276 | ||
a107deea PP |
1277 | if (cfg->cmd_data.print_lttng_live_sessions.output_path->len > 0) { |
1278 | out_stream = | |
1279 | fopen(cfg->cmd_data.print_lttng_live_sessions.output_path->str, | |
1280 | "w"); | |
1281 | if (!out_stream) { | |
1282 | ret = -1; | |
1283 | BT_LOGE_ERRNO("Cannot open file for writing", | |
1284 | ": path=\"%s\"", | |
1285 | cfg->cmd_data.print_lttng_live_sessions.output_path->str); | |
1286 | goto end; | |
1287 | } | |
1288 | } | |
1289 | ||
44514773 | 1290 | array_size = bt_value_array_get_size(results); |
96e8c7e1 MD |
1291 | for (i = 0; i < array_size; i++) { |
1292 | const char *url_text; | |
1293 | int64_t timer_us, streams, clients; | |
1294 | ||
ce141536 | 1295 | map = bt_value_array_borrow_element_by_index_const(results, i); |
96e8c7e1 MD |
1296 | if (!map) { |
1297 | BT_LOGE_STR("Unexpected empty array entry."); | |
1298 | goto error; | |
1299 | } | |
1300 | if (!bt_value_is_map(map)) { | |
1301 | BT_LOGE_STR("Unexpected entry type."); | |
1302 | goto error; | |
1303 | } | |
1304 | ||
ce141536 | 1305 | v = bt_value_map_borrow_entry_value_const(map, "url"); |
96e8c7e1 MD |
1306 | if (!v) { |
1307 | BT_LOGE_STR("Unexpected empty array \"url\" entry."); | |
1308 | goto error; | |
1309 | } | |
b5cdc106 | 1310 | url_text = bt_value_string_get(v); |
a107deea | 1311 | fprintf(out_stream, "%s", url_text); |
ce141536 | 1312 | v = bt_value_map_borrow_entry_value_const(map, "timer-us"); |
96e8c7e1 MD |
1313 | if (!v) { |
1314 | BT_LOGE_STR("Unexpected empty array \"timer-us\" entry."); | |
1315 | goto error; | |
1316 | } | |
68d9d039 | 1317 | timer_us = bt_value_signed_integer_get(v); |
a107deea | 1318 | fprintf(out_stream, " (timer = %" PRIu64 ", ", timer_us); |
ce141536 | 1319 | v = bt_value_map_borrow_entry_value_const(map, "stream-count"); |
96e8c7e1 MD |
1320 | if (!v) { |
1321 | BT_LOGE_STR("Unexpected empty array \"stream-count\" entry."); | |
1322 | goto error; | |
1323 | } | |
68d9d039 | 1324 | streams = bt_value_signed_integer_get(v); |
a107deea | 1325 | fprintf(out_stream, "%" PRIu64 " stream(s), ", streams); |
ce141536 | 1326 | v = bt_value_map_borrow_entry_value_const(map, "client-count"); |
96e8c7e1 MD |
1327 | if (!v) { |
1328 | BT_LOGE_STR("Unexpected empty array \"client-count\" entry."); | |
1329 | goto error; | |
1330 | } | |
68d9d039 | 1331 | clients = bt_value_signed_integer_get(v); |
a107deea | 1332 | fprintf(out_stream, "%" PRIu64 " client(s) connected)\n", clients); |
96e8c7e1 | 1333 | } |
1286dcbb PP |
1334 | |
1335 | goto end; | |
1336 | ||
1337 | failed: | |
1338 | BT_LOGE("Failed to query for sessions: %s", fail_reason); | |
1339 | fprintf(stderr, "%s%sFailed to request sessions: %s%s\n", | |
1340 | bt_common_color_bold(), | |
1341 | bt_common_color_fg_red(), | |
1342 | fail_reason, | |
1343 | bt_common_color_reset()); | |
1344 | ||
1345 | error: | |
1346 | ret = -1; | |
1347 | ||
96e8c7e1 | 1348 | end: |
8c6884d9 PP |
1349 | bt_value_put_ref(results); |
1350 | bt_value_put_ref(params); | |
1351 | bt_component_class_put_ref(comp_cls); | |
a107deea PP |
1352 | |
1353 | if (out_stream && out_stream != stdout) { | |
1354 | int fclose_ret = fclose(out_stream); | |
1355 | ||
1356 | if (fclose_ret) { | |
1357 | BT_LOGE_ERRNO("Cannot close file stream", | |
1358 | ": path=\"%s\"", | |
1359 | cfg->cmd_data.print_lttng_live_sessions.output_path->str); | |
1360 | } | |
1361 | } | |
1362 | ||
83255e55 | 1363 | return ret; |
db0f160a PP |
1364 | } |
1365 | ||
9009cc24 PP |
1366 | static |
1367 | int cmd_print_ctf_metadata(struct bt_config *cfg) | |
05a67631 PP |
1368 | { |
1369 | int ret = 0; | |
8eee8ea2 PP |
1370 | const bt_component_class *comp_cls = NULL; |
1371 | const bt_value *results = NULL; | |
1372 | bt_value *params = NULL; | |
1373 | const bt_value *metadata_text_value = NULL; | |
05a67631 | 1374 | const char *metadata_text = NULL; |
db0f160a PP |
1375 | static const char * const plugin_name = "ctf"; |
1376 | static const char * const comp_cls_name = "fs"; | |
ee78f405 | 1377 | static const bt_component_class_type comp_cls_type = |
db0f160a | 1378 | BT_COMPONENT_CLASS_TYPE_SOURCE; |
1286dcbb | 1379 | const char *fail_reason = NULL; |
a107deea | 1380 | FILE *out_stream = stdout; |
db0f160a | 1381 | |
8b45963b | 1382 | BT_ASSERT(cfg->cmd_data.print_ctf_metadata.path); |
db0f160a PP |
1383 | comp_cls = find_component_class(plugin_name, comp_cls_name, |
1384 | comp_cls_type); | |
05a67631 | 1385 | if (!comp_cls) { |
7213a328 PP |
1386 | BT_LOGE("Cannot find component class: plugin-name=\"%s\", " |
1387 | "comp-cls-name=\"%s\", comp-cls-type=%d", | |
1388 | plugin_name, comp_cls_name, | |
1389 | BT_COMPONENT_CLASS_TYPE_SOURCE); | |
05a67631 PP |
1390 | fprintf(stderr, "%s%sCannot find component class %s", |
1391 | bt_common_color_bold(), | |
1392 | bt_common_color_fg_red(), | |
1393 | bt_common_color_reset()); | |
db0f160a PP |
1394 | print_plugin_comp_cls_opt(stderr, plugin_name, |
1395 | comp_cls_name, comp_cls_type); | |
05a67631 PP |
1396 | fprintf(stderr, "\n"); |
1397 | ret = -1; | |
1398 | goto end; | |
1399 | } | |
1400 | ||
ce141536 | 1401 | params = bt_value_map_create(); |
05a67631 PP |
1402 | if (!params) { |
1403 | ret = -1; | |
1404 | goto end; | |
1405 | } | |
1406 | ||
ce141536 | 1407 | ret = bt_value_map_insert_string_entry(params, "path", |
db0f160a | 1408 | cfg->cmd_data.print_ctf_metadata.path->str); |
05a67631 PP |
1409 | if (ret) { |
1410 | ret = -1; | |
1411 | goto end; | |
1412 | } | |
1413 | ||
83da519a | 1414 | ret = query(cfg, comp_cls, "metadata-info", |
ce141536 | 1415 | params, &results, &fail_reason); |
1286dcbb PP |
1416 | if (ret) { |
1417 | goto failed; | |
05a67631 PP |
1418 | } |
1419 | ||
ce141536 PP |
1420 | metadata_text_value = bt_value_map_borrow_entry_value_const(results, |
1421 | "text"); | |
05a67631 | 1422 | if (!metadata_text_value) { |
7213a328 | 1423 | BT_LOGE_STR("Cannot find `text` string value in the resulting metadata info object."); |
05a67631 PP |
1424 | ret = -1; |
1425 | goto end; | |
1426 | } | |
1427 | ||
b5cdc106 | 1428 | metadata_text = bt_value_string_get(metadata_text_value); |
a107deea PP |
1429 | |
1430 | if (cfg->cmd_data.print_ctf_metadata.output_path->len > 0) { | |
1431 | out_stream = | |
1432 | fopen(cfg->cmd_data.print_ctf_metadata.output_path->str, | |
1433 | "w"); | |
1434 | if (!out_stream) { | |
1435 | ret = -1; | |
1436 | BT_LOGE_ERRNO("Cannot open file for writing", | |
1437 | ": path=\"%s\"", | |
1438 | cfg->cmd_data.print_ctf_metadata.output_path->str); | |
1439 | goto end; | |
1440 | } | |
1441 | } | |
1442 | ||
1443 | ret = fprintf(out_stream, "%s\n", metadata_text); | |
1444 | if (ret < 0) { | |
1445 | BT_LOGE("Cannot write whole metadata text to output stream: " | |
1446 | "ret=%d", ret); | |
1ec75dfa | 1447 | goto end; |
a107deea PP |
1448 | } |
1449 | ||
1ec75dfa SM |
1450 | ret = 0; |
1451 | ||
1286dcbb PP |
1452 | goto end; |
1453 | ||
1454 | failed: | |
1455 | ret = -1; | |
1456 | BT_LOGE("Failed to query for metadata info: %s", fail_reason); | |
1457 | fprintf(stderr, "%s%sFailed to request metadata info: %s%s\n", | |
1458 | bt_common_color_bold(), | |
1459 | bt_common_color_fg_red(), | |
1460 | fail_reason, | |
1461 | bt_common_color_reset()); | |
05a67631 PP |
1462 | |
1463 | end: | |
8c6884d9 PP |
1464 | bt_value_put_ref(results); |
1465 | bt_value_put_ref(params); | |
1466 | bt_component_class_put_ref(comp_cls); | |
a107deea PP |
1467 | |
1468 | if (out_stream && out_stream != stdout) { | |
1469 | int fclose_ret = fclose(out_stream); | |
1470 | ||
1471 | if (fclose_ret) { | |
1472 | BT_LOGE_ERRNO("Cannot close file stream", | |
1473 | ": path=\"%s\"", | |
1474 | cfg->cmd_data.print_ctf_metadata.output_path->str); | |
1475 | } | |
1476 | } | |
1477 | ||
83255e55 | 1478 | return ret; |
05a67631 PP |
1479 | } |
1480 | ||
b5fe3e00 JG |
1481 | struct port_id { |
1482 | char *instance_name; | |
1483 | char *port_name; | |
1484 | }; | |
1485 | ||
1486 | struct trace_range { | |
1487 | uint64_t intersection_range_begin_ns; | |
1488 | uint64_t intersection_range_end_ns; | |
1489 | }; | |
1490 | ||
1491 | static | |
1492 | guint port_id_hash(gconstpointer v) | |
1493 | { | |
1494 | const struct port_id *id = v; | |
1495 | ||
8b45963b PP |
1496 | BT_ASSERT(id->instance_name); |
1497 | BT_ASSERT(id->port_name); | |
b5fe3e00 JG |
1498 | |
1499 | return g_str_hash(id->instance_name) ^ g_str_hash(id->port_name); | |
1500 | } | |
1501 | ||
1502 | static | |
1503 | gboolean port_id_equal(gconstpointer v1, gconstpointer v2) | |
1504 | { | |
1505 | const struct port_id *id1 = v1; | |
1506 | const struct port_id *id2 = v2; | |
1507 | ||
1508 | return !strcmp(id1->instance_name, id2->instance_name) && | |
1509 | !strcmp(id1->port_name, id2->port_name); | |
1510 | } | |
1511 | ||
1512 | static | |
1513 | void port_id_destroy(gpointer data) | |
1514 | { | |
1515 | struct port_id *id = data; | |
1516 | ||
1517 | free(id->instance_name); | |
1518 | free(id->port_name); | |
1519 | free(id); | |
1520 | } | |
1521 | ||
1522 | static | |
1523 | void trace_range_destroy(gpointer data) | |
1524 | { | |
1525 | free(data); | |
1526 | } | |
1527 | ||
9009cc24 PP |
1528 | struct cmd_run_ctx { |
1529 | /* Owned by this */ | |
834e9996 PP |
1530 | GHashTable *src_components; |
1531 | ||
1532 | /* Owned by this */ | |
1533 | GHashTable *flt_components; | |
1534 | ||
1535 | /* Owned by this */ | |
1536 | GHashTable *sink_components; | |
9009cc24 PP |
1537 | |
1538 | /* Owned by this */ | |
8eee8ea2 | 1539 | bt_graph *graph; |
9009cc24 PP |
1540 | |
1541 | /* Weak */ | |
1542 | struct bt_config *cfg; | |
1543 | ||
1544 | bool connect_ports; | |
b5fe3e00 JG |
1545 | |
1546 | bool stream_intersection_mode; | |
1547 | ||
1548 | /* | |
1549 | * Association of struct port_id -> struct trace_range. | |
1550 | */ | |
1551 | GHashTable *intersections; | |
9009cc24 PP |
1552 | }; |
1553 | ||
b5fe3e00 JG |
1554 | /* Returns a timestamp of the form "(-)s.ns" */ |
1555 | static | |
1556 | char *s_from_ns(int64_t ns) | |
1557 | { | |
1558 | int ret; | |
1559 | char *s_ret = NULL; | |
1560 | bool is_negative; | |
1561 | int64_t ts_sec_abs, ts_nsec_abs; | |
1562 | int64_t ts_sec = ns / NSEC_PER_SEC; | |
1563 | int64_t ts_nsec = ns % NSEC_PER_SEC; | |
1564 | ||
1565 | if (ts_sec >= 0 && ts_nsec >= 0) { | |
1566 | is_negative = false; | |
1567 | ts_sec_abs = ts_sec; | |
1568 | ts_nsec_abs = ts_nsec; | |
1569 | } else if (ts_sec > 0 && ts_nsec < 0) { | |
1570 | is_negative = false; | |
1571 | ts_sec_abs = ts_sec - 1; | |
1572 | ts_nsec_abs = NSEC_PER_SEC + ts_nsec; | |
1573 | } else if (ts_sec == 0 && ts_nsec < 0) { | |
1574 | is_negative = true; | |
1575 | ts_sec_abs = ts_sec; | |
1576 | ts_nsec_abs = -ts_nsec; | |
1577 | } else if (ts_sec < 0 && ts_nsec > 0) { | |
1578 | is_negative = true; | |
1579 | ts_sec_abs = -(ts_sec + 1); | |
1580 | ts_nsec_abs = NSEC_PER_SEC - ts_nsec; | |
1581 | } else if (ts_sec < 0 && ts_nsec == 0) { | |
1582 | is_negative = true; | |
1583 | ts_sec_abs = -ts_sec; | |
1584 | ts_nsec_abs = ts_nsec; | |
1585 | } else { /* (ts_sec < 0 && ts_nsec < 0) */ | |
1586 | is_negative = true; | |
1587 | ts_sec_abs = -ts_sec; | |
1588 | ts_nsec_abs = -ts_nsec; | |
1589 | } | |
1590 | ||
1591 | ret = asprintf(&s_ret, "%s%" PRId64 ".%09" PRId64, | |
1592 | is_negative ? "-" : "", ts_sec_abs, ts_nsec_abs); | |
1593 | if (ret < 0) { | |
1594 | s_ret = NULL; | |
1595 | } | |
1596 | return s_ret; | |
1597 | } | |
1598 | ||
9009cc24 PP |
1599 | static |
1600 | int cmd_run_ctx_connect_upstream_port_to_downstream_component( | |
834e9996 | 1601 | struct cmd_run_ctx *ctx, |
8eee8ea2 PP |
1602 | const bt_component *upstream_comp, |
1603 | const bt_port_output *out_upstream_port, | |
9009cc24 | 1604 | struct bt_config_connection *cfg_conn) |
290725f7 | 1605 | { |
834e9996 | 1606 | typedef uint64_t (*input_port_count_func_t)(void *); |
8eee8ea2 | 1607 | typedef const bt_port_input *(*borrow_input_port_by_index_func_t)( |
7b53201c | 1608 | const void *, uint64_t); |
8eee8ea2 | 1609 | const bt_port *upstream_port = |
7b53201c | 1610 | bt_port_output_as_port_const(out_upstream_port); |
834e9996 | 1611 | |
290725f7 | 1612 | int ret = 0; |
9009cc24 | 1613 | GQuark downstreamp_comp_name_quark; |
834e9996 PP |
1614 | void *downstream_comp; |
1615 | uint64_t downstream_port_count; | |
9009cc24 | 1616 | uint64_t i; |
834e9996 PP |
1617 | input_port_count_func_t port_count_fn; |
1618 | borrow_input_port_by_index_func_t port_by_index_fn; | |
ee78f405 | 1619 | bt_graph_status status = BT_GRAPH_STATUS_ERROR; |
b5fe3e00 | 1620 | bool insert_trimmer = false; |
8eee8ea2 | 1621 | bt_value *trimmer_params = NULL; |
b5fe3e00 JG |
1622 | char *intersection_begin = NULL; |
1623 | char *intersection_end = NULL; | |
8eee8ea2 PP |
1624 | const bt_component_filter *trimmer = NULL; |
1625 | const bt_component_class_filter *trimmer_class = NULL; | |
1626 | const bt_port_input *trimmer_input = NULL; | |
1627 | const bt_port_output *trimmer_output = NULL; | |
b5fe3e00 JG |
1628 | |
1629 | if (ctx->intersections && | |
1630 | bt_component_get_class_type(upstream_comp) == | |
1631 | BT_COMPONENT_CLASS_TYPE_SOURCE) { | |
1632 | struct trace_range *range; | |
1633 | struct port_id port_id = { | |
1634 | .instance_name = (char *) bt_component_get_name(upstream_comp), | |
1635 | .port_name = (char *) bt_port_get_name(upstream_port) | |
1636 | }; | |
1637 | ||
1638 | if (!port_id.instance_name || !port_id.port_name) { | |
1639 | goto error; | |
1640 | } | |
1641 | ||
1642 | range = (struct trace_range *) g_hash_table_lookup( | |
1643 | ctx->intersections, &port_id); | |
1644 | if (range) { | |
ee78f405 | 1645 | bt_value_status status; |
b5fe3e00 JG |
1646 | |
1647 | intersection_begin = s_from_ns( | |
1648 | range->intersection_range_begin_ns); | |
1649 | intersection_end = s_from_ns( | |
1650 | range->intersection_range_end_ns); | |
1651 | if (!intersection_begin || !intersection_end) { | |
1652 | BT_LOGE_STR("Cannot create trimmer argument timestamp string."); | |
1653 | goto error; | |
1654 | } | |
1655 | ||
1656 | insert_trimmer = true; | |
ce141536 | 1657 | trimmer_params = bt_value_map_create(); |
b5fe3e00 JG |
1658 | if (!trimmer_params) { |
1659 | goto error; | |
1660 | } | |
1661 | ||
ce141536 | 1662 | status = bt_value_map_insert_string_entry( |
44514773 | 1663 | trimmer_params, "begin", intersection_begin); |
b5fe3e00 JG |
1664 | if (status != BT_VALUE_STATUS_OK) { |
1665 | goto error; | |
1666 | } | |
ce141536 | 1667 | status = bt_value_map_insert_string_entry( |
44514773 | 1668 | trimmer_params, |
b5fe3e00 JG |
1669 | "end", intersection_end); |
1670 | if (status != BT_VALUE_STATUS_OK) { | |
1671 | goto error; | |
1672 | } | |
1673 | } | |
1674 | ||
834e9996 | 1675 | trimmer_class = find_filter_component_class("utils", "trimmer"); |
b5fe3e00 JG |
1676 | if (!trimmer_class) { |
1677 | goto error; | |
1678 | } | |
1679 | } | |
9009cc24 | 1680 | |
7213a328 PP |
1681 | BT_LOGI("Connecting upstream port to the next available downstream port: " |
1682 | "upstream-port-addr=%p, upstream-port-name=\"%s\", " | |
1683 | "downstream-comp-name=\"%s\", conn-arg=\"%s\"", | |
1684 | upstream_port, bt_port_get_name(upstream_port), | |
1685 | cfg_conn->downstream_comp_name->str, | |
1686 | cfg_conn->arg->str); | |
9009cc24 PP |
1687 | downstreamp_comp_name_quark = g_quark_from_string( |
1688 | cfg_conn->downstream_comp_name->str); | |
8b45963b | 1689 | BT_ASSERT(downstreamp_comp_name_quark > 0); |
834e9996 | 1690 | downstream_comp = g_hash_table_lookup(ctx->flt_components, |
71c7c95f | 1691 | GUINT_TO_POINTER(downstreamp_comp_name_quark)); |
834e9996 PP |
1692 | port_count_fn = (input_port_count_func_t) |
1693 | bt_component_filter_get_input_port_count; | |
1694 | port_by_index_fn = (borrow_input_port_by_index_func_t) | |
7b53201c | 1695 | bt_component_filter_borrow_input_port_by_index_const; |
834e9996 PP |
1696 | |
1697 | if (!downstream_comp) { | |
1698 | downstream_comp = g_hash_table_lookup(ctx->sink_components, | |
1699 | GUINT_TO_POINTER(downstreamp_comp_name_quark)); | |
1700 | port_count_fn = (input_port_count_func_t) | |
1701 | bt_component_sink_get_input_port_count; | |
1702 | port_by_index_fn = (borrow_input_port_by_index_func_t) | |
7b53201c | 1703 | bt_component_sink_borrow_input_port_by_index_const; |
834e9996 PP |
1704 | } |
1705 | ||
9009cc24 | 1706 | if (!downstream_comp) { |
7213a328 PP |
1707 | BT_LOGE("Cannot find downstream component: comp-name=\"%s\", " |
1708 | "conn-arg=\"%s\"", cfg_conn->downstream_comp_name->str, | |
1709 | cfg_conn->arg->str); | |
9009cc24 PP |
1710 | fprintf(stderr, "Cannot create connection: cannot find downstream component: %s\n", |
1711 | cfg_conn->arg->str); | |
1712 | goto error; | |
1713 | } | |
1714 | ||
9009cc24 | 1715 | downstream_port_count = port_count_fn(downstream_comp); |
9009cc24 PP |
1716 | |
1717 | for (i = 0; i < downstream_port_count; i++) { | |
8eee8ea2 | 1718 | const bt_port_input *in_downstream_port = |
9009cc24 | 1719 | port_by_index_fn(downstream_comp, i); |
8eee8ea2 | 1720 | const bt_port *downstream_port = |
7b53201c | 1721 | bt_port_input_as_port_const(in_downstream_port); |
b5fe3e00 | 1722 | const char *upstream_port_name; |
9009cc24 PP |
1723 | const char *downstream_port_name; |
1724 | ||
8b45963b | 1725 | BT_ASSERT(downstream_port); |
9009cc24 | 1726 | |
b5fe3e00 | 1727 | /* Skip port if it's already connected. */ |
9009cc24 | 1728 | if (bt_port_is_connected(downstream_port)) { |
a684a357 | 1729 | BT_LOGI("Skipping downstream port: already connected: " |
7213a328 PP |
1730 | "port-addr=%p, port-name=\"%s\"", |
1731 | downstream_port, | |
1732 | bt_port_get_name(downstream_port)); | |
9009cc24 PP |
1733 | continue; |
1734 | } | |
1735 | ||
1736 | downstream_port_name = bt_port_get_name(downstream_port); | |
8b45963b | 1737 | BT_ASSERT(downstream_port_name); |
b5fe3e00 | 1738 | upstream_port_name = bt_port_get_name(upstream_port); |
8b45963b | 1739 | BT_ASSERT(upstream_port_name); |
9009cc24 | 1740 | |
b5fe3e00 | 1741 | if (!bt_common_star_glob_match( |
41342c71 MJ |
1742 | cfg_conn->downstream_port_glob->str, SIZE_MAX, |
1743 | downstream_port_name, SIZE_MAX)) { | |
b5fe3e00 JG |
1744 | continue; |
1745 | } | |
1746 | ||
1747 | if (insert_trimmer) { | |
1748 | /* | |
834e9996 PP |
1749 | * In order to insert the trimmer between the |
1750 | * two components that were being connected, we | |
1751 | * create a connection configuration entry which | |
1752 | * describes a connection from the trimmer's | |
1753 | * output to the original input that was being | |
1754 | * connected. | |
b5fe3e00 | 1755 | * |
834e9996 PP |
1756 | * Hence, the creation of the trimmer will cause |
1757 | * the graph "new port" listener to establish | |
1758 | * all downstream connections as its output port | |
1759 | * is connected. We will then establish the | |
1760 | * connection between the original upstream | |
1761 | * source and the trimmer. | |
b5fe3e00 JG |
1762 | */ |
1763 | char *trimmer_name = NULL; | |
ee78f405 | 1764 | bt_graph_status graph_status; |
b5fe3e00 | 1765 | |
834e9996 PP |
1766 | ret = asprintf(&trimmer_name, |
1767 | "stream-intersection-trimmer-%s", | |
b5fe3e00 JG |
1768 | upstream_port_name); |
1769 | if (ret < 0) { | |
1770 | goto error; | |
1771 | } | |
1772 | ret = 0; | |
1773 | ||
1774 | ctx->connect_ports = false; | |
7b53201c | 1775 | graph_status = bt_graph_add_filter_component( |
834e9996 | 1776 | ctx->graph, trimmer_class, trimmer_name, |
cc81b5ab PP |
1777 | trimmer_params, ctx->cfg->log_level, |
1778 | &trimmer); | |
b5fe3e00 JG |
1779 | free(trimmer_name); |
1780 | if (graph_status != BT_GRAPH_STATUS_OK) { | |
1781 | goto error; | |
1782 | } | |
8b45963b | 1783 | BT_ASSERT(trimmer); |
b5fe3e00 JG |
1784 | |
1785 | trimmer_input = | |
7b53201c | 1786 | bt_component_filter_borrow_input_port_by_index_const( |
b5fe3e00 JG |
1787 | trimmer, 0); |
1788 | if (!trimmer_input) { | |
1789 | goto error; | |
1790 | } | |
1791 | trimmer_output = | |
7b53201c | 1792 | bt_component_filter_borrow_output_port_by_index_const( |
b5fe3e00 JG |
1793 | trimmer, 0); |
1794 | if (!trimmer_output) { | |
9009cc24 PP |
1795 | goto error; |
1796 | } | |
1797 | ||
b5fe3e00 JG |
1798 | /* |
1799 | * Replace the current downstream port by the trimmer's | |
1800 | * upstream port. | |
1801 | */ | |
834e9996 PP |
1802 | in_downstream_port = trimmer_input; |
1803 | downstream_port = | |
7b53201c | 1804 | bt_port_input_as_port_const(in_downstream_port); |
b5fe3e00 JG |
1805 | downstream_port_name = bt_port_get_name( |
1806 | downstream_port); | |
834e9996 | 1807 | BT_ASSERT(downstream_port_name); |
b5fe3e00 JG |
1808 | } |
1809 | ||
1810 | /* We have a winner! */ | |
7b53201c | 1811 | status = bt_graph_connect_ports(ctx->graph, |
834e9996 PP |
1812 | out_upstream_port, in_downstream_port, NULL); |
1813 | downstream_port = NULL; | |
b5fe3e00 JG |
1814 | switch (status) { |
1815 | case BT_GRAPH_STATUS_OK: | |
1816 | break; | |
1817 | case BT_GRAPH_STATUS_CANCELED: | |
1818 | BT_LOGI_STR("Graph was canceled by user."); | |
1819 | status = BT_GRAPH_STATUS_OK; | |
1820 | break; | |
1821 | case BT_GRAPH_STATUS_COMPONENT_REFUSES_PORT_CONNECTION: | |
1822 | BT_LOGE("A component refused a connection to one of its ports: " | |
7213a328 PP |
1823 | "upstream-comp-addr=%p, upstream-comp-name=\"%s\", " |
1824 | "upstream-port-addr=%p, upstream-port-name=\"%s\", " | |
1825 | "downstream-comp-addr=%p, downstream-comp-name=\"%s\", " | |
1826 | "downstream-port-addr=%p, downstream-port-name=\"%s\", " | |
1827 | "conn-arg=\"%s\"", | |
1828 | upstream_comp, bt_component_get_name(upstream_comp), | |
1829 | upstream_port, bt_port_get_name(upstream_port), | |
1830 | downstream_comp, cfg_conn->downstream_comp_name->str, | |
1831 | downstream_port, downstream_port_name, | |
1832 | cfg_conn->arg->str); | |
b5fe3e00 JG |
1833 | fprintf(stderr, |
1834 | "A component refused a connection to one of its ports (`%s` to `%s`): %s\n", | |
1835 | bt_port_get_name(upstream_port), | |
1836 | downstream_port_name, | |
1837 | cfg_conn->arg->str); | |
1838 | break; | |
1839 | default: | |
1840 | BT_LOGE("Cannot create connection: graph refuses to connect ports: " | |
1841 | "upstream-comp-addr=%p, upstream-comp-name=\"%s\", " | |
1842 | "upstream-port-addr=%p, upstream-port-name=\"%s\", " | |
1843 | "downstream-comp-addr=%p, downstream-comp-name=\"%s\", " | |
1844 | "downstream-port-addr=%p, downstream-port-name=\"%s\", " | |
1845 | "conn-arg=\"%s\"", | |
1846 | upstream_comp, bt_component_get_name(upstream_comp), | |
1847 | upstream_port, bt_port_get_name(upstream_port), | |
1848 | downstream_comp, cfg_conn->downstream_comp_name->str, | |
1849 | downstream_port, downstream_port_name, | |
1850 | cfg_conn->arg->str); | |
1851 | fprintf(stderr, | |
1852 | "Cannot create connection: graph refuses to connect ports (`%s` to `%s`): %s\n", | |
1853 | bt_port_get_name(upstream_port), | |
1854 | downstream_port_name, | |
1855 | cfg_conn->arg->str); | |
1856 | goto error; | |
9009cc24 PP |
1857 | } |
1858 | ||
b5fe3e00 JG |
1859 | BT_LOGI("Connected component ports: " |
1860 | "upstream-comp-addr=%p, upstream-comp-name=\"%s\", " | |
1861 | "upstream-port-addr=%p, upstream-port-name=\"%s\", " | |
1862 | "downstream-comp-addr=%p, downstream-comp-name=\"%s\", " | |
1863 | "downstream-port-addr=%p, downstream-port-name=\"%s\", " | |
1864 | "conn-arg=\"%s\"", | |
1865 | upstream_comp, bt_component_get_name(upstream_comp), | |
1866 | upstream_port, bt_port_get_name(upstream_port), | |
1867 | downstream_comp, cfg_conn->downstream_comp_name->str, | |
1868 | downstream_port, downstream_port_name, | |
1869 | cfg_conn->arg->str); | |
1870 | ||
1871 | if (insert_trimmer) { | |
1872 | /* | |
1873 | * The first connection, from the source to the trimmer, | |
1874 | * has been done. We now connect the trimmer to the | |
1875 | * original downstream port. | |
1876 | */ | |
1877 | ret = cmd_run_ctx_connect_upstream_port_to_downstream_component( | |
834e9996 | 1878 | ctx, |
7b53201c | 1879 | bt_component_filter_as_component_const(trimmer), |
834e9996 | 1880 | trimmer_output, cfg_conn); |
b5fe3e00 JG |
1881 | if (ret) { |
1882 | goto error; | |
1883 | } | |
1884 | ctx->connect_ports = true; | |
1885 | } | |
9009cc24 | 1886 | |
6de93a4a PP |
1887 | /* |
1888 | * We found a matching downstream port: the search is | |
1889 | * over. | |
1890 | */ | |
1891 | goto end; | |
05a67631 PP |
1892 | } |
1893 | ||
6de93a4a PP |
1894 | /* No downstream port found */ |
1895 | BT_LOGE("Cannot create connection: cannot find a matching downstream port for upstream port: " | |
1896 | "upstream-port-addr=%p, upstream-port-name=\"%s\", " | |
1897 | "downstream-comp-name=\"%s\", conn-arg=\"%s\"", | |
1898 | upstream_port, bt_port_get_name(upstream_port), | |
1899 | cfg_conn->downstream_comp_name->str, | |
1900 | cfg_conn->arg->str); | |
1901 | fprintf(stderr, | |
1902 | "Cannot create connection: cannot find a matching downstream port for upstream port `%s`: %s\n", | |
1903 | bt_port_get_name(upstream_port), cfg_conn->arg->str); | |
9009cc24 PP |
1904 | |
1905 | error: | |
1906 | ret = -1; | |
1907 | ||
1908 | end: | |
b5fe3e00 JG |
1909 | free(intersection_begin); |
1910 | free(intersection_end); | |
8c6884d9 PP |
1911 | BT_VALUE_PUT_REF_AND_RESET(trimmer_params); |
1912 | BT_COMPONENT_CLASS_FILTER_PUT_REF_AND_RESET(trimmer_class); | |
1913 | BT_COMPONENT_FILTER_PUT_REF_AND_RESET(trimmer); | |
9009cc24 PP |
1914 | return ret; |
1915 | } | |
1916 | ||
1917 | static | |
1918 | int cmd_run_ctx_connect_upstream_port(struct cmd_run_ctx *ctx, | |
8eee8ea2 | 1919 | const bt_port_output *upstream_port) |
9009cc24 PP |
1920 | { |
1921 | int ret = 0; | |
1922 | const char *upstream_port_name; | |
1923 | const char *upstream_comp_name; | |
8eee8ea2 | 1924 | const bt_component *upstream_comp = NULL; |
9009cc24 PP |
1925 | size_t i; |
1926 | ||
8b45963b PP |
1927 | BT_ASSERT(ctx); |
1928 | BT_ASSERT(upstream_port); | |
834e9996 | 1929 | upstream_port_name = bt_port_get_name( |
7b53201c | 1930 | bt_port_output_as_port_const(upstream_port)); |
8b45963b | 1931 | BT_ASSERT(upstream_port_name); |
7b53201c PP |
1932 | upstream_comp = bt_port_borrow_component_const( |
1933 | bt_port_output_as_port_const(upstream_port)); | |
9009cc24 | 1934 | if (!upstream_comp) { |
7213a328 PP |
1935 | BT_LOGW("Upstream port to connect is not part of a component: " |
1936 | "port-addr=%p, port-name=\"%s\"", | |
1937 | upstream_port, upstream_port_name); | |
98ecef32 MD |
1938 | ret = -1; |
1939 | goto end; | |
33bceaf8 JG |
1940 | } |
1941 | ||
9009cc24 | 1942 | upstream_comp_name = bt_component_get_name(upstream_comp); |
8b45963b | 1943 | BT_ASSERT(upstream_comp_name); |
7213a328 PP |
1944 | BT_LOGI("Connecting upstream port: comp-addr=%p, comp-name=\"%s\", " |
1945 | "port-addr=%p, port-name=\"%s\"", | |
1946 | upstream_comp, upstream_comp_name, | |
1947 | upstream_port, upstream_port_name); | |
9009cc24 PP |
1948 | |
1949 | for (i = 0; i < ctx->cfg->cmd_data.run.connections->len; i++) { | |
1950 | struct bt_config_connection *cfg_conn = | |
1951 | g_ptr_array_index( | |
1952 | ctx->cfg->cmd_data.run.connections, i); | |
1953 | ||
1954 | if (strcmp(cfg_conn->upstream_comp_name->str, | |
b5fe3e00 JG |
1955 | upstream_comp_name)) { |
1956 | continue; | |
1957 | } | |
1958 | ||
1959 | if (!bt_common_star_glob_match( | |
1960 | cfg_conn->upstream_port_glob->str, | |
41342c71 | 1961 | SIZE_MAX, upstream_port_name, SIZE_MAX)) { |
b5fe3e00 JG |
1962 | continue; |
1963 | } | |
1964 | ||
1965 | ret = cmd_run_ctx_connect_upstream_port_to_downstream_component( | |
1966 | ctx, upstream_comp, upstream_port, cfg_conn); | |
1967 | if (ret) { | |
1968 | BT_LOGE("Cannot connect upstream port: " | |
1969 | "port-addr=%p, port-name=\"%s\"", | |
1970 | upstream_port, | |
1971 | upstream_port_name); | |
1972 | fprintf(stderr, | |
1973 | "Cannot connect port `%s` of component `%s` to a downstream port: %s\n", | |
1974 | upstream_port_name, | |
1975 | upstream_comp_name, | |
1976 | cfg_conn->arg->str); | |
1977 | goto error; | |
9009cc24 | 1978 | } |
b5fe3e00 | 1979 | goto end; |
9009cc24 PP |
1980 | } |
1981 | ||
7213a328 PP |
1982 | BT_LOGE("Cannot connect upstream port: port does not match any connection argument: " |
1983 | "port-addr=%p, port-name=\"%s\"", upstream_port, | |
1984 | upstream_port_name); | |
9009cc24 PP |
1985 | fprintf(stderr, |
1986 | "Cannot create connection: upstream port `%s` does not match any connection\n", | |
7213a328 | 1987 | upstream_port_name); |
9009cc24 PP |
1988 | |
1989 | error: | |
1990 | ret = -1; | |
1991 | ||
1992 | end: | |
9009cc24 PP |
1993 | return ret; |
1994 | } | |
1995 | ||
1996 | static | |
e18f3e2b SM |
1997 | bt_graph_listener_status |
1998 | graph_output_port_added_listener(struct cmd_run_ctx *ctx, | |
8eee8ea2 | 1999 | const bt_port_output *out_port) |
9009cc24 | 2000 | { |
8eee8ea2 PP |
2001 | const bt_component *comp; |
2002 | const bt_port *port = bt_port_output_as_port_const(out_port); | |
e18f3e2b | 2003 | bt_graph_listener_status ret = BT_GRAPH_LISTENER_STATUS_OK; |
9009cc24 | 2004 | |
7b53201c | 2005 | comp = bt_port_borrow_component_const(port); |
e12720c0 PP |
2006 | BT_LOGI("Port added to a graph's component: comp-addr=%p, " |
2007 | "comp-name=\"%s\", port-addr=%p, port-name=\"%s\"", | |
2008 | comp, comp ? bt_component_get_name(comp) : "", | |
7213a328 | 2009 | port, bt_port_get_name(port)); |
36712f1d PP |
2010 | |
2011 | if (!ctx->connect_ports) { | |
2012 | goto end; | |
2013 | } | |
2014 | ||
e12720c0 PP |
2015 | if (!comp) { |
2016 | BT_LOGW_STR("Port has no component."); | |
56a1cced JG |
2017 | goto end; |
2018 | } | |
7c7c0433 | 2019 | |
e12720c0 PP |
2020 | if (bt_port_is_connected(port)) { |
2021 | BT_LOGW_STR("Port is already connected."); | |
7c7c0433 JG |
2022 | goto end; |
2023 | } | |
2024 | ||
834e9996 | 2025 | if (cmd_run_ctx_connect_upstream_port(ctx, out_port)) { |
7213a328 | 2026 | BT_LOGF_STR("Cannot connect upstream port."); |
9009cc24 | 2027 | fprintf(stderr, "Added port could not be connected: aborting\n"); |
e18f3e2b SM |
2028 | ret = BT_GRAPH_LISTENER_STATUS_ERROR; |
2029 | goto end; | |
9009cc24 PP |
2030 | } |
2031 | ||
2032 | end: | |
e18f3e2b | 2033 | return ret; |
9009cc24 PP |
2034 | } |
2035 | ||
2036 | static | |
e18f3e2b | 2037 | bt_graph_listener_status graph_source_output_port_added_listener( |
8eee8ea2 PP |
2038 | const bt_component_source *component, |
2039 | const bt_port_output *port, void *data) | |
9009cc24 | 2040 | { |
e18f3e2b | 2041 | return graph_output_port_added_listener(data, port); |
9009cc24 PP |
2042 | } |
2043 | ||
2044 | static | |
e18f3e2b | 2045 | bt_graph_listener_status graph_filter_output_port_added_listener( |
8eee8ea2 PP |
2046 | const bt_component_filter *component, |
2047 | const bt_port_output *port, void *data) | |
9009cc24 | 2048 | { |
e18f3e2b | 2049 | return graph_output_port_added_listener(data, port); |
9009cc24 PP |
2050 | } |
2051 | ||
2052 | static | |
2053 | void cmd_run_ctx_destroy(struct cmd_run_ctx *ctx) | |
2054 | { | |
2055 | if (!ctx) { | |
2056 | return; | |
2057 | } | |
2058 | ||
834e9996 PP |
2059 | if (ctx->src_components) { |
2060 | g_hash_table_destroy(ctx->src_components); | |
2061 | ctx->src_components = NULL; | |
2062 | } | |
2063 | ||
2064 | if (ctx->flt_components) { | |
2065 | g_hash_table_destroy(ctx->flt_components); | |
2066 | ctx->flt_components = NULL; | |
2067 | } | |
2068 | ||
2069 | if (ctx->sink_components) { | |
2070 | g_hash_table_destroy(ctx->sink_components); | |
2071 | ctx->sink_components = NULL; | |
9009cc24 PP |
2072 | } |
2073 | ||
b5fe3e00 JG |
2074 | if (ctx->intersections) { |
2075 | g_hash_table_destroy(ctx->intersections); | |
ea06dc14 | 2076 | ctx->intersections = NULL; |
b5fe3e00 JG |
2077 | } |
2078 | ||
8c6884d9 | 2079 | BT_GRAPH_PUT_REF_AND_RESET(ctx->graph); |
5401f780 | 2080 | the_graph = NULL; |
9009cc24 PP |
2081 | ctx->cfg = NULL; |
2082 | } | |
2083 | ||
2084 | static | |
2085 | int cmd_run_ctx_init(struct cmd_run_ctx *ctx, struct bt_config *cfg) | |
2086 | { | |
2087 | int ret = 0; | |
ee78f405 | 2088 | bt_graph_status status; |
9009cc24 PP |
2089 | |
2090 | ctx->cfg = cfg; | |
2091 | ctx->connect_ports = false; | |
834e9996 | 2092 | ctx->src_components = g_hash_table_new_full(g_direct_hash, |
4b70020d | 2093 | g_direct_equal, NULL, (GDestroyNotify) bt_object_put_ref); |
834e9996 PP |
2094 | if (!ctx->src_components) { |
2095 | goto error; | |
2096 | } | |
2097 | ||
2098 | ctx->flt_components = g_hash_table_new_full(g_direct_hash, | |
4b70020d | 2099 | g_direct_equal, NULL, (GDestroyNotify) bt_object_put_ref); |
834e9996 PP |
2100 | if (!ctx->flt_components) { |
2101 | goto error; | |
2102 | } | |
2103 | ||
2104 | ctx->sink_components = g_hash_table_new_full(g_direct_hash, | |
4b70020d | 2105 | g_direct_equal, NULL, (GDestroyNotify) bt_object_put_ref); |
834e9996 | 2106 | if (!ctx->sink_components) { |
9009cc24 PP |
2107 | goto error; |
2108 | } | |
2109 | ||
b5fe3e00 JG |
2110 | if (cfg->cmd_data.run.stream_intersection_mode) { |
2111 | ctx->stream_intersection_mode = true; | |
2112 | ctx->intersections = g_hash_table_new_full(port_id_hash, | |
2113 | port_id_equal, port_id_destroy, trace_range_destroy); | |
2114 | if (!ctx->intersections) { | |
2115 | goto error; | |
2116 | } | |
2117 | } | |
2118 | ||
7b53201c | 2119 | ctx->graph = bt_graph_create(); |
9009cc24 PP |
2120 | if (!ctx->graph) { |
2121 | goto error; | |
2122 | } | |
2123 | ||
5401f780 | 2124 | the_graph = ctx->graph; |
7b53201c | 2125 | status = bt_graph_add_source_component_output_port_added_listener( |
834e9996 PP |
2126 | ctx->graph, graph_source_output_port_added_listener, NULL, ctx, |
2127 | NULL); | |
2128 | if (status != BT_GRAPH_STATUS_OK) { | |
0d107cdd | 2129 | BT_LOGE_STR("Cannot add \"port added\" listener to graph."); |
9009cc24 PP |
2130 | goto error; |
2131 | } | |
2132 | ||
7b53201c | 2133 | status = bt_graph_add_filter_component_output_port_added_listener( |
834e9996 PP |
2134 | ctx->graph, graph_filter_output_port_added_listener, NULL, ctx, |
2135 | NULL); | |
2136 | if (status != BT_GRAPH_STATUS_OK) { | |
2137 | BT_LOGE_STR("Cannot add \"port added\" listener to graph."); | |
9009cc24 PP |
2138 | goto error; |
2139 | } | |
2140 | ||
2141 | goto end; | |
2142 | ||
2143 | error: | |
2144 | cmd_run_ctx_destroy(ctx); | |
2145 | ret = -1; | |
2146 | ||
2147 | end: | |
2148 | return ret; | |
2149 | } | |
2150 | ||
b5fe3e00 JG |
2151 | static |
2152 | int set_stream_intersections(struct cmd_run_ctx *ctx, | |
2153 | struct bt_config_component *cfg_comp, | |
8eee8ea2 | 2154 | const bt_component_class_source *src_comp_cls) |
b5fe3e00 JG |
2155 | { |
2156 | int ret = 0; | |
2157 | uint64_t trace_idx; | |
2158 | int64_t trace_count; | |
b5fe3e00 | 2159 | const char *path = NULL; |
8eee8ea2 PP |
2160 | const bt_value *query_result = NULL; |
2161 | const bt_value *trace_info = NULL; | |
2162 | const bt_value *intersection_range = NULL; | |
2163 | const bt_value *intersection_begin = NULL; | |
2164 | const bt_value *intersection_end = NULL; | |
8eee8ea2 PP |
2165 | const bt_value *stream_infos = NULL; |
2166 | const bt_value *stream_info = NULL; | |
b5fe3e00 JG |
2167 | struct port_id *port_id = NULL; |
2168 | struct trace_range *trace_range = NULL; | |
1286dcbb | 2169 | const char *fail_reason = NULL; |
8eee8ea2 | 2170 | const bt_component_class *comp_cls = |
7b53201c | 2171 | bt_component_class_source_as_component_class_const(src_comp_cls); |
b5fe3e00 | 2172 | |
83da519a | 2173 | ret = query(ctx->cfg, comp_cls, "trace-info", |
bf5b7748 | 2174 | cfg_comp->params, &query_result, |
1286dcbb PP |
2175 | &fail_reason); |
2176 | if (ret) { | |
2177 | BT_LOGD("Component class does not support the `trace-info` query: %s: " | |
2178 | "comp-class-name=\"%s\"", fail_reason, | |
b5fe3e00 JG |
2179 | bt_component_class_get_name(comp_cls)); |
2180 | ret = -1; | |
2181 | goto error; | |
2182 | } | |
2183 | ||
8b45963b PP |
2184 | BT_ASSERT(query_result); |
2185 | ||
b5fe3e00 JG |
2186 | if (!bt_value_is_array(query_result)) { |
2187 | BT_LOGD("Unexpected format of \'trace-info\' query result: " | |
2188 | "component-class-name=%s", | |
2189 | bt_component_class_get_name(comp_cls)); | |
2190 | ret = -1; | |
2191 | goto error; | |
2192 | } | |
2193 | ||
44514773 | 2194 | trace_count = bt_value_array_get_size(query_result); |
b5fe3e00 JG |
2195 | if (trace_count < 0) { |
2196 | ret = -1; | |
2197 | goto error; | |
2198 | } | |
2199 | ||
2200 | for (trace_idx = 0; trace_idx < trace_count; trace_idx++) { | |
2201 | int64_t begin, end; | |
2202 | uint64_t stream_idx; | |
2203 | int64_t stream_count; | |
2204 | ||
ce141536 | 2205 | trace_info = bt_value_array_borrow_element_by_index_const( |
44514773 | 2206 | query_result, trace_idx); |
b5fe3e00 JG |
2207 | if (!trace_info || !bt_value_is_map(trace_info)) { |
2208 | ret = -1; | |
2209 | BT_LOGD_STR("Cannot retrieve trace from query result."); | |
2210 | goto error; | |
2211 | } | |
2212 | ||
ce141536 PP |
2213 | intersection_range = bt_value_map_borrow_entry_value_const( |
2214 | trace_info, "intersection-range-ns"); | |
b5fe3e00 JG |
2215 | if (!intersection_range) { |
2216 | ret = -1; | |
2217 | BT_LOGD_STR("Cannot retrieve \'intersetion-range-ns\' field from query result."); | |
2218 | goto error; | |
2219 | } | |
2220 | ||
ce141536 PP |
2221 | intersection_begin = bt_value_map_borrow_entry_value_const(intersection_range, |
2222 | "begin"); | |
b5fe3e00 JG |
2223 | if (!intersection_begin) { |
2224 | ret = -1; | |
2225 | BT_LOGD_STR("Cannot retrieve intersection-range-ns \'begin\' field from query result."); | |
2226 | goto error; | |
2227 | } | |
2228 | ||
ce141536 PP |
2229 | intersection_end = bt_value_map_borrow_entry_value_const(intersection_range, |
2230 | "end"); | |
b5fe3e00 JG |
2231 | if (!intersection_end) { |
2232 | ret = -1; | |
2233 | BT_LOGD_STR("Cannot retrieve intersection-range-ns \'end\' field from query result."); | |
2234 | goto error; | |
2235 | } | |
2236 | ||
68d9d039 PP |
2237 | begin = bt_value_signed_integer_get(intersection_begin); |
2238 | end = bt_value_signed_integer_get(intersection_end); | |
b5fe3e00 JG |
2239 | |
2240 | if (begin < 0 || end < 0 || end < begin) { | |
2241 | BT_LOGW("Invalid trace stream intersection values: " | |
2242 | "intersection-range-ns:begin=%" PRId64 | |
2243 | ", intersection-range-ns:end=%" PRId64, | |
2244 | begin, end); | |
2245 | ret = -1; | |
2246 | goto error; | |
2247 | } | |
2248 | ||
ce141536 PP |
2249 | stream_infos = bt_value_map_borrow_entry_value_const(trace_info, |
2250 | "streams"); | |
b5fe3e00 JG |
2251 | if (!stream_infos || !bt_value_is_array(stream_infos)) { |
2252 | ret = -1; | |
8f2be485 | 2253 | BT_LOGD_STR("Cannot retrieve stream information from trace in query result."); |
b5fe3e00 JG |
2254 | goto error; |
2255 | } | |
2256 | ||
44514773 | 2257 | stream_count = bt_value_array_get_size(stream_infos); |
b5fe3e00 JG |
2258 | if (stream_count < 0) { |
2259 | ret = -1; | |
2260 | goto error; | |
2261 | } | |
2262 | ||
b5fe3e00 | 2263 | for (stream_idx = 0; stream_idx < stream_count; stream_idx++) { |
ddf49b27 | 2264 | const bt_value *port_name; |
b5fe3e00 JG |
2265 | |
2266 | port_id = g_new0(struct port_id, 1); | |
2267 | if (!port_id) { | |
2268 | ret = -1; | |
2269 | BT_LOGE_STR("Cannot allocate memory for port_id structure."); | |
2270 | goto error; | |
2271 | } | |
2272 | port_id->instance_name = strdup(cfg_comp->instance_name->str); | |
2273 | if (!port_id->instance_name) { | |
2274 | ret = -1; | |
2275 | BT_LOGE_STR("Cannot allocate memory for port_id component instance name."); | |
2276 | goto error; | |
2277 | } | |
2278 | ||
2279 | trace_range = g_new0(struct trace_range, 1); | |
2280 | if (!trace_range) { | |
2281 | ret = -1; | |
2282 | BT_LOGE_STR("Cannot allocate memory for trace_range structure."); | |
2283 | goto error; | |
2284 | } | |
2285 | trace_range->intersection_range_begin_ns = begin; | |
2286 | trace_range->intersection_range_end_ns = end; | |
2287 | ||
ce141536 | 2288 | stream_info = bt_value_array_borrow_element_by_index_const( |
44514773 | 2289 | stream_infos, stream_idx); |
b5fe3e00 JG |
2290 | if (!stream_info || !bt_value_is_map(stream_info)) { |
2291 | ret = -1; | |
a684a357 | 2292 | BT_LOGE_STR("Cannot retrieve stream informations from trace in query result."); |
b5fe3e00 JG |
2293 | goto error; |
2294 | } | |
2295 | ||
ddf49b27 SM |
2296 | port_name = bt_value_map_borrow_entry_value_const(stream_info, "port-name"); |
2297 | if (!port_name || !bt_value_is_string(port_name)) { | |
b5fe3e00 | 2298 | ret = -1; |
a684a357 | 2299 | BT_LOGE_STR("Cannot retrieve port name in query result."); |
b5fe3e00 JG |
2300 | goto error; |
2301 | } | |
2302 | ||
ddf49b27 | 2303 | port_id->port_name = g_strdup(bt_value_string_get(port_name)); |
b5fe3e00 JG |
2304 | if (!port_id->port_name) { |
2305 | ret = -1; | |
2306 | BT_LOGE_STR("Cannot allocate memory for port_id port_name."); | |
2307 | goto error; | |
2308 | } | |
2309 | ||
2310 | BT_LOGD("Inserting stream intersection "); | |
2311 | ||
eea1eb1a | 2312 | g_hash_table_insert(ctx->intersections, port_id, trace_range); |
b5fe3e00 JG |
2313 | |
2314 | port_id = NULL; | |
2315 | trace_range = NULL; | |
b5fe3e00 | 2316 | } |
b5fe3e00 JG |
2317 | } |
2318 | ||
2319 | goto end; | |
2320 | ||
2321 | error: | |
2322 | fprintf(stderr, "%s%sCannot determine stream intersection of trace at path \'%s\'.%s\n", | |
2323 | bt_common_color_bold(), | |
2324 | bt_common_color_fg_yellow(), | |
2325 | path ? path : "(unknown)", | |
2326 | bt_common_color_reset()); | |
2327 | end: | |
8c6884d9 | 2328 | bt_value_put_ref(query_result); |
b5fe3e00 JG |
2329 | g_free(port_id); |
2330 | g_free(trace_range); | |
2331 | return ret; | |
2332 | } | |
2333 | ||
9009cc24 PP |
2334 | static |
2335 | int cmd_run_ctx_create_components_from_config_components( | |
2336 | struct cmd_run_ctx *ctx, GPtrArray *cfg_components) | |
2337 | { | |
2338 | size_t i; | |
7b53201c PP |
2339 | const void *comp_cls = NULL; |
2340 | const void *comp = NULL; | |
9009cc24 PP |
2341 | int ret = 0; |
2342 | ||
2343 | for (i = 0; i < cfg_components->len; i++) { | |
2344 | struct bt_config_component *cfg_comp = | |
2345 | g_ptr_array_index(cfg_components, i); | |
2346 | GQuark quark; | |
2347 | ||
834e9996 PP |
2348 | switch (cfg_comp->type) { |
2349 | case BT_COMPONENT_CLASS_TYPE_SOURCE: | |
2350 | comp_cls = find_source_component_class( | |
2351 | cfg_comp->plugin_name->str, | |
2352 | cfg_comp->comp_cls_name->str); | |
2353 | break; | |
2354 | case BT_COMPONENT_CLASS_TYPE_FILTER: | |
2355 | comp_cls = find_filter_component_class( | |
2356 | cfg_comp->plugin_name->str, | |
2357 | cfg_comp->comp_cls_name->str); | |
2358 | break; | |
2359 | case BT_COMPONENT_CLASS_TYPE_SINK: | |
2360 | comp_cls = find_sink_component_class( | |
2361 | cfg_comp->plugin_name->str, | |
2362 | cfg_comp->comp_cls_name->str); | |
2363 | break; | |
2364 | default: | |
2365 | abort(); | |
2366 | } | |
2367 | ||
9009cc24 | 2368 | if (!comp_cls) { |
7213a328 PP |
2369 | BT_LOGE("Cannot find component class: plugin-name=\"%s\", " |
2370 | "comp-cls-name=\"%s\", comp-cls-type=%d", | |
2371 | cfg_comp->plugin_name->str, | |
2372 | cfg_comp->comp_cls_name->str, | |
2373 | cfg_comp->type); | |
9009cc24 PP |
2374 | fprintf(stderr, "%s%sCannot find component class %s", |
2375 | bt_common_color_bold(), | |
2376 | bt_common_color_fg_red(), | |
2377 | bt_common_color_reset()); | |
2378 | print_plugin_comp_cls_opt(stderr, | |
2379 | cfg_comp->plugin_name->str, | |
2380 | cfg_comp->comp_cls_name->str, | |
2381 | cfg_comp->type); | |
2382 | fprintf(stderr, "\n"); | |
2383 | goto error; | |
2384 | } | |
2385 | ||
c4f81dc9 PP |
2386 | BT_ASSERT(cfg_comp->log_level >= BT_LOG_VERBOSE); |
2387 | ||
834e9996 PP |
2388 | switch (cfg_comp->type) { |
2389 | case BT_COMPONENT_CLASS_TYPE_SOURCE: | |
7b53201c | 2390 | ret = bt_graph_add_source_component(ctx->graph, |
834e9996 | 2391 | comp_cls, cfg_comp->instance_name->str, |
c4f81dc9 | 2392 | cfg_comp->params, cfg_comp->log_level, |
834e9996 PP |
2393 | (void *) &comp); |
2394 | break; | |
2395 | case BT_COMPONENT_CLASS_TYPE_FILTER: | |
7b53201c | 2396 | ret = bt_graph_add_filter_component(ctx->graph, |
834e9996 | 2397 | comp_cls, cfg_comp->instance_name->str, |
c4f81dc9 | 2398 | cfg_comp->params, cfg_comp->log_level, |
834e9996 PP |
2399 | (void *) &comp); |
2400 | break; | |
2401 | case BT_COMPONENT_CLASS_TYPE_SINK: | |
7b53201c | 2402 | ret = bt_graph_add_sink_component(ctx->graph, |
834e9996 | 2403 | comp_cls, cfg_comp->instance_name->str, |
c4f81dc9 | 2404 | cfg_comp->params, cfg_comp->log_level, |
834e9996 PP |
2405 | (void *) &comp); |
2406 | break; | |
2407 | default: | |
2408 | abort(); | |
2409 | } | |
2410 | ||
36712f1d | 2411 | if (ret) { |
7213a328 | 2412 | BT_LOGE("Cannot create component: plugin-name=\"%s\", " |
32e87ceb | 2413 | "comp-cls-name=\"%s\", comp-cls-type=%d, " |
7213a328 PP |
2414 | "comp-name=\"%s\"", |
2415 | cfg_comp->plugin_name->str, | |
2416 | cfg_comp->comp_cls_name->str, | |
2417 | cfg_comp->type, cfg_comp->instance_name->str); | |
9009cc24 PP |
2418 | fprintf(stderr, "%s%sCannot create component `%s`%s\n", |
2419 | bt_common_color_bold(), | |
2420 | bt_common_color_fg_red(), | |
2421 | cfg_comp->instance_name->str, | |
2422 | bt_common_color_reset()); | |
2423 | goto error; | |
2424 | } | |
2425 | ||
b5fe3e00 JG |
2426 | if (ctx->stream_intersection_mode && |
2427 | cfg_comp->type == BT_COMPONENT_CLASS_TYPE_SOURCE) { | |
2428 | ret = set_stream_intersections(ctx, cfg_comp, comp_cls); | |
2429 | if (ret) { | |
2430 | goto error; | |
2431 | } | |
2432 | } | |
2433 | ||
7213a328 PP |
2434 | BT_LOGI("Created and inserted component: comp-addr=%p, comp-name=\"%s\"", |
2435 | comp, cfg_comp->instance_name->str); | |
9009cc24 | 2436 | quark = g_quark_from_string(cfg_comp->instance_name->str); |
8b45963b | 2437 | BT_ASSERT(quark > 0); |
834e9996 PP |
2438 | |
2439 | switch (cfg_comp->type) { | |
2440 | case BT_COMPONENT_CLASS_TYPE_SOURCE: | |
2441 | g_hash_table_insert(ctx->src_components, | |
7b53201c | 2442 | GUINT_TO_POINTER(quark), (void *) comp); |
834e9996 PP |
2443 | break; |
2444 | case BT_COMPONENT_CLASS_TYPE_FILTER: | |
2445 | g_hash_table_insert(ctx->flt_components, | |
7b53201c | 2446 | GUINT_TO_POINTER(quark), (void *) comp); |
834e9996 PP |
2447 | break; |
2448 | case BT_COMPONENT_CLASS_TYPE_SINK: | |
2449 | g_hash_table_insert(ctx->sink_components, | |
7b53201c | 2450 | GUINT_TO_POINTER(quark), (void *) comp); |
834e9996 PP |
2451 | break; |
2452 | default: | |
2453 | abort(); | |
2454 | } | |
2455 | ||
9009cc24 | 2456 | comp = NULL; |
8138bfe1 | 2457 | BT_OBJECT_PUT_REF_AND_RESET(comp_cls); |
9009cc24 PP |
2458 | } |
2459 | ||
2460 | goto end; | |
2461 | ||
2462 | error: | |
2463 | ret = -1; | |
2464 | ||
2465 | end: | |
8138bfe1 PP |
2466 | bt_object_put_ref(comp); |
2467 | bt_object_put_ref(comp_cls); | |
9009cc24 PP |
2468 | return ret; |
2469 | } | |
56a1cced | 2470 | |
9009cc24 PP |
2471 | static |
2472 | int cmd_run_ctx_create_components(struct cmd_run_ctx *ctx) | |
2473 | { | |
2474 | int ret = 0; | |
2475 | ||
2476 | /* | |
2477 | * Make sure that, during this phase, our graph's "port added" | |
2478 | * listener does not connect ports while we are creating the | |
2479 | * components because we have a special, initial phase for | |
2480 | * this. | |
2481 | */ | |
2482 | ctx->connect_ports = false; | |
2483 | ||
2484 | ret = cmd_run_ctx_create_components_from_config_components( | |
2485 | ctx, ctx->cfg->cmd_data.run.sources); | |
2486 | if (ret) { | |
7c7c0433 | 2487 | ret = -1; |
2e339de1 JG |
2488 | goto end; |
2489 | } | |
2490 | ||
9009cc24 PP |
2491 | ret = cmd_run_ctx_create_components_from_config_components( |
2492 | ctx, ctx->cfg->cmd_data.run.filters); | |
6c2f3ee5 | 2493 | if (ret) { |
290725f7 | 2494 | ret = -1; |
fec2a9f2 JG |
2495 | goto end; |
2496 | } | |
78586d8a | 2497 | |
9009cc24 PP |
2498 | ret = cmd_run_ctx_create_components_from_config_components( |
2499 | ctx, ctx->cfg->cmd_data.run.sinks); | |
2500 | if (ret) { | |
2501 | ret = -1; | |
2502 | goto end; | |
2503 | } | |
2504 | ||
2505 | end: | |
2506 | return ret; | |
2507 | } | |
2508 | ||
7b53201c | 2509 | typedef uint64_t (*output_port_count_func_t)(const void *); |
8eee8ea2 | 2510 | typedef const bt_port_output *(*borrow_output_port_by_index_func_t)( |
7b53201c | 2511 | const void *, uint64_t); |
834e9996 | 2512 | |
9009cc24 PP |
2513 | static |
2514 | int cmd_run_ctx_connect_comp_ports(struct cmd_run_ctx *ctx, | |
834e9996 PP |
2515 | void *comp, output_port_count_func_t port_count_fn, |
2516 | borrow_output_port_by_index_func_t port_by_index_fn) | |
9009cc24 PP |
2517 | { |
2518 | int ret = 0; | |
834e9996 | 2519 | uint64_t count; |
9009cc24 PP |
2520 | uint64_t i; |
2521 | ||
2522 | count = port_count_fn(comp); | |
9009cc24 PP |
2523 | |
2524 | for (i = 0; i < count; i++) { | |
8eee8ea2 | 2525 | const bt_port_output *upstream_port = port_by_index_fn(comp, i); |
9009cc24 | 2526 | |
8b45963b | 2527 | BT_ASSERT(upstream_port); |
9009cc24 | 2528 | ret = cmd_run_ctx_connect_upstream_port(ctx, upstream_port); |
9009cc24 PP |
2529 | if (ret) { |
2530 | goto end; | |
2531 | } | |
2532 | } | |
2533 | ||
2534 | end: | |
2535 | return ret; | |
2536 | } | |
2537 | ||
2538 | static | |
2539 | int cmd_run_ctx_connect_ports(struct cmd_run_ctx *ctx) | |
2540 | { | |
2541 | int ret = 0; | |
2542 | GHashTableIter iter; | |
2543 | gpointer g_name_quark, g_comp; | |
2544 | ||
2545 | ctx->connect_ports = true; | |
834e9996 | 2546 | g_hash_table_iter_init(&iter, ctx->src_components); |
9009cc24 PP |
2547 | |
2548 | while (g_hash_table_iter_next(&iter, &g_name_quark, &g_comp)) { | |
834e9996 PP |
2549 | ret = cmd_run_ctx_connect_comp_ports(ctx, g_comp, |
2550 | (output_port_count_func_t) | |
2551 | bt_component_source_get_output_port_count, | |
2552 | (borrow_output_port_by_index_func_t) | |
7b53201c | 2553 | bt_component_source_borrow_output_port_by_index_const); |
834e9996 PP |
2554 | if (ret) { |
2555 | goto end; | |
9009cc24 | 2556 | } |
834e9996 PP |
2557 | } |
2558 | ||
2559 | g_hash_table_iter_init(&iter, ctx->flt_components); | |
9009cc24 | 2560 | |
834e9996 PP |
2561 | while (g_hash_table_iter_next(&iter, &g_name_quark, &g_comp)) { |
2562 | ret = cmd_run_ctx_connect_comp_ports(ctx, g_comp, | |
2563 | (output_port_count_func_t) | |
2564 | bt_component_filter_get_output_port_count, | |
2565 | (borrow_output_port_by_index_func_t) | |
7b53201c | 2566 | bt_component_filter_borrow_output_port_by_index_const); |
9009cc24 PP |
2567 | if (ret) { |
2568 | goto end; | |
2569 | } | |
2570 | } | |
2571 | ||
2572 | end: | |
2573 | return ret; | |
2574 | } | |
2575 | ||
fd948396 | 2576 | static inline |
ee78f405 | 2577 | const char *bt_graph_status_str(bt_graph_status status) |
fd948396 PP |
2578 | { |
2579 | switch (status) { | |
fd948396 PP |
2580 | case BT_GRAPH_STATUS_OK: |
2581 | return "BT_GRAPH_STATUS_OK"; | |
834e9996 PP |
2582 | case BT_GRAPH_STATUS_END: |
2583 | return "BT_GRAPH_STATUS_END"; | |
2584 | case BT_GRAPH_STATUS_AGAIN: | |
2585 | return "BT_GRAPH_STATUS_AGAIN"; | |
2586 | case BT_GRAPH_STATUS_COMPONENT_REFUSES_PORT_CONNECTION: | |
2587 | return "BT_GRAPH_STATUS_COMPONENT_REFUSES_PORT_CONNECTION"; | |
2588 | case BT_GRAPH_STATUS_CANCELED: | |
2589 | return "BT_GRAPH_STATUS_CANCELED"; | |
fd948396 PP |
2590 | case BT_GRAPH_STATUS_ERROR: |
2591 | return "BT_GRAPH_STATUS_ERROR"; | |
834e9996 PP |
2592 | case BT_GRAPH_STATUS_NOMEM: |
2593 | return "BT_GRAPH_STATUS_NOMEM"; | |
fd948396 PP |
2594 | default: |
2595 | return "(unknown)"; | |
2596 | } | |
2597 | } | |
2598 | ||
9009cc24 PP |
2599 | static |
2600 | int cmd_run(struct bt_config *cfg) | |
2601 | { | |
2602 | int ret = 0; | |
2603 | struct cmd_run_ctx ctx = { 0 }; | |
2604 | ||
9009cc24 PP |
2605 | /* Initialize the command's context and the graph object */ |
2606 | if (cmd_run_ctx_init(&ctx, cfg)) { | |
7213a328 | 2607 | BT_LOGE_STR("Cannot initialize the command's context."); |
9009cc24 PP |
2608 | fprintf(stderr, "Cannot initialize the command's context\n"); |
2609 | goto error; | |
2610 | } | |
2611 | ||
cc308374 PP |
2612 | if (canceled) { |
2613 | BT_LOGI_STR("Canceled by user before creating components."); | |
2614 | goto error; | |
2615 | } | |
2616 | ||
2617 | BT_LOGI_STR("Creating components."); | |
2618 | ||
9009cc24 PP |
2619 | /* Create the requested component instances */ |
2620 | if (cmd_run_ctx_create_components(&ctx)) { | |
7213a328 | 2621 | BT_LOGE_STR("Cannot create components."); |
9009cc24 PP |
2622 | fprintf(stderr, "Cannot create components\n"); |
2623 | goto error; | |
2624 | } | |
2625 | ||
cc308374 PP |
2626 | if (canceled) { |
2627 | BT_LOGI_STR("Canceled by user before connecting components."); | |
2628 | goto error; | |
2629 | } | |
2630 | ||
2631 | BT_LOGI_STR("Connecting components."); | |
2632 | ||
9009cc24 PP |
2633 | /* Connect the initially visible component ports */ |
2634 | if (cmd_run_ctx_connect_ports(&ctx)) { | |
7213a328 | 2635 | BT_LOGE_STR("Cannot connect initial component ports."); |
9009cc24 PP |
2636 | fprintf(stderr, "Cannot connect initial component ports\n"); |
2637 | goto error; | |
2638 | } | |
2639 | ||
5401f780 | 2640 | if (canceled) { |
cc308374 PP |
2641 | BT_LOGI_STR("Canceled by user before running the graph."); |
2642 | goto error; | |
5401f780 PP |
2643 | } |
2644 | ||
7213a328 PP |
2645 | BT_LOGI_STR("Running the graph."); |
2646 | ||
9009cc24 | 2647 | /* Run the graph */ |
fec2a9f2 | 2648 | while (true) { |
ee78f405 | 2649 | bt_graph_status graph_status = bt_graph_run(ctx.graph); |
61ddbc8a | 2650 | |
5669a3e7 PP |
2651 | /* |
2652 | * Reset console in case something messed with console | |
2653 | * codes during the graph's execution. | |
2654 | */ | |
2655 | printf("%s", bt_common_color_reset()); | |
2656 | fflush(stdout); | |
2657 | fprintf(stderr, "%s", bt_common_color_reset()); | |
7b53201c | 2658 | BT_LOGV("bt_graph_run() returned: status=%s", |
fd948396 PP |
2659 | bt_graph_status_str(graph_status)); |
2660 | ||
61ddbc8a | 2661 | switch (graph_status) { |
9009cc24 PP |
2662 | case BT_GRAPH_STATUS_OK: |
2663 | break; | |
5401f780 | 2664 | case BT_GRAPH_STATUS_CANCELED: |
fd948396 | 2665 | BT_LOGI_STR("Graph was canceled by user."); |
5401f780 | 2666 | goto error; |
61ddbc8a | 2667 | case BT_GRAPH_STATUS_AGAIN: |
7b53201c | 2668 | if (bt_graph_is_canceled(ctx.graph)) { |
fd948396 | 2669 | BT_LOGI_STR("Graph was canceled by user."); |
5401f780 PP |
2670 | goto error; |
2671 | } | |
2672 | ||
9009cc24 | 2673 | if (cfg->cmd_data.run.retry_duration_us > 0) { |
7213a328 PP |
2674 | BT_LOGV("Got BT_GRAPH_STATUS_AGAIN: sleeping: " |
2675 | "time-us=%" PRIu64, | |
2676 | cfg->cmd_data.run.retry_duration_us); | |
2677 | ||
9009cc24 | 2678 | if (usleep(cfg->cmd_data.run.retry_duration_us)) { |
7b53201c | 2679 | if (bt_graph_is_canceled(ctx.graph)) { |
cfa4637b PP |
2680 | BT_LOGI_STR("Graph was canceled by user."); |
2681 | goto error; | |
2682 | } | |
9009cc24 PP |
2683 | } |
2684 | } | |
78586d8a | 2685 | break; |
834e9996 | 2686 | case BT_GRAPH_STATUS_END: |
fec2a9f2 JG |
2687 | goto end; |
2688 | default: | |
7213a328 PP |
2689 | BT_LOGE_STR("Graph failed to complete successfully"); |
2690 | fprintf(stderr, "Graph failed to complete successfully\n"); | |
9009cc24 | 2691 | goto error; |
78586d8a | 2692 | } |
fec2a9f2 | 2693 | } |
290725f7 | 2694 | |
9009cc24 PP |
2695 | goto end; |
2696 | ||
2697 | error: | |
2698 | if (ret == 0) { | |
2699 | ret = -1; | |
2700 | } | |
2701 | ||
11e1d048 | 2702 | end: |
9009cc24 | 2703 | cmd_run_ctx_destroy(&ctx); |
290725f7 PP |
2704 | return ret; |
2705 | } | |
2706 | ||
9009cc24 PP |
2707 | static |
2708 | void warn_command_name_and_directory_clash(struct bt_config *cfg) | |
290725f7 | 2709 | { |
9009cc24 PP |
2710 | const char *env_clash; |
2711 | ||
290725f7 PP |
2712 | if (!cfg->command_name) { |
2713 | return; | |
2714 | } | |
2715 | ||
9009cc24 PP |
2716 | env_clash = getenv(ENV_BABELTRACE_WARN_COMMAND_NAME_DIRECTORY_CLASH); |
2717 | if (env_clash && strcmp(env_clash, "0") == 0) { | |
2718 | return; | |
2719 | } | |
2720 | ||
290725f7 PP |
2721 | if (g_file_test(cfg->command_name, |
2722 | G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { | |
2723 | fprintf(stderr, "\nNOTE: The `%s` command was executed. If you meant to convert a\n", | |
2724 | cfg->command_name); | |
2725 | fprintf(stderr, "trace located in the local `%s` directory, please use:\n", | |
2726 | cfg->command_name); | |
2727 | fprintf(stderr, "\n"); | |
142ac9b0 | 2728 | fprintf(stderr, " babeltrace2 convert %s [OPTIONS]\n", |
290725f7 PP |
2729 | cfg->command_name); |
2730 | } | |
2731 | } | |
2732 | ||
7213a328 PP |
2733 | static |
2734 | void init_log_level(void) | |
2735 | { | |
c6d4d1ae | 2736 | bt_cli_log_level = bt_log_get_level_from_env(ENV_BABELTRACE_CLI_LOG_LEVEL); |
7213a328 PP |
2737 | } |
2738 | ||
c6d4d1ae PP |
2739 | static |
2740 | void set_auto_log_levels(struct bt_config *cfg) | |
2741 | { | |
2742 | const char **env_var_name; | |
2743 | ||
f4f9e43b PP |
2744 | /* |
2745 | * Override the configuration's default log level if | |
2746 | * BABELTRACE_VERBOSE or BABELTRACE_DEBUG environment variables | |
2747 | * are found for backward compatibility with legacy Babetrace 1. | |
2748 | */ | |
2749 | if (getenv("BABELTRACE_DEBUG") && | |
2750 | strcmp(getenv("BABELTRACE_DEBUG"), "1") == 0) { | |
8a46ff40 | 2751 | cfg->log_level = BT_LOG_VERBOSE; |
f4f9e43b PP |
2752 | } else if (getenv("BABELTRACE_VERBOSE") && |
2753 | strcmp(getenv("BABELTRACE_VERBOSE"), "1") == 0) { | |
8a46ff40 | 2754 | cfg->log_level = BT_LOG_INFO; |
f4f9e43b PP |
2755 | } |
2756 | ||
c6d4d1ae PP |
2757 | /* |
2758 | * Set log levels according to --debug or --verbose. For | |
2759 | * backward compatibility, --debug is more verbose than | |
2760 | * --verbose. So: | |
2761 | * | |
2762 | * --verbose: INFO log level | |
2763 | * --debug: VERBOSE log level (includes DEBUG, which is | |
2764 | * is less verbose than VERBOSE in the internal | |
2765 | * logging framework) | |
2766 | */ | |
2767 | if (!getenv("BABELTRACE_LOGGING_GLOBAL_LEVEL")) { | |
2768 | if (cfg->verbose) { | |
8a46ff40 | 2769 | bt_logging_set_global_level(BT_LOG_INFO); |
c6d4d1ae | 2770 | } else if (cfg->debug) { |
8a46ff40 | 2771 | bt_logging_set_global_level(BT_LOG_VERBOSE); |
c6d4d1ae PP |
2772 | } else { |
2773 | /* | |
2774 | * Set library's default log level if not | |
2775 | * explicitly specified. | |
2776 | */ | |
8a46ff40 | 2777 | bt_logging_set_global_level(cfg->log_level); |
c6d4d1ae PP |
2778 | } |
2779 | } | |
2780 | ||
2781 | if (!getenv(ENV_BABELTRACE_CLI_LOG_LEVEL)) { | |
2782 | if (cfg->verbose) { | |
2783 | bt_cli_log_level = BT_LOG_INFO; | |
2784 | } else if (cfg->debug) { | |
2785 | bt_cli_log_level = BT_LOG_VERBOSE; | |
2786 | } else { | |
2787 | /* | |
2788 | * Set CLI's default log level if not explicitly | |
2789 | * specified. | |
2790 | */ | |
8a46ff40 | 2791 | bt_cli_log_level = cfg->log_level; |
c6d4d1ae PP |
2792 | } |
2793 | } | |
2794 | ||
2795 | env_var_name = log_level_env_var_names; | |
2796 | ||
2797 | while (*env_var_name) { | |
2798 | if (!getenv(*env_var_name)) { | |
2799 | if (cfg->verbose) { | |
9be5a6e6 | 2800 | g_setenv(*env_var_name, "I", 1); |
c6d4d1ae | 2801 | } else if (cfg->debug) { |
9be5a6e6 | 2802 | g_setenv(*env_var_name, "V", 1); |
c6d4d1ae | 2803 | } else { |
9e503aa9 PP |
2804 | char val[2] = { 0 }; |
2805 | ||
c6d4d1ae PP |
2806 | /* |
2807 | * Set module's default log level if not | |
2808 | * explicitly specified. | |
2809 | */ | |
8a46ff40 PP |
2810 | val[0] = bt_log_get_letter_from_level( |
2811 | cfg->log_level); | |
9be5a6e6 | 2812 | g_setenv(*env_var_name, val, 1); |
c6d4d1ae PP |
2813 | } |
2814 | } | |
2815 | ||
2816 | env_var_name++; | |
2817 | } | |
c6d4d1ae PP |
2818 | } |
2819 | ||
290725f7 PP |
2820 | int main(int argc, const char **argv) |
2821 | { | |
2822 | int ret; | |
2823 | int retcode; | |
2824 | struct bt_config *cfg; | |
2825 | ||
7213a328 | 2826 | init_log_level(); |
3265acbc | 2827 | set_signal_handler(); |
9009cc24 PP |
2828 | init_static_data(); |
2829 | cfg = bt_config_cli_args_create_with_default(argc, argv, &retcode); | |
290725f7 PP |
2830 | |
2831 | if (retcode < 0) { | |
2832 | /* Quit without errors; typically usage/version */ | |
2833 | retcode = 0; | |
7213a328 | 2834 | BT_LOGI_STR("Quitting without errors."); |
290725f7 PP |
2835 | goto end; |
2836 | } | |
2837 | ||
2838 | if (retcode > 0) { | |
7213a328 | 2839 | BT_LOGE("Command-line error: retcode=%d", retcode); |
290725f7 PP |
2840 | goto end; |
2841 | } | |
2842 | ||
2843 | if (!cfg) { | |
7213a328 | 2844 | BT_LOGE_STR("Failed to create a valid Babeltrace configuration."); |
290725f7 | 2845 | fprintf(stderr, "Failed to create Babeltrace configuration\n"); |
db0f160a | 2846 | retcode = 1; |
290725f7 PP |
2847 | goto end; |
2848 | } | |
2849 | ||
c6d4d1ae | 2850 | set_auto_log_levels(cfg); |
290725f7 PP |
2851 | print_cfg(cfg); |
2852 | ||
db0f160a | 2853 | if (cfg->command_needs_plugins) { |
ce141536 | 2854 | ret = load_all_plugins(cfg->plugin_paths); |
db0f160a | 2855 | if (ret) { |
7213a328 | 2856 | BT_LOGE("Failed to load plugins: ret=%d", ret); |
db0f160a PP |
2857 | retcode = 1; |
2858 | goto end; | |
2859 | } | |
2860 | } | |
2861 | ||
7213a328 PP |
2862 | BT_LOGI("Executing command: cmd=%d, command-name=\"%s\"", |
2863 | cfg->command, cfg->command_name); | |
2864 | ||
290725f7 | 2865 | switch (cfg->command) { |
db0f160a PP |
2866 | case BT_CONFIG_COMMAND_RUN: |
2867 | ret = cmd_run(cfg); | |
290725f7 PP |
2868 | break; |
2869 | case BT_CONFIG_COMMAND_LIST_PLUGINS: | |
2870 | ret = cmd_list_plugins(cfg); | |
2871 | break; | |
22e22462 PP |
2872 | case BT_CONFIG_COMMAND_HELP: |
2873 | ret = cmd_help(cfg); | |
2874 | break; | |
a67681c1 PP |
2875 | case BT_CONFIG_COMMAND_QUERY: |
2876 | ret = cmd_query(cfg); | |
63ce0e1d | 2877 | break; |
db0f160a PP |
2878 | case BT_CONFIG_COMMAND_PRINT_CTF_METADATA: |
2879 | ret = cmd_print_ctf_metadata(cfg); | |
2880 | break; | |
2881 | case BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS: | |
2882 | ret = cmd_print_lttng_live_sessions(cfg); | |
2883 | break; | |
290725f7 | 2884 | default: |
0fbb9a9f PP |
2885 | BT_LOGF("Invalid/unknown command: cmd=%d", cfg->command); |
2886 | abort(); | |
290725f7 PP |
2887 | } |
2888 | ||
d26ef3e3 PP |
2889 | BT_LOGI("Command completed: cmd=%d, command-name=\"%s\", ret=%d", |
2890 | cfg->command, cfg->command_name, ret); | |
290725f7 PP |
2891 | warn_command_name_and_directory_clash(cfg); |
2892 | retcode = ret ? 1 : 0; | |
2893 | ||
2894 | end: | |
8138bfe1 | 2895 | BT_OBJECT_PUT_REF_AND_RESET(cfg); |
9009cc24 | 2896 | fini_static_data(); |
290725f7 | 2897 | return retcode; |
4c8bfb7e | 2898 | } |