+++ /dev/null
-babeltrace2-log(1)
-=================
-:manpagetype: program
-:revdate: 5 October 2017
-
-
-NAME
-----
-babeltrace2-log - Convert a Linux kernel ring buffer to a CTF trace
-
-
-SYNOPSIS
---------
-[verse]
-*babeltrace2-log* [opt:--with-timestamps] 'OUTPUT-PATH'
-
-
-DESCRIPTION
------------
-The `babeltrace2-log` tool reads the lines of a Linux kernel ring buffer,
-as printed by the man:dmesg(1) tool, from the standard input stream and
-converts them to a http://diamon.org/ctf/[CTF] trace written to the
-'OUTPUT-PATH' directory.
-
-Usage example:
-
-[role="term"]
-----
-$ dmesg | babeltrace2-log --with-timestamps my-trace
-----
-
-The events of the generated CTF trace are named `string` and contain a
-single payload string field named `str` which contains the corresponding
-ring buffer line.
-
-By default, `babeltrace2-log` does not try to extract the timestamps of
-the kernel ring buffer lines to use them as the created events's
-timestamps. A typical man:dmesg(1) line looks like this:
-
-----
-[87166.510937] PM: Finishing wakeup.
-----
-
-In the last example, the `[87166.510937]` part is a timestamp which
-could be extracted. You can make `babeltrace2-log` extract timestamps
-from lines with the opt:--with-timestamps option.
-
-
-OPTIONS
--------
-opt:-t, opt:--with-timestamps::
- Extract timestamps from the kernel ring buffer lines: set
- the created event's payload's `str` field to the rest of the line,
- excluding any timestamp prefix.
-
-
-ENVIRONMENT VARIABLES
----------------------
-See the environment variables of man:babeltrace2-source.text.dmesg(7),
-man:babeltrace2-filter.utils.muxer(7), and
-man:babeltrace2-sink.ctf.fs(7).
-
-include::common-lib-env.txt[]
-
-include::common-cli-files.txt[]
-
-include::common-cmd-footer.txt[]
-
-
-SEE ALSO
---------
-man:babeltrace2-intro(7),
-man:babeltrace2-source.text.dmesg(7),
-man:babeltrace2-filter.utils.muxer(7),
-man:babeltrace2-sink.ctf.fs(7)
AM_CPPFLAGS += '-DCONFIG_IN_TREE_PROVIDER_DIR="$(abs_top_builddir)/src/python-plugin-provider/.libs"'
endif
-bin_PROGRAMS = babeltrace2.bin babeltrace2-log.bin
-noinst_PROGRAMS = babeltrace2 babeltrace2-log
+bin_PROGRAMS = babeltrace2.bin
+noinst_PROGRAMS = babeltrace2
babeltrace2_bin_SOURCES = \
babeltrace2.c \
babeltrace2_LDFLAGS = $(babeltrace2_bin_LDFLAGS)
babeltrace2_LDADD = $(babeltrace2_bin_LDADD)
babeltrace2_CFLAGS = $(AM_CFLAGS) -DBT_SET_DEFAULT_IN_TREE_CONFIGURATION
-
-# babeltrace2-log rules and config below
-babeltrace2_log_bin_SOURCES = babeltrace2-log.c
-babeltrace2_log_bin_LDADD = \
- $(top_builddir)/src/compat/libcompat.la \
- $(top_builddir)/src/common/libbabeltrace2-common.la \
- $(top_builddir)/src/logging/libbabeltrace2-logging.la \
- $(POPT_LIBS)
-babeltrace2_log_bin_CFLAGS = $(AM_CFLAGS) '-DBT_CLI_PATH="$(abs_top_builddir)/src/cli/babeltrace2$(EXEEXT)"'
-
-# Only used for in-tree execution and tests
-babeltrace2_log_SOURCES = $(babeltrace2_log_bin_SOURCES)
-babeltrace2_log_LDADD = $(babeltrace2_log_bin_LDADD)
-babeltrace2_log_CFLAGS = $(AM_CFLAGS) '-DBT_CLI_PATH="$(bindir)/babeltrace2$(EXEEXT)"'
+++ /dev/null
-/*
- * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdbool.h>
-#include <string.h>
-#include "common/assert.h"
-#include <babeltrace2/babeltrace.h>
-#include <popt.h>
-#include <glib.h>
-
-static
-void print_usage(FILE *fp)
-{
- fprintf(stderr, "Usage: babeltrace2-log [OPTIONS] OUTPUT-PATH\n");
- fprintf(stderr, "\n");
- fprintf(stderr, "Options:\n");
- fprintf(stderr, "\n");
- fprintf(stderr, " -t, --with-timestamps Extract timestamps from lines and map them to\n");
- fprintf(stderr, " a CTF clock class\n");
-}
-
-static
-int parse_params(int argc, char *argv[], char **output_path,
- bool *no_extract_ts)
-{
- enum {
- OPT_WITH_TIMESTAMPS = 1,
- OPT_HELP = 2,
- };
- static struct poptOption opts[] = {
- { "with-timestamps", 't', POPT_ARG_NONE, NULL, OPT_WITH_TIMESTAMPS, NULL, NULL },
- { "help", 'h', POPT_ARG_NONE, NULL, OPT_HELP, NULL, NULL },
- { NULL, '\0', 0, NULL, 0, NULL, NULL },
- };
- poptContext pc = NULL;
- int opt;
- int ret = 0;
- const char *leftover;
-
- *no_extract_ts = true;
- pc = poptGetContext(NULL, argc, (const char **) argv, opts, 0);
- if (!pc) {
- fprintf(stderr, "Cannot get popt context\n");
- goto error;
- }
-
- poptReadDefaultConfig(pc, 0);
-
- while ((opt = poptGetNextOpt(pc)) > 0) {
- switch (opt) {
- case OPT_HELP:
- print_usage(stdout);
- goto end;
- case OPT_WITH_TIMESTAMPS:
- *no_extract_ts = false;
- break;
- default:
- fprintf(stderr, "Unknown command-line option specified (option code %d)\n",
- opt);
- goto error;
- }
- }
-
- if (opt < -1) {
- fprintf(stderr, "While parsing command-line options, at option %s: %s\n",
- poptBadOption(pc, 0), poptStrerror(opt));
- goto error;
- }
-
- leftover = poptGetArg(pc);
- if (!leftover) {
- fprintf(stderr, "Command line error: Missing output path\n");
- print_usage(stderr);
- goto error;
- }
-
- *output_path = strdup(leftover);
- BT_ASSERT(*output_path);
- goto end;
-
-error:
- ret = 1;
-
-end:
- if (pc) {
- poptFreeContext(pc);
- }
-
- return ret;
-}
-
-int main(int argc, char *argv[])
-{
- char *output_path = NULL;
- bool no_extract_ts;
- int retcode;
- GError *error = NULL;
- gchar *bt_argv[] = {
- BT_CLI_PATH,
- "run",
- "--component",
- "dmesg:src.text.dmesg",
- "--params",
- NULL, /* no-extract-timestamp=? placeholder */
- "--component",
- "ctf:sink.ctf.fs",
- "--key",
- "path",
- "--value",
- NULL, /* output path placeholder */
- "--params",
- "single-trace=yes",
- "--connect",
- "dmesg:ctf",
- NULL, /* sentinel */
- };
-
- retcode = parse_params(argc, argv, &output_path, &no_extract_ts);
- if (retcode) {
- goto end;
- }
-
- if (no_extract_ts) {
- bt_argv[5] = "no-extract-timestamp=yes";
- } else {
- bt_argv[5] = "no-extract-timestamp=no";
- }
-
- bt_argv[11] = output_path;
- (void) g_spawn_sync(NULL, bt_argv, NULL,
- G_SPAWN_CHILD_INHERITS_STDIN, NULL, NULL,
- NULL, NULL, &retcode, &error);
-
- if (error) {
- fprintf(stderr, "Failed to execute \"%s\": %s (%d)\n",
- bt_argv[0], error->message, error->code);
- }
-
-end:
- free(output_path);
-
- if (error) {
- g_error_free(error);
- }
-
- return retcode;
-}