Linux Audio

Check our new training course

Loading...
v4.6
 
  1#include <linux/compiler.h>
 
 
  2#include "builtin.h"
  3#include "perf.h"
  4#include "debug.h"
  5#include <subcmd/parse-options.h>
 
  6#include "data-convert-bt.h"
  7
  8typedef int (*data_cmd_fn_t)(int argc, const char **argv, const char *prefix);
  9
 10struct data_cmd {
 11	const char	*name;
 12	const char	*summary;
 13	data_cmd_fn_t	fn;
 14};
 15
 16static struct data_cmd data_cmds[];
 17
 18#define for_each_cmd(cmd) \
 19	for (cmd = data_cmds; cmd && cmd->name; cmd++)
 20
 21static const struct option data_options[] = {
 22	OPT_END()
 23};
 24
 25static const char * const data_subcommands[] = { "convert", NULL };
 26
 27static const char *data_usage[] = {
 28	"perf data [<common options>] <command> [<options>]",
 29	NULL
 30};
 31
 32static void print_usage(void)
 33{
 34	struct data_cmd *cmd;
 35
 36	printf("Usage:\n");
 37	printf("\t%s\n\n", data_usage[0]);
 38	printf("\tAvailable commands:\n");
 39
 40	for_each_cmd(cmd) {
 41		printf("\t %s\t- %s\n", cmd->name, cmd->summary);
 42	}
 43
 44	printf("\n");
 45}
 46
 47static const char * const data_convert_usage[] = {
 48	"perf data convert [<options>]",
 49	NULL
 50};
 51
 52static int cmd_data_convert(int argc, const char **argv,
 53			    const char *prefix __maybe_unused)
 54{
 55	const char *to_ctf     = NULL;
 56	bool force = false;
 
 
 
 57	const struct option options[] = {
 58		OPT_INCR('v', "verbose", &verbose, "be more verbose"),
 59		OPT_STRING('i', "input", &input_name, "file", "input file name"),
 60#ifdef HAVE_LIBBABELTRACE_SUPPORT
 61		OPT_STRING(0, "to-ctf", &to_ctf, NULL, "Convert to CTF format"),
 
 62#endif
 63		OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
 
 64		OPT_END()
 65	};
 66
 67#ifndef HAVE_LIBBABELTRACE_SUPPORT
 68	pr_err("No conversion support compiled in.\n");
 69	return -1;
 70#endif
 71
 72	argc = parse_options(argc, argv, options,
 73			     data_convert_usage, 0);
 74	if (argc) {
 75		usage_with_options(data_convert_usage, options);
 76		return -1;
 77	}
 78
 79	if (to_ctf) {
 80#ifdef HAVE_LIBBABELTRACE_SUPPORT
 81		return bt_convert__perf2ctf(input_name, to_ctf, force);
 82#else
 83		pr_err("The libbabeltrace support is not compiled in.\n");
 84		return -1;
 85#endif
 86	}
 87
 88	return 0;
 89}
 90
 91static struct data_cmd data_cmds[] = {
 92	{ "convert", "converts data file between formats", cmd_data_convert },
 93	{ .name = NULL, },
 94};
 95
 96int cmd_data(int argc, const char **argv, const char *prefix)
 97{
 98	struct data_cmd *cmd;
 99	const char *cmdstr;
100
101	/* No command specified. */
102	if (argc < 2)
103		goto usage;
104
105	argc = parse_options_subcommand(argc, argv, data_options, data_subcommands, data_usage,
106			     PARSE_OPT_STOP_AT_NON_OPTION);
107	if (argc < 1)
108		goto usage;
109
110	cmdstr = argv[0];
111
112	for_each_cmd(cmd) {
113		if (strcmp(cmd->name, cmdstr))
114			continue;
115
116		return cmd->fn(argc, argv, prefix);
117	}
118
119	pr_err("Unknown command: %s\n", cmdstr);
120usage:
121	print_usage();
122	return -1;
123}
v5.9
  1// SPDX-License-Identifier: GPL-2.0
  2#include <linux/compiler.h>
  3#include <stdio.h>
  4#include <string.h>
  5#include "builtin.h"
  6#include "perf.h"
  7#include "debug.h"
  8#include <subcmd/parse-options.h>
  9#include "data-convert.h"
 10#include "data-convert-bt.h"
 11
 12typedef int (*data_cmd_fn_t)(int argc, const char **argv);
 13
 14struct data_cmd {
 15	const char	*name;
 16	const char	*summary;
 17	data_cmd_fn_t	fn;
 18};
 19
 20static struct data_cmd data_cmds[];
 21
 22#define for_each_cmd(cmd) \
 23	for (cmd = data_cmds; cmd && cmd->name; cmd++)
 24
 25static const struct option data_options[] = {
 26	OPT_END()
 27};
 28
 29static const char * const data_subcommands[] = { "convert", NULL };
 30
 31static const char *data_usage[] = {
 32	"perf data [<common options>] <command> [<options>]",
 33	NULL
 34};
 35
 36static void print_usage(void)
 37{
 38	struct data_cmd *cmd;
 39
 40	printf("Usage:\n");
 41	printf("\t%s\n\n", data_usage[0]);
 42	printf("\tAvailable commands:\n");
 43
 44	for_each_cmd(cmd) {
 45		printf("\t %s\t- %s\n", cmd->name, cmd->summary);
 46	}
 47
 48	printf("\n");
 49}
 50
 51static const char * const data_convert_usage[] = {
 52	"perf data convert [<options>]",
 53	NULL
 54};
 55
 56static int cmd_data_convert(int argc, const char **argv)
 
 57{
 58	const char *to_ctf     = NULL;
 59	struct perf_data_convert_opts opts = {
 60		.force = false,
 61		.all = false,
 62	};
 63	const struct option options[] = {
 64		OPT_INCR('v', "verbose", &verbose, "be more verbose"),
 65		OPT_STRING('i', "input", &input_name, "file", "input file name"),
 66#ifdef HAVE_LIBBABELTRACE_SUPPORT
 67		OPT_STRING(0, "to-ctf", &to_ctf, NULL, "Convert to CTF format"),
 68		OPT_BOOLEAN(0, "tod", &opts.tod, "Convert time to wall clock time"),
 69#endif
 70		OPT_BOOLEAN('f', "force", &opts.force, "don't complain, do it"),
 71		OPT_BOOLEAN(0, "all", &opts.all, "Convert all events"),
 72		OPT_END()
 73	};
 74
 75#ifndef HAVE_LIBBABELTRACE_SUPPORT
 76	pr_err("No conversion support compiled in. perf should be compiled with environment variables LIBBABELTRACE=1 and LIBBABELTRACE_DIR=/path/to/libbabeltrace/\n");
 77	return -1;
 78#endif
 79
 80	argc = parse_options(argc, argv, options,
 81			     data_convert_usage, 0);
 82	if (argc) {
 83		usage_with_options(data_convert_usage, options);
 84		return -1;
 85	}
 86
 87	if (to_ctf) {
 88#ifdef HAVE_LIBBABELTRACE_SUPPORT
 89		return bt_convert__perf2ctf(input_name, to_ctf, &opts);
 90#else
 91		pr_err("The libbabeltrace support is not compiled in.\n");
 92		return -1;
 93#endif
 94	}
 95
 96	return 0;
 97}
 98
 99static struct data_cmd data_cmds[] = {
100	{ "convert", "converts data file between formats", cmd_data_convert },
101	{ .name = NULL, },
102};
103
104int cmd_data(int argc, const char **argv)
105{
106	struct data_cmd *cmd;
107	const char *cmdstr;
108
109	/* No command specified. */
110	if (argc < 2)
111		goto usage;
112
113	argc = parse_options_subcommand(argc, argv, data_options, data_subcommands, data_usage,
114			     PARSE_OPT_STOP_AT_NON_OPTION);
115	if (argc < 1)
116		goto usage;
117
118	cmdstr = argv[0];
119
120	for_each_cmd(cmd) {
121		if (strcmp(cmd->name, cmdstr))
122			continue;
123
124		return cmd->fn(argc, argv);
125	}
126
127	pr_err("Unknown command: %s\n", cmdstr);
128usage:
129	print_usage();
130	return -1;
131}