mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-07-22 03:27:30 -04:00
The 1.x branch of Babeltrace has been superseded by 2.x in 2020 and has been unmaintained since 2022, efforts have started to remove it from popular distributions. Babeltrace 2.x offers a very similar 'ctf-writer' library that can be used with minimal changes for the '--to-ctf' feature and has been packaged since Debian 11 and Fedora 32. This patch replaces the 'libbabeltrace' build feature with 'babeltrace2-ctf-writer' using pkgconfig detection, adjusts the naming of the public headers and applies minor API cleanups. There is no changes to the output ctf traces, the ctf-writer API still implements version 1.8 of the CTF specification that can be read by either Babeltrace 1 / 2 or any CTF compliant reader. Also remove some ifdefs in the cli option parsing to allow printing the helpful error message with '--to-ctf' when built without babeltrace2. Reviewed-by: Ian Rogers <irogers@google.com> Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Derek Foreman <derek.foreman@collabora.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@linaro.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
119 lines
2.9 KiB
C
119 lines
2.9 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <linux/compiler.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include "builtin.h"
|
|
#include "debug.h"
|
|
#include <subcmd/parse-options.h>
|
|
#include "data-convert.h"
|
|
#include "util/util.h"
|
|
|
|
typedef int (*data_cmd_fn_t)(int argc, const char **argv);
|
|
|
|
struct data_cmd {
|
|
const char *name;
|
|
const char *summary;
|
|
data_cmd_fn_t fn;
|
|
};
|
|
|
|
static struct data_cmd data_cmds[];
|
|
|
|
#define for_each_cmd(cmd) \
|
|
for (cmd = data_cmds; cmd && cmd->name; cmd++)
|
|
|
|
static const char * const data_subcommands[] = { "convert", NULL };
|
|
|
|
static const char *data_usage[] = {
|
|
"perf data convert [<options>]",
|
|
NULL
|
|
};
|
|
|
|
static const char *to_json;
|
|
static const char *to_ctf;
|
|
static struct perf_data_convert_opts opts = {
|
|
.force = false,
|
|
.all = false,
|
|
.time_str = NULL,
|
|
};
|
|
|
|
static const struct option data_options[] = {
|
|
OPT_INCR('v', "verbose", &verbose, "be more verbose"),
|
|
OPT_STRING('i', "input", &input_name, "file", "input file name"),
|
|
OPT_STRING(0, "to-json", &to_json, NULL, "Convert to JSON format"),
|
|
OPT_STRING(0, "to-ctf", &to_ctf, NULL, "Convert to CTF format"),
|
|
OPT_BOOLEAN(0, "tod", &opts.tod, "Convert time to wall clock time"),
|
|
OPT_BOOLEAN('f', "force", &opts.force, "don't complain, do it"),
|
|
OPT_BOOLEAN(0, "all", &opts.all, "Convert all events"),
|
|
OPT_STRING(0, "time", &opts.time_str, "str",
|
|
"Time span of interest (start,stop)"),
|
|
OPT_END()
|
|
};
|
|
|
|
static int cmd_data_convert(int argc, const char **argv)
|
|
{
|
|
|
|
argc = parse_options(argc, argv, data_options,
|
|
data_usage, 0);
|
|
if (argc) {
|
|
usage_with_options(data_usage, data_options);
|
|
return -1;
|
|
}
|
|
|
|
if (to_json && to_ctf) {
|
|
pr_err("You cannot specify both --to-ctf and --to-json.\n");
|
|
return -1;
|
|
}
|
|
if (!to_json && !to_ctf) {
|
|
pr_err("You must specify one of --to-ctf or --to-json.\n");
|
|
return -1;
|
|
}
|
|
|
|
if (to_json)
|
|
return bt_convert__perf2json(input_name, to_json, &opts);
|
|
|
|
if (to_ctf) {
|
|
#if defined(HAVE_BABELTRACE2_CTF_WRITER_SUPPORT) && defined(HAVE_LIBTRACEEVENT)
|
|
return bt_convert__perf2ctf(input_name, to_ctf, &opts);
|
|
#else
|
|
pr_err("The babeltrace2 ctf support is not compiled in. Ensure you have both\n"
|
|
"libbabeltrace2-dev[el] and libtraceevent-dev[el] installed or set\n"
|
|
"PKG_CONFIG_PATH to find a local installation of those libraries.\n");
|
|
return -1;
|
|
#endif
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct data_cmd data_cmds[] = {
|
|
{ "convert", "converts data file between formats", cmd_data_convert },
|
|
{ .name = NULL, },
|
|
};
|
|
|
|
int cmd_data(int argc, const char **argv)
|
|
{
|
|
struct data_cmd *cmd;
|
|
const char *cmdstr;
|
|
|
|
argc = parse_options_subcommand(argc, argv, data_options, data_subcommands, data_usage,
|
|
PARSE_OPT_STOP_AT_NON_OPTION);
|
|
|
|
if (!argc) {
|
|
usage_with_options(data_usage, data_options);
|
|
return -1;
|
|
}
|
|
|
|
cmdstr = argv[0];
|
|
|
|
for_each_cmd(cmd) {
|
|
if (strcmp(cmd->name, cmdstr))
|
|
continue;
|
|
|
|
return cmd->fn(argc, argv);
|
|
}
|
|
|
|
pr_err("Unknown command: %s\n", cmdstr);
|
|
usage_with_options(data_usage, data_options);
|
|
return -1;
|
|
}
|