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