Skip to content

Commit edbe981

Browse files
olsajiriacmel
authored andcommitted
perf data: Add perf data to CTF conversion support
Adding 'perf data convert' to convert perf data file into different format. This patch adds support for CTF format conversion. To convert perf.data into CTF run: $ perf data convert --to-ctf=./ctf-data/ [ perf data convert: Converted 'perf.data' into CTF data './ctf-data/' ] [ perf data convert: Converted and wrote 11.268 MB (100230 samples) ] The command will create CTF metadata out of perf.data file (or one specified via -i option) and then convert all sample events into single CTF stream. Each sample_type bit is translated into separated CTF event field apart from following exceptions: PERF_SAMPLE_RAW - added in next patch PERF_SAMPLE_READ - TODO PERF_SAMPLE_CALLCHAIN - TODO PERF_SAMPLE_BRANCH_STACK - TODO PERF_SAMPLE_REGS_USER - TODO PERF_SAMPLE_STACK_USER - TODO $ perf --debug=data-convert=2 data convert ... The converted CTF data could be analyzed by CTF tools, like babletrace or tracecompass [1]. $ babeltrace ./ctf-data/ [03:19:13.962125533] (+?.?????????) cycles: { }, { ip = 0xFFFFFFFF8105443A, tid = 20714, pid = 20714, period = 1 } [03:19:13.962130001] (+0.000004468) cycles: { }, { ip = 0xFFFFFFFF8105443A, tid = 20714, pid = 20714, period = 1 } [03:19:13.962131936] (+0.000001935) cycles: { }, { ip = 0xFFFFFFFF8105443A, tid = 20714, pid = 20714, period = 8 } [03:19:13.962133732] (+0.000001796) cycles: { }, { ip = 0xFFFFFFFF8105443A, tid = 20714, pid = 20714, period = 114 } [03:19:13.962135557] (+0.000001825) cycles: { }, { ip = 0xFFFFFFFF8105443A, tid = 20714, pid = 20714, period = 2087 } [03:19:13.962137627] (+0.000002070) cycles: { }, { ip = 0xFFFFFFFF81361938, tid = 20714, pid = 20714, period = 37582 } [03:19:13.962161091] (+0.000023464) cycles: { }, { ip = 0xFFFFFFFF8124218F, tid = 20714, pid = 20714, period = 600246 } [03:19:13.962517569] (+0.000356478) cycles: { }, { ip = 0xFFFFFFFF811A75DB, tid = 20714, pid = 20714, period = 1325731 } [03:19:13.969518008] (+0.007000439) cycles: { }, { ip = 0x34080917B2, tid = 20714, pid = 20714, period = 1144298 } The following members to the ctf-environment were decided to be added to distinguish and specify perf CTF data: - domain It says "kernel" because it contains a kernel trace (not to be confused with a user space like lttng-ust does) - tracer_name It says perf. This can be used to distinguish between lttng and perf CTF based trace. - version The kernel version from stream. In addition to release, this is what it looks like on a Debian kernel: release = "3.14-1-amd64"; version = "3.14.0"; [1] http://projects.eclipse.org/projects/tools.tracecompass Signed-off-by: Jiri Olsa <jolsa@kernel.org> Acked-by: Namhyung Kim <namhyung@kernel.org> Reviewed-by: David Ahern <dsahern@gmail.com> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jeremie Galarneau <jgalar@efficios.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Cc: Tom Zanussi <tzanussi@gmail.com> Cc: Wang Nan <wangnan0@huawei.com> Link: http://lkml.kernel.org/r/1424470628-5969-4-git-send-email-jolsa@kernel.org Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 2245bf1 commit edbe981

9 files changed

Lines changed: 701 additions & 1 deletion

File tree

‎tools/perf/Documentation/perf-data.txt‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,28 @@ SYNOPSIS
1313
DESCRIPTION
1414
-----------
1515
Data file related processing.
16+
17+
COMMANDS
18+
--------
19+
convert::
20+
Converts perf data file into another format (only CTF [1] format is support by now).
21+
It's possible to set data-convert debug variable to get debug messages from conversion,
22+
like:
23+
perf --debug data-convert data convert ...
24+
25+
OPTIONS for 'convert'
26+
---------------------
27+
--to-ctf::
28+
Triggers the CTF conversion, specify the path of CTF data directory.
29+
30+
-i::
31+
Specify input perf data file path.
32+
33+
-v::
34+
--verbose::
35+
Be more verbose (show counter open errors, etc).
36+
37+
SEE ALSO
38+
--------
39+
linkperf:perf[1]
40+
[1] Common Trace Format - http://www.efficios.com/ctf

‎tools/perf/Documentation/perf.txt‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@ SYNOPSIS
1313
OPTIONS
1414
-------
1515
--debug::
16-
Setup debug variable (just verbose for now) in value
16+
Setup debug variable (see list below) in value
1717
range (0, 10). Use like:
1818
--debug verbose # sets verbose = 1
1919
--debug verbose=2 # sets verbose = 2
2020

21+
List of debug variables allowed to set:
22+
verbose - general debug messages
23+
ordered-events - ordered events object debug messages
24+
data-convert - data convert command debug messages
25+
2126
--buildid-dir::
2227
Setup buildid cache directory. It has higher priority than
2328
buildid.dir config file option.

‎tools/perf/builtin-data.c‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "perf.h"
44
#include "debug.h"
55
#include "parse-options.h"
6+
#include "data-convert-bt.h"
67

78
typedef int (*data_cmd_fn_t)(int argc, const char **argv, const char *prefix);
89

@@ -41,7 +42,50 @@ static void print_usage(void)
4142
printf("\n");
4243
}
4344

45+
static const char * const data_convert_usage[] = {
46+
"perf data convert [<options>]",
47+
NULL
48+
};
49+
50+
static int cmd_data_convert(int argc, const char **argv,
51+
const char *prefix __maybe_unused)
52+
{
53+
const char *to_ctf = NULL;
54+
const struct option options[] = {
55+
OPT_INCR('v', "verbose", &verbose, "be more verbose"),
56+
OPT_STRING('i', "input", &input_name, "file", "input file name"),
57+
#ifdef HAVE_LIBBABELTRACE_SUPPORT
58+
OPT_STRING(0, "to-ctf", &to_ctf, NULL, "Convert to CTF format"),
59+
#endif
60+
OPT_END()
61+
};
62+
63+
#ifndef HAVE_LIBBABELTRACE_SUPPORT
64+
pr_err("No conversion support compiled in.\n");
65+
return -1;
66+
#endif
67+
68+
argc = parse_options(argc, argv, options,
69+
data_convert_usage, 0);
70+
if (argc) {
71+
usage_with_options(data_convert_usage, options);
72+
return -1;
73+
}
74+
75+
if (to_ctf) {
76+
#ifdef HAVE_LIBBABELTRACE_SUPPORT
77+
return bt_convert__perf2ctf(input_name, to_ctf);
78+
#else
79+
pr_err("The libbabeltrace support is not compiled in.\n");
80+
return -1;
81+
#endif
82+
}
83+
84+
return 0;
85+
}
86+
4487
static struct data_cmd data_cmds[] = {
88+
{ "convert", "converts data file between formats", cmd_data_convert },
4589
{ NULL },
4690
};
4791

‎tools/perf/config/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,7 @@ ifndef NO_LIBBABELTRACE
713713
CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS)
714714
LDFLAGS += $(LIBBABELTRACE_LDFLAGS)
715715
EXTLIBS += -lbabeltrace-ctf
716+
$(call detected,CONFIG_LIBBABELTRACE)
716717
endif
717718
endif
718719

‎tools/perf/util/Build‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ libperf-$(CONFIG_DWARF) += dwarf-aux.o
8888
libperf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
8989
libperf-$(CONFIG_LIBUNWIND) += unwind-libunwind.o
9090

91+
libperf-$(CONFIG_LIBBABELTRACE) += data-convert-bt.o
92+
9193
libperf-y += scripting-engines/
9294

9395
libperf-$(CONFIG_PERF_REGS) += perf_regs.o

0 commit comments

Comments
 (0)