2017-11-01 15:07:57 +01:00
// SPDX-License-Identifier: GPL-2.0
2015-02-20 23:16:59 +01:00
#include <linux/compiler.h>
#include "builtin.h"
#include "perf.h"
#include "debug.h"
2015-12-15 09:39:39 -06:00
#include <subcmd/parse-options.h>
2016-06-24 11:22:07 +00:00
#include "data-convert.h"
2015-02-20 23:17:00 +01:00
#include "data-convert-bt.h"
2015-02-20 23:16:59 +01:00
2017-03-27 11:47:20 -03:00
typedef int ( * data_cmd_fn_t )( int argc , const char ** argv );
2015-02-20 23:16:59 +01:00
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 struct option data_options [] = {
OPT_END ()
};
2015-03-18 21:35:52 +08:00
static const char * const data_subcommands [] = { "convert" , NULL };
static const char * data_usage [] = {
2015-02-20 23:16:59 +01:00
"perf data [<common options>] <command> [<options>]" ,
NULL
};
static void print_usage ( void )
{
struct data_cmd * cmd ;
printf ( "Usage: \n " );
printf ( " \t %s \n\n " , data_usage [ 0 ]);
printf ( " \t Available commands: \n " );
for_each_cmd ( cmd ) {
printf ( " \t %s \t - %s \n " , cmd -> name , cmd -> summary );
}
printf ( " \n " );
}
2015-02-20 23:17:00 +01:00
static const char * const data_convert_usage [] = {
"perf data convert [<options>]" ,
NULL
};
2017-03-27 11:47:20 -03:00
static int cmd_data_convert ( int argc , const char ** argv )
2015-02-20 23:17:00 +01:00
{
const char * to_ctf = NULL ;
2016-06-24 11:22:07 +00:00
struct perf_data_convert_opts opts = {
. force = false ,
2016-06-24 11:22:08 +00:00
. all = false ,
2016-06-24 11:22:07 +00:00
};
2015-02-20 23:17:00 +01:00
const struct option options [] = {
OPT_INCR ( 'v' , "verbose" , & verbose , "be more verbose" ),
OPT_STRING ( 'i' , "input" , & input_name , "file" , "input file name" ),
#ifdef HAVE_LIBBABELTRACE_SUPPORT
OPT_STRING ( 0 , "to-ctf" , & to_ctf , NULL , "Convert to CTF format" ),
#endif
2016-06-24 11:22:07 +00:00
OPT_BOOLEAN ( 'f' , "force" , & opts . force , "don't complain, do it" ),
2016-06-24 11:22:11 +00:00
OPT_BOOLEAN ( 0 , "all" , & opts . all , "Convert all events" ),
2015-02-20 23:17:00 +01:00
OPT_END ()
};
#ifndef HAVE_LIBBABELTRACE_SUPPORT
2017-07-27 14:12:05 -04:00
pr_err ( "No conversion support compiled in. perf should be compiled with environment variables LIBBABELTRACE=1 and LIBBABELTRACE_DIR=/path/to/libbabeltrace/ \n " );
2015-02-20 23:17:00 +01:00
return - 1 ;
#endif
argc = parse_options ( argc , argv , options ,
data_convert_usage , 0 );
if ( argc ) {
usage_with_options ( data_convert_usage , options );
return - 1 ;
}
if ( to_ctf ) {
#ifdef HAVE_LIBBABELTRACE_SUPPORT
2016-06-24 11:22:07 +00:00
return bt_convert__perf2ctf ( input_name , to_ctf , & opts );
2015-02-20 23:17:00 +01:00
#else
pr_err ( "The libbabeltrace support is not compiled in. \n " );
return - 1 ;
#endif
}
return 0 ;
}
2015-02-20 23:16:59 +01:00
static struct data_cmd data_cmds [] = {
2015-02-20 23:17:00 +01:00
{ "convert" , "converts data file between formats" , cmd_data_convert },
2015-02-27 19:53:46 +08:00
{ . name = NULL , },
2015-02-20 23:16:59 +01:00
};
2017-03-27 11:47:20 -03:00
int cmd_data ( int argc , const char ** argv )
2015-02-20 23:16:59 +01:00
{
struct data_cmd * cmd ;
const char * cmdstr ;
/* No command specified. */
if ( argc < 2 )
goto usage ;
2015-03-18 21:35:52 +08:00
argc = parse_options_subcommand ( argc , argv , data_options , data_subcommands , data_usage ,
2015-02-20 23:16:59 +01:00
PARSE_OPT_STOP_AT_NON_OPTION );
if ( argc < 1 )
goto usage ;
cmdstr = argv [ 0 ];
for_each_cmd ( cmd ) {
if ( strcmp ( cmd -> name , cmdstr ))
continue ;
2017-03-27 11:47:20 -03:00
return cmd -> fn ( argc , argv );
2015-02-20 23:16:59 +01:00
}
pr_err ( "Unknown command: %s \n " , cmdstr );
usage :
print_usage ();
return - 1 ;
}