cli: support --output opt. for -o ctf-metadata and -i lttng-live
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 7 Nov 2017 19:57:32 +0000 (14:57 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 8 Nov 2017 15:44:51 +0000 (10:44 -0500)
Babeltrace 1 supports the -w/--output option to print the metadata text
or the available LTTng live sessions to a file instead of the standard
output.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
cli/babeltrace-cfg-cli-args.c
cli/babeltrace-cfg.h
cli/babeltrace.c
doc/man/babeltrace-convert.1.txt

index da60680a091dd2dc906cf21c1e6c501204c252e7..8f01e64b60be196574afef220677de77a2f69db2 100644 (file)
@@ -909,6 +909,9 @@ void bt_config_destroy(struct bt_object *obj)
                if (cfg->cmd_data.print_ctf_metadata.path) {
                        g_string_free(cfg->cmd_data.print_ctf_metadata.path,
                                TRUE);
+                       g_string_free(
+                               cfg->cmd_data.print_ctf_metadata.output_path,
+                               TRUE);
                }
                break;
        case BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS:
@@ -916,6 +919,9 @@ void bt_config_destroy(struct bt_object *obj)
                        g_string_free(
                                cfg->cmd_data.print_lttng_live_sessions.url,
                                TRUE);
+                       g_string_free(
+                               cfg->cmd_data.print_lttng_live_sessions.output_path,
+                               TRUE);
                }
                break;
        default:
@@ -1659,6 +1665,12 @@ struct bt_config *bt_config_print_ctf_metadata_create(
                goto error;
        }
 
+       cfg->cmd_data.print_ctf_metadata.output_path = g_string_new(NULL);
+       if (!cfg->cmd_data.print_ctf_metadata.output_path) {
+               print_err_oom();
+               goto error;
+       }
+
        goto end;
 
 error:
@@ -1687,6 +1699,13 @@ struct bt_config *bt_config_print_lttng_live_sessions_create(
                goto error;
        }
 
+       cfg->cmd_data.print_lttng_live_sessions.output_path =
+               g_string_new(NULL);
+       if (!cfg->cmd_data.print_lttng_live_sessions.output_path) {
+               print_err_oom();
+               goto error;
+       }
+
        goto end;
 
 error:
@@ -4319,6 +4338,13 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                gs_leftover = leftovers->data;
                g_string_assign(cfg->cmd_data.print_ctf_metadata.path,
                        gs_leftover->str);
+
+               if (output) {
+                       g_string_assign(
+                               cfg->cmd_data.print_ctf_metadata.output_path,
+                               output);
+               }
+
                goto end;
        }
 
@@ -4406,6 +4432,13 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
 
                                g_string_assign(cfg->cmd_data.print_lttng_live_sessions.url,
                                        gs_leftover->str);
+
+                               if (output) {
+                                       g_string_assign(
+                                               cfg->cmd_data.print_lttng_live_sessions.output_path,
+                                               output);
+                               }
+
                                goto end;
                        }
 
index 89065244352a1e4a8c1f35f6a6f185840f6f40d4..864f3daff1514a8db894b13c81010abf9bcc3cd5 100644 (file)
@@ -114,11 +114,13 @@ struct bt_config {
                /* BT_CONFIG_COMMAND_PRINT_CTF_METADATA */
                struct {
                        GString *path;
+                       GString *output_path;
                } print_ctf_metadata;
 
                /* BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS */
                struct {
                        GString *url;
+                       GString *output_path;
                } print_lttng_live_sessions;
        } cmd_data;
 };
index 56e32714710c68e524e855d5dcb56349c93bda85..23e377100b70d52d3d25259e529cb3f87033baec 100644 (file)
@@ -1156,6 +1156,7 @@ int cmd_print_lttng_live_sessions(struct bt_config *cfg)
                BT_COMPONENT_CLASS_TYPE_SOURCE;
        int64_t array_size, i;
        const char *fail_reason = NULL;
+       FILE *out_stream = stdout;
 
        assert(cfg->cmd_data.print_lttng_live_sessions.url);
        comp_cls = find_component_class(plugin_name, comp_cls_name,
@@ -1200,6 +1201,19 @@ int cmd_print_lttng_live_sessions(struct bt_config *cfg)
                goto error;
        }
 
+       if (cfg->cmd_data.print_lttng_live_sessions.output_path->len > 0) {
+               out_stream =
+                       fopen(cfg->cmd_data.print_lttng_live_sessions.output_path->str,
+                               "w");
+               if (!out_stream) {
+                       ret = -1;
+                       BT_LOGE_ERRNO("Cannot open file for writing",
+                               ": path=\"%s\"",
+                               cfg->cmd_data.print_lttng_live_sessions.output_path->str);
+                       goto end;
+               }
+       }
+
        array_size = bt_value_array_size(results);
        for (i = 0; i < array_size; i++) {
                const char *url_text;
@@ -1222,7 +1236,7 @@ int cmd_print_lttng_live_sessions(struct bt_config *cfg)
                }
                ret = bt_value_string_get(v, &url_text);
                assert(ret == 0);
-               printf("%s", url_text);
+               fprintf(out_stream, "%s", url_text);
                BT_PUT(v);
 
                v = bt_value_map_get(map, "timer-us");
@@ -1232,7 +1246,7 @@ int cmd_print_lttng_live_sessions(struct bt_config *cfg)
                }
                ret = bt_value_integer_get(v, &timer_us);
                assert(ret == 0);
-               printf(" (timer = %" PRIu64 ", ", timer_us);
+               fprintf(out_stream, " (timer = %" PRIu64 ", ", timer_us);
                BT_PUT(v);
 
                v = bt_value_map_get(map, "stream-count");
@@ -1242,7 +1256,7 @@ int cmd_print_lttng_live_sessions(struct bt_config *cfg)
                }
                ret = bt_value_integer_get(v, &streams);
                assert(ret == 0);
-               printf("%" PRIu64 " stream(s), ", streams);
+               fprintf(out_stream, "%" PRIu64 " stream(s), ", streams);
                BT_PUT(v);
 
                v = bt_value_map_get(map, "client-count");
@@ -1252,7 +1266,7 @@ int cmd_print_lttng_live_sessions(struct bt_config *cfg)
                }
                ret = bt_value_integer_get(v, &clients);
                assert(ret == 0);
-               printf("%" PRIu64 " client(s) connected)\n", clients);
+               fprintf(out_stream, "%" PRIu64 " client(s) connected)\n", clients);
                BT_PUT(v);
 
                BT_PUT(map);
@@ -1277,6 +1291,17 @@ end:
        bt_put(results);
        bt_put(params);
        bt_put(comp_cls);
+
+       if (out_stream && out_stream != stdout) {
+               int fclose_ret = fclose(out_stream);
+
+               if (fclose_ret) {
+                       BT_LOGE_ERRNO("Cannot close file stream",
+                               ": path=\"%s\"",
+                               cfg->cmd_data.print_lttng_live_sessions.output_path->str);
+               }
+       }
+
        return 0;
 }
 
@@ -1294,6 +1319,7 @@ int cmd_print_ctf_metadata(struct bt_config *cfg)
        static const enum bt_component_class_type comp_cls_type =
                BT_COMPONENT_CLASS_TYPE_SOURCE;
        const char *fail_reason = NULL;
+       FILE *out_stream = stdout;
 
        assert(cfg->cmd_data.print_ctf_metadata.path);
        comp_cls = find_component_class(plugin_name, comp_cls_name,
@@ -1341,7 +1367,26 @@ int cmd_print_ctf_metadata(struct bt_config *cfg)
 
        ret = bt_value_string_get(metadata_text_value, &metadata_text);
        assert(ret == 0);
-       printf("%s\n", metadata_text);
+
+       if (cfg->cmd_data.print_ctf_metadata.output_path->len > 0) {
+               out_stream =
+                       fopen(cfg->cmd_data.print_ctf_metadata.output_path->str,
+                               "w");
+               if (!out_stream) {
+                       ret = -1;
+                       BT_LOGE_ERRNO("Cannot open file for writing",
+                               ": path=\"%s\"",
+                               cfg->cmd_data.print_ctf_metadata.output_path->str);
+                       goto end;
+               }
+       }
+
+       ret = fprintf(out_stream, "%s\n", metadata_text);
+       if (ret < 0) {
+               BT_LOGE("Cannot write whole metadata text to output stream: "
+                       "ret=%d", ret);
+       }
+
        goto end;
 
 failed:
@@ -1359,6 +1404,17 @@ end:
        bt_put(params);
        bt_put(metadata_text_value);
        bt_put(comp_cls);
+
+       if (out_stream && out_stream != stdout) {
+               int fclose_ret = fclose(out_stream);
+
+               if (fclose_ret) {
+                       BT_LOGE_ERRNO("Cannot close file stream",
+                               ": path=\"%s\"",
+                               cfg->cmd_data.print_ctf_metadata.output_path->str);
+               }
+       }
+
        return 0;
 }
 
index 8f4aff1a776e2861360a150cf542d35a7de48192..03b843bf6ca12bceb26ec62664e4fce3e2b19389 100644 (file)
@@ -26,6 +26,7 @@ Print the metadata text of a CTF trace:
 *babeltrace convert* ['GENERAL OPTIONS'] [opt:--omit-home-plugin-path]
                    [opt:--omit-system-plugin-path]
                    [opt:--plugin-path='PATH'[:__PATH__]...]
+                   [opt:--output='OUTPATH']
                    opt:--output-format=`ctf-metadata` 'TRACE-PATH'
 
 Print the available http://lttng.org/docs/#doc-lttng-live[LTTng live]
@@ -35,7 +36,7 @@ sessions:
 *babeltrace convert* ['GENERAL OPTIONS'] [opt:--omit-home-plugin-path]
                    [opt:--omit-system-plugin-path]
                    [opt:--plugin-path='PATH'[:__PATH__]...]
-                   opt:--input-format=`lttng-live` 'URL'
+                   [opt:--output='OUTPATH'] opt:--input-format=`lttng-live` 'URL'
 
 
 DESCRIPTION
@@ -779,11 +780,16 @@ component does not print the duration since the last event on the line.
 Shared options
 ~~~~~~~~~~~~~~
 opt:-w 'PATH', opt:--output='PATH'::
-    When you specify opt:--output-format=`ctf`, set the
-    manparam:sink.ctf.fs:path initialization parameter of the implicit
-    compcls:sink.ctf.fs component to 'PATH'. Otherwise, create an
-    implicit compcls:sink.text.pretty component and set its
-    manparam:sink.text.pretty:path initialization parameter to 'PATH'.
+    With opt:--output-format=`ctf-metadata` or
+    opt:--input-format=`lttng-live` (when printing the available LTTng
+    live sessions), write the text to the file 'PATH' instead of the
+    standard output.
++
+When you specify opt:--output-format=`ctf`, set the
+manparam:sink.ctf.fs:path initialization parameter of the implicit
+compcls:sink.ctf.fs component to 'PATH'. Otherwise, create an implicit
+compcls:sink.text.pretty component and set its
+manparam:sink.text.pretty:path initialization parameter to 'PATH'.
 +
 See man:babeltrace-sink.ctf.fs(7) and
 man:babeltrace-sink.text.pretty(7) to learn more about those
This page took 0.032128 seconds and 4 git commands to generate.