Add new command-line option to perf data convert for generating trace.dat output files.
The --to-trace-dat option: - Accepts output filename for trace.dat format - Mutually exclusive with --to-ctf and --to-json - Calls trace_convert__perf2dat() to perform conversion Usage: $ perf record -e sched:* -a sleep 1 $ perf data convert --to-trace-dat=trace.dat $ trace-cmd report trace.dat Signed-off-by: Tanushree Shah <[email protected]> --- tools/perf/builtin-data.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-data.c b/tools/perf/builtin-data.c index 4c08ccb8c06b..96ccab77456a 100644 --- a/tools/perf/builtin-data.c +++ b/tools/perf/builtin-data.c @@ -30,6 +30,9 @@ static const char *data_usage[] = { static const char *to_json; static const char *to_ctf; +#ifdef HAVE_LIBTRACEEVENT + static const char *trace_dat_output; +#endif static struct perf_data_convert_opts opts = { .force = false, .all = false, @@ -48,6 +51,10 @@ static const struct option data_options[] = { OPT_BOOLEAN(0, "all", &opts.all, "Convert all events"), OPT_STRING(0, "time", &opts.time_str, "str", "Time span of interest (start,stop)"), +#ifdef HAVE_LIBTRACEEVENT + OPT_STRING(0, "to-trace-dat", &trace_dat_output, + "file", "Convert to trace.dat format using perf.data tracepoints"), +#endif OPT_END() }; @@ -65,16 +72,43 @@ static int cmd_data_convert(int argc, const char **argv) pr_err("You cannot specify both --to-ctf and --to-json.\n"); return -1; } +#ifdef HAVE_LIBTRACEEVENT + if (trace_dat_output && (to_json || to_ctf)) { + pr_err("You cannot specify --to-trace-dat with --to-ctf or --to-json.\n"); + return -1; + } +#endif + #ifdef HAVE_LIBBABELTRACE_SUPPORT + #ifdef HAVE_LIBTRACEEVENT + if (!to_json && !to_ctf && !trace_dat_output) { + pr_err("You must specify one of --to-ctf, --to-json, or --to-trace-dat.\n"); + return -1; + } + #else if (!to_json && !to_ctf) { pr_err("You must specify one of --to-ctf or --to-json.\n"); return -1; } + #endif #else + #ifdef HAVE_LIBTRACEEVENT + if (!to_json && !trace_dat_output) { + pr_err("You must specify --to-json or --to-trace-dat.\n"); + return -1; + } + #else if (!to_json) { pr_err("You must specify --to-json.\n"); - return -1; -} + return -1 + } + #endif +#endif + +#ifdef HAVE_LIBTRACEEVENT + if (trace_dat_output) + return trace_convert__perf2dat(input_name ? input_name : "perf.data", + trace_dat_output, &opts); #endif if (to_json) -- 2.53.0
