~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/perf/builtin-data.c

Version: ~ [ linux-6.6-rc1 ] ~ [ linux-6.5.2 ] ~ [ linux-6.4.15 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.52 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.131 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.194 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.256 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.294 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.325 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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 
 11 typedef int (*data_cmd_fn_t)(int argc, const char **argv);
 12 
 13 struct data_cmd {
 14         const char      *name;
 15         const char      *summary;
 16         data_cmd_fn_t   fn;
 17 };
 18 
 19 static struct data_cmd data_cmds[];
 20 
 21 #define for_each_cmd(cmd) \
 22         for (cmd = data_cmds; cmd && cmd->name; cmd++)
 23 
 24 static const char * const data_subcommands[] = { "convert", NULL };
 25 
 26 static const char *data_usage[] = {
 27         "perf data convert [<options>]",
 28         NULL
 29 };
 30 
 31 const char *to_json;
 32 const char *to_ctf;
 33 struct perf_data_convert_opts opts = {
 34         .force = false,
 35         .all = false,
 36 };
 37 
 38 const struct option data_options[] = {
 39                 OPT_INCR('v', "verbose", &verbose, "be more verbose"),
 40                 OPT_STRING('i', "input", &input_name, "file", "input file name"),
 41                 OPT_STRING(0, "to-json", &to_json, NULL, "Convert to JSON format"),
 42 #ifdef HAVE_LIBBABELTRACE_SUPPORT
 43                 OPT_STRING(0, "to-ctf", &to_ctf, NULL, "Convert to CTF format"),
 44                 OPT_BOOLEAN(0, "tod", &opts.tod, "Convert time to wall clock time"),
 45 #endif
 46                 OPT_BOOLEAN('f', "force", &opts.force, "don't complain, do it"),
 47                 OPT_BOOLEAN(0, "all", &opts.all, "Convert all events"),
 48                 OPT_END()
 49         };
 50 
 51 static int cmd_data_convert(int argc, const char **argv)
 52 {
 53 
 54         argc = parse_options(argc, argv, data_options,
 55                              data_usage, 0);
 56         if (argc) {
 57                 usage_with_options(data_usage, data_options);
 58                 return -1;
 59         }
 60 
 61         if (to_json && to_ctf) {
 62                 pr_err("You cannot specify both --to-ctf and --to-json.\n");
 63                 return -1;
 64         }
 65 #ifdef HAVE_LIBBABELTRACE_SUPPORT
 66         if (!to_json && !to_ctf) {
 67                 pr_err("You must specify one of --to-ctf or --to-json.\n");
 68                 return -1;
 69         }
 70 #else
 71         if (!to_json) {
 72                 pr_err("You must specify --to-json.\n");
 73         return -1;
 74 }
 75 #endif
 76 
 77         if (to_json)
 78                 return bt_convert__perf2json(input_name, to_json, &opts);
 79 
 80         if (to_ctf) {
 81 #ifdef HAVE_LIBBABELTRACE_SUPPORT
 82                 return bt_convert__perf2ctf(input_name, to_ctf, &opts);
 83 #else
 84                 pr_err("The libbabeltrace support is not compiled in. perf should be "
 85                        "compiled with environment variables LIBBABELTRACE=1 and "
 86                        "LIBBABELTRACE_DIR=/path/to/libbabeltrace/\n");
 87                 return -1;
 88 #endif
 89         }
 90 
 91         return 0;
 92 }
 93 
 94 static struct data_cmd data_cmds[] = {
 95         { "convert", "converts data file between formats", cmd_data_convert },
 96         { .name = NULL, },
 97 };
 98 
 99 int cmd_data(int argc, const char **argv)
100 {
101         struct data_cmd *cmd;
102         const char *cmdstr;
103 
104         argc = parse_options_subcommand(argc, argv, data_options, data_subcommands, data_usage,
105                              PARSE_OPT_STOP_AT_NON_OPTION);
106 
107         if (!argc) {
108                 usage_with_options(data_usage, data_options);
109                 return -1;
110         }
111 
112         cmdstr = argv[0];
113 
114         for_each_cmd(cmd) {
115                 if (strcmp(cmd->name, cmdstr))
116                         continue;
117 
118                 return cmd->fn(argc, argv);
119         }
120 
121         pr_err("Unknown command: %s\n", cmdstr);
122         usage_with_options(data_usage, data_options);
123         return -1;
124 }
125 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp