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