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