perf tools: Introduce an abstraction for AUX Area and Instruction Tracing
Adrian Hunter
reviewerv3 cover perf tools: Introduce an abstraction for AUX Area and Instruction Tracing
Hi
Here is V3 patches for the introduction of an abstraction for using the AUX area and Instruction tracing.
The patches can also be found here:
http://git.infradead.org/users/ahunter/linux-perf.git
An example perf.data file and build id archive can be found here:
http://git.infradead.org/~ahunter/tfr/
There is also a tar of the 3 most relevant files with debugging symbols. These need to be placed in under the correct paths in /usr/lib/debug to get symbols.
Changes in V3:
New patch:
perf tools: Amend mmap ref counting for the AUX area mmap
Move some code under arch:
perf tools: Add Intel PT support
perf tools: Add Intel BTS support
Updated documentation:
perf report: Add Instruction Tracing support
perf auxtrace: Add option to synthesize events for transactions perf tools: Take Intel PT into use
perf tools: Add Intel BTS support
Patches already applied:
perf header: Add AUX area tracing feature
perf evlist: Add support for mmapping an AUX area buffer
perf tools: Add user events for AUX area tracing
perf tools: Add support for AUX area recording
perf record: Add basic AUX area tracing support
perf record: Extend -m option for AUX area tracing mmap pages perf tools: Add a user event for AUX area tracing errors
perf session: Add hooks to allow transparent decoding of AUX area tracing data perf session: Add instruction tracing options
perf auxtrace: Add helpers for AUX area tracing errors
perf auxtrace: Add helpers for queuing AUX area tracing data perf auxtrace: Add a heap for sorting AUX area tracing queues perf auxtrace: Add processing for AUX area tracing events
perf auxtrace: Add a hashtable for caching
perf tools: Add member to struct dso for an instruction cache perf script: Add Instruction Tracing support
perf inject: Re-pipe AUX area tracing events
perf inject: Add Instruction Tracing support
perf script: Add field option 'flags' to print sample flags
perf tools: Add aux_watermark member of struct perf_event_attr
Changes in V2:
Get rid of MIN()
perf auxtrace: Add helpers for AUX area tracing errors perf inject: Re-pipe AUX area tracing events
perf tools: Add build option NO_AUXTRACE to exclude AUX area tracing
Intel BTS can be used on most recent Intel CPUs. Intel PT is available on Broadwell.
Examples:
Trace 'ls' with Intel BTS userspace only
perf record --per-thread -e intel_bts//u ls perf report
perf script
Trace 'ls' with Intel BTS kernel and userspace
~/libexec/perf-core/perf-with-kcore record bts-ls --per-thread -e intel_bts// -- ls ~/libexec/perf-core/perf-with-kcore report bts-ls ~/libexec/perf-core/perf-with-kcore script bts-ls
Trace 'ls' with Intel PT userspace only
perf record -e intel_pt//u ls
perf report
perf script
Trace 'ls' with Intel PT kernel and userspace
~/libexec/perf-core/perf-with-kcore record pt-ls -e intel_pt// -- ls ~/libexec/perf-core/perf-with-kcore report pt-ls ~/libexec/perf-core/perf-with-kcore script pt-ls
The abstraction has two separate aspects:
1. recording AUX area data
2. processing AUX area data
Recording consists of mmapping a separate buffer and copying the data into the perf.data file. The buffer is an AUX area buffer. The data is written preceded by a new user event PERF_RECORD_AUXTRACE. The data is too big to fit in the event but follows immediately afterward. Session processing has to skip to get to the next event header in a similar fashion to the existing PERF_RECORD_HEADER_TRACING_DATA
event. The main recording patches are:
perf evlist: Add support for mmapping an AUX area buffer perf tools: Add user events for AUX area tracing perf tools: Add support for AUX area recording perf record: Add basic AUX area tracing support
Processing consists of providing hooks in session processing to enable a decoder to see all the events and deliver synthesized events transparently into the event stream. The main processing patch is:
perf session: Add hooks to allow transparent decoding of AUX area tracing data
Adrian Hunter (25):
perf tools: Amend mmap ref counting for the AUX area mmap perf script: Always allow fields 'addr' and 'cpu' for auxtrace perf report: Add Instruction Tracing support
perf tools: Add AUX area tracing index
perf tools: Hit all build ids when AUX area tracing
perf tools: Add build option NO_AUXTRACE to exclude AUX area tracing perf auxtrace: Add option to synthesize events for transactions perf tools: Add support for PERF_RECORD_AUX
perf tools: Add support for PERF_RECORD_ITRACE_START perf tools: Add AUX area tracing Snapshot Mode
perf record: Add AUX area tracing Snapshot Mode support perf auxtrace: Add Intel PT as an AUX area tracing type perf tools: Add Intel PT packet decoder
perf tools: Add Intel PT instruction decoder
perf tools: Add Intel PT log
perf tools: Add Intel PT decoder
perf tools: Add Intel PT support
perf tools: Take Intel PT into use
perf tools: Allow auxtrace data alignment
perf tools: Add Intel BTS support
perf tools: Output sample flags and insn_len from intel_pt perf tools: Output sample flags and insn_len from intel_bts perf tools: Intel PT to always update thread stack trace number perf tools: Intel BTS to always update thread stack trace number perf tools: Add example call-graph script
tools/build/Makefile.build | 2 + tools/perf/.gitignore | 2 + tools/perf/Documentation/intel-bts.txt | 69 + tools/perf/Documentation/intel-pt.txt | 467 +++++ tools/perf/Documentation/perf-inject.txt | 9 +- tools/perf/Documentation/perf-record.txt | 7 + tools/perf/Documentation/perf-report.txt | 28 + tools/perf/Documentation/perf-script.txt | 9 +- tools/perf/Makefile.perf | 8 +- tools/perf/arch/x86/util/Build | 5 + tools/perf/arch/x86/util/auxtrace.c | 83 + tools/perf/arch/x86/util/intel-bts.c | 458 +++++ tools/perf/arch/x86/util/intel-pt.c | 752 ++++++++ tools/perf/arch/x86/util/pmu.c | 15 + tools/perf/builtin-buildid-list.c | 9 + tools/perf/builtin-inject.c | 78 +- tools/perf/builtin-record.c | 172 +- tools/perf/builtin-report.c | 11 + tools/perf/builtin-script.c | 29 +- tools/perf/config/Makefile | 5 + tools/perf/perf.h | 3 + .../scripts/python/call-graph-from-postgresql.py | 285 +++ tools/perf/tests/make | 2 + tools/perf/util/Build | 5 +- tools/perf/util/auxtrace.c | 322 +++- tools/perf/util/auxtrace.h | 220 +++ tools/perf/util/event.c | 39 + tools/perf/util/event.h | 24 + tools/perf/util/evlist.c | 2 +- tools/perf/util/header.c | 31 +- tools/perf/util/intel-bts.c | 919 ++++++++++ tools/perf/util/intel-bts.h | 43 + tools/perf/util/intel-pt-decoder/Build | 14 + .../perf/util/intel-pt-decoder/intel-pt-decoder.c | 1738 ++++++++++++++++++ .../perf/util/intel-pt-decoder/intel-pt-decoder.h | 89 + .../util/intel-pt-decoder/intel-pt-insn-decoder.c | 246 +++ .../util/intel-pt-decoder/intel-pt-insn-decoder.h | 65 + tools/perf/util/intel-pt-decoder/intel-pt-log.c | 155 ++ tools/perf/util/intel-pt-decoder/intel-pt-log.h | 52 + .../util/intel-pt-decoder/intel-pt-pkt-decoder.c | 400 +++++ .../util/intel-pt-decoder/intel-pt-pkt-decoder.h | 64 + tools/perf/util/intel-pt.c | 1897 ++++++++++++++++++++ tools/perf/util/intel-pt.h | 57 + tools/perf/util/machine.c | 21 + tools/perf/util/machine.h | 4 + tools/perf/util/parse-options.h | 4 + tools/perf/util/session.c | 32 + tools/perf/util/session.h | 1 + tools/perf/util/tool.h | 2 + 49 files changed, 8882 insertions(+), 72 deletions(-) create mode 100644 tools/perf/Documentation/intel-bts.txt create mode 100644 tools/perf/Documentation/intel-pt.txt create mode 100644 tools/perf/arch/x86/util/auxtrace.c create mode 100644 tools/perf/arch/x86/util/intel-bts.c create mode 100644 tools/perf/arch/x86/util/intel-pt.c create mode 100644 tools/perf/arch/x86/util/pmu.c create mode 100644 tools/perf/scripts/python/call-graph-from-postgresql.py create mode 100644 tools/perf/util/intel-bts.c create mode 100644 tools/perf/util/intel-bts.h create mode 100644 tools/perf/util/intel-pt-decoder/Build create mode 100644 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c create mode 100644 tools/perf/util/intel-pt-decoder/intel-pt-decoder.h create mode 100644 tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c create mode 100644 tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.h create mode 100644 tools/perf/util/intel-pt-decoder/intel-pt-log.c create mode 100644 tools/perf/util/intel-pt-decoder/intel-pt-log.h create mode 100644 tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c create mode 100644 tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.h create mode 100644 tools/perf/util/intel-pt.c create mode 100644 tools/perf/util/intel-pt.h
Regards
Adrian
Adrian Hunter
reviewerPATCH v3 1/25 perf tools: Amend mmap ref counting for the AUX area mmap
Reference counting of the mmap buffer does not work correctly when there is an AUX area mmap also.
In snapshot mode it is not easy to know if the AUX area mmap buffer contains usefull information. Equally the evlist does not know if the recording is in sanpshot mode anyway.
Consequently, for now just assume the AUX area mmap always has data, which will just cause the mmap buffer to remain mmapped for the duration of the recording.
--- tools/perf/util/evlist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/evlist.c +1 -1
@@ -695,7 +695,7 @@ union perf_event *perf_evlist__mmap_read(struct perf_evlist *evlist, int idx)static bool perf_mmap__empty (struct perf_mmap *md) { -return perf_mmap__read_head (md) == md->prev; +return perf_mmap__read_head (md) == md->prev && !md->auxtrace_mmap.base; }static void perf_evlist__mmap_get (struct perf_evlist *evlist,int idx)
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf evlist: Amend mmap ref counting for the AUX area mmap
perf evlist: Amend mmap ref counting for the AUX area mmap
Commit-ID: b72e74d1f140eb32865540f9e26e9fe0fcf983b9 Gitweb: http://git.kernel.org/tip/b72e74d1f140eb32865540f9e26e9fe0fcf983b9 Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 24 Apr 2015 22:29:43 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 4 May 2015 12:43:48 -0300
perf evlist: Amend mmap ref counting for the AUX area mmap
Reference counting of the mmap buffer does not work correctly when there is an AUX area mmap also.
In snapshot mode it is not easy to know if the AUX area mmap buffer contains usefull information. Equally the evlist does not know if the recording is in sanpshot mode anyway.
Consequently, for now just assume the AUX area mmap always has data, which will just cause the mmap buffer to remain mmapped for the duration of the recording.
--- tools/perf/util/evlist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/evlist.c +1 -1
@@ -695,7 +695,7 @@ union perf_event *perf_evlist__mmap_read(struct perf_evlist *evlist, int idx)static bool perf_mmap__empty (struct perf_mmap *md) { -return perf_mmap__read_head (md) == md->prev; +return perf_mmap__read_head (md) == md->prev && !md->auxtrace_mmap.base; }static void perf_evlist__mmap_get (struct perf_evlist *evlist,int idx)
Adrian Hunter
reviewerPATCH v3 2/25 perf script: Always allow fields 'addr' and 'cpu' for auxtrace
In reply to Adrian HunterIf a file contains AUX area tracing data then always allow fields 'addr' and 'cpu' to be selected as options for perf script. This is necessary because AUX area decoding may synthesize events with that information.
--- tools/perf/builtin-script.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-)
tools/perf/builtin-script.c +22 -7
@@ -148,9 +148,10 @@ static const char *output_field2str(enum perf_output_field field)#define PRINT_FIELD (x) (output[attr->type].fields & PERF_OUTPUT_##x) -static int perf_evsel__check_stype (struct perf_evsel *evsel, -u64 sample_type,const char *sample_msg, -enum perf_output_field field) +static int perf_evsel__do_check_stype (struct perf_evsel *evsel, +u64 sample_type,const char *sample_msg, +enum perf_output_field field, +bool allow_user_set) {struct perf_event_attr *attr = &evsel->attr;int type = attr->type;
@@ -160,6 +161,8 @@ static int perf_evsel__check_stype(struct perf_evsel *evsel,return 0 ;if (output[type].user_set) { +if (allow_user_set) +return 0 ; evname =perf_evsel__name (evsel); pr_err("Samples for '%s' event do not have %s attribute set. " "Cannot print '%s' field.\n",
@@ -177,10 +180,22 @@ static int perf_evsel__check_stype(struct perf_evsel *evsel,return 0 ; } +static int perf_evsel__check_stype (struct perf_evsel *evsel, +u64 sample_type,const char *sample_msg, +enum perf_output_field field) +{ +return perf_evsel__do_check_stype (evsel, sample_type, sample_msg, field, + false); +} +static int perf_evsel__check_attr (struct perf_evsel *evsel,struct perf_session *session) {struct perf_event_attr *attr = &evsel->attr; +bool allow_user_set; + + allow_user_set =perf_header__has_feat (&session->header, +HEADER_AUXTRACE );if (PRINT_FIELD (TRACE ) && !perf_session__has_traces (session,"record -R" ))
@@ -193,8 +208,8 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel, }if (PRINT_FIELD (ADDR ) && -perf_evsel__check_stype (evsel,PERF_SAMPLE_ADDR ,"ADDR" , -PERF_OUTPUT_ADDR )) +perf_evsel__do_check_stype (evsel,PERF_SAMPLE_ADDR ,"ADDR" , +PERF_OUTPUT_ADDR , allow_user_set))return -EINVAL ;if (PRINT_FIELD (SYM ) && !PRINT_FIELD (IP ) && !PRINT_FIELD (ADDR )) {
@@ -231,8 +246,8 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel,return -EINVAL ;if (PRINT_FIELD (CPU ) && -perf_evsel__check_stype (evsel,PERF_SAMPLE_CPU ,"CPU" , -PERF_OUTPUT_CPU )) +perf_evsel__do_check_stype (evsel,PERF_SAMPLE_CPU ,"CPU" , +PERF_OUTPUT_CPU , allow_user_set))return -EINVAL ; if (PRINT_FIELD(PERIOD) &&
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf script: Always allow fields 'addr' and 'cpu' for auxtrace
perf script: Always allow fields 'addr' and 'cpu' for auxtrace
Commit-ID: 6d5cdd64f314e03c8606c777dc44b09769f8e038 Gitweb: http://git.kernel.org/tip/6d5cdd64f314e03c8606c777dc44b09769f8e038 Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 24 Apr 2015 22:29:44 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 4 May 2015 12:43:49 -0300
perf script: Always allow fields 'addr' and 'cpu' for auxtrace
If a file contains AUX area tracing data then always allow fields 'addr' and 'cpu' to be selected as options for perf script. This is necessary because AUX area decoding may synthesize events with that information.
--- tools/perf/builtin-script.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-)
tools/perf/builtin-script.c +22 -7
@@ -148,9 +148,10 @@ static const char *output_field2str(enum perf_output_field field)#define PRINT_FIELD (x) (output[attr->type].fields & PERF_OUTPUT_##x) -static int perf_evsel__check_stype (struct perf_evsel *evsel, -u64 sample_type,const char *sample_msg, -enum perf_output_field field) +static int perf_evsel__do_check_stype (struct perf_evsel *evsel, +u64 sample_type,const char *sample_msg, +enum perf_output_field field, +bool allow_user_set) {struct perf_event_attr *attr = &evsel->attr;int type = attr->type;
@@ -160,6 +161,8 @@ static int perf_evsel__check_stype(struct perf_evsel *evsel,return 0 ;if (output[type].user_set) { +if (allow_user_set) +return 0 ; evname =perf_evsel__name (evsel); pr_err("Samples for '%s' event do not have %s attribute set. " "Cannot print '%s' field.\n",
@@ -177,10 +180,22 @@ static int perf_evsel__check_stype(struct perf_evsel *evsel,return 0 ; } +static int perf_evsel__check_stype (struct perf_evsel *evsel, +u64 sample_type,const char *sample_msg, +enum perf_output_field field) +{ +return perf_evsel__do_check_stype (evsel, sample_type, sample_msg, field, + false); +} +static int perf_evsel__check_attr (struct perf_evsel *evsel,struct perf_session *session) {struct perf_event_attr *attr = &evsel->attr; +bool allow_user_set; + + allow_user_set =perf_header__has_feat (&session->header, +HEADER_AUXTRACE );if (PRINT_FIELD (TRACE ) && !perf_session__has_traces (session,"record -R" ))
@@ -193,8 +208,8 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel, }if (PRINT_FIELD (ADDR ) && -perf_evsel__check_stype (evsel,PERF_SAMPLE_ADDR ,"ADDR" , -PERF_OUTPUT_ADDR )) +perf_evsel__do_check_stype (evsel,PERF_SAMPLE_ADDR ,"ADDR" , +PERF_OUTPUT_ADDR , allow_user_set))return -EINVAL ;if (PRINT_FIELD (SYM ) && !PRINT_FIELD (IP ) && !PRINT_FIELD (ADDR )) {
@@ -231,8 +246,8 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel,return -EINVAL ;if (PRINT_FIELD (CPU ) && -perf_evsel__check_stype (evsel,PERF_SAMPLE_CPU ,"CPU" , -PERF_OUTPUT_CPU )) +perf_evsel__do_check_stype (evsel,PERF_SAMPLE_CPU ,"CPU" , +PERF_OUTPUT_CPU , allow_user_set))return -EINVAL ; if (PRINT_FIELD(PERIOD) &&
Adrian Hunter
reviewerPATCH v3 3/25 perf report: Add Instruction Tracing support
In reply to Adrian HunterAdd support for decoding an AUX area assuming
it contains instruction tracing data.
--- tools/perf/Documentation/perf-report.txt | 27 +++++++++++++++++++++++++++ tools/perf/builtin-report.c | 11 +++++++++++ 2 files changed, 38 insertions(+)
tools/perf/Documentation/perf-report.txt +27 -0
@@ -323,6 +323,33 @@ OPTIONS --header-only:: Show only perf.data header (forces --stdio). +--itrace:: + Options for decoding instruction tracing data. The options are: + + i synthesize instructions events + b synthesize branches events + c synthesize branches events (calls only) + r synthesize branches events (returns only) + e synthesize error events + d create a debug log + g synthesize a call chain for instructions events + + The default is all events i.e. the same as --itrace=ibe + + In addition, the period (default 100000) for instructions events + can be specified in units of: + + i instructions + t ticks + ms milliseconds + us microseconds + ns nanoseconds (default) + + Also the call chain size (default 16, max. 1024) for instructions + events can be specified. + + To disable decoding entirely, use --no-itrace. + SEE ALSO -------- linkperf:perf-stat[1], linkperf:perf-annotate[1]
tools/perf/builtin-report.c +11 -0
@@ -36,6 +36,8 @@#include "util/data.h" #include "arch/common.h" +#include "util/auxtrace.h" +#include <dlfcn.h> #include <linux/bitmap.h>
@@ -585,6 +587,7 @@ parse_percent_limit(const struct option *opt, const char *str,int cmd_report (int argc,const char **argv,const char *prefix__maybe_unused ) {struct perf_session *session; +struct itrace_synth_opts itrace_synth_opts = {0 };struct stat st;bool has_br_stack = false;int branch_mode =-1 ;
@@ -607,6 +610,9 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused) .attr = perf_event__process_attr, .tracing_data = perf_event__process_tracing_data, .build_id = perf_event__process_build_id, + .id_index = perf_event__process_id_index, + .auxtrace_info = perf_event__process_auxtrace_info, + .auxtrace = perf_event__process_auxtrace, .ordered_events = true, .ordering_requires_timestamps = true, },
@@ -717,6 +723,9 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused) "Don't show entries under that percent", parse_percent_limit),OPT_CALLBACK (0 ,"percentage" ,NULL ,"relative|absolute" ,"how to display percentage of filtered entries" , parse_filter_percentage), +OPT_CALLBACK_OPTARG ('Z' ,"itrace" , &itrace_synth_opts,NULL ,"opts" , +"Instruction Tracing options" , + itrace_parse_synth_opts),OPT_END () }; struct perf_data_file file = {
@@ -761,6 +770,8 @@ repeat: report.queue_size); } + session->itrace_synth_opts = &itrace_synth_opts; + report.session = session; has_br_stack = perf_header__has_feat(&session->header,
Signature · 1 line
1.9.1
tip-bot for Adrian Hunter
merge bot[tip:perf/core] perf report: Add Instruction Tracing support
perf report: Add Instruction Tracing support
Commit-ID: 520a2ebc2f0bd46b65feb7ca73a9ed65ea1a36bd Gitweb: http://git.kernel.org/tip/520a2ebc2f0bd46b65feb7ca73a9ed65ea1a36bd Author: Adrian Hunter <[email protected]> AuthorDate: Fri, 24 Apr 2015 22:29:45 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 4 May 2015 12:43:50 -0300
perf report: Add Instruction Tracing support
Add support for decoding an AUX area assuming it contains instruction tracing data.
--- tools/perf/Documentation/perf-report.txt | 27 +++++++++++++++++++++++++++ tools/perf/builtin-report.c | 11 +++++++++++ 2 files changed, 38 insertions(+)
tools/perf/Documentation/perf-report.txt +27 -0
@@ -327,6 +327,33 @@ OPTIONS include::callchain-overhead-calculation.txt[] +--itrace:: + Options for decoding instruction tracing data. The options are: + + i synthesize instructions events + b synthesize branches events + c synthesize branches events (calls only) + r synthesize branches events (returns only) + e synthesize error events + d create a debug log + g synthesize a call chain for instructions events + + The default is all events i.e. the same as --itrace=ibe + + In addition, the period (default 100000) for instructions events + can be specified in units of: + + i instructions + t ticks + ms milliseconds + us microseconds + ns nanoseconds (default) + + Also the call chain size (default 16, max. 1024) for instructions + events can be specified. + + To disable decoding entirely, use --no-itrace. + SEE ALSO -------- linkperf:perf-stat[1], linkperf:perf-annotate[1]
tools/perf/builtin-report.c +11 -0
@@ -36,6 +36,8 @@#include "util/data.h" #include "arch/common.h" +#include "util/auxtrace.h" +#include <dlfcn.h> #include <linux/bitmap.h>
@@ -585,6 +587,7 @@ parse_percent_limit(const struct option *opt, const char *str,int cmd_report (int argc,const char **argv,const char *prefix__maybe_unused ) {struct perf_session *session; +struct itrace_synth_opts itrace_synth_opts = { .set =0 , };struct stat st;bool has_br_stack = false;int branch_mode =-1 ;
@@ -607,6 +610,9 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused) .attr = perf_event__process_attr, .tracing_data = perf_event__process_tracing_data, .build_id = perf_event__process_build_id, + .id_index = perf_event__process_id_index, + .auxtrace_info = perf_event__process_auxtrace_info, + .auxtrace = perf_event__process_auxtrace, .ordered_events = true, .ordering_requires_timestamps = true, },
@@ -717,6 +723,9 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused) "Don't show entries under that percent", parse_percent_limit),OPT_CALLBACK (0 ,"percentage" ,NULL ,"relative|absolute" ,"how to display percentage of filtered entries" , parse_filter_percentage), +OPT_CALLBACK_OPTARG (0 ,"itrace" , &itrace_synth_opts,NULL ,"opts" , +"Instruction Tracing options" , + itrace_parse_synth_opts),OPT_END () }; struct perf_data_file file = {
@@ -761,6 +770,8 @@ repeat: report.queue_size); } + session->itrace_synth_opts = &itrace_synth_opts; + report.session = session; has_br_stack = perf_header__has_feat(&session->header,
Adrian Hunter
reviewerPATCH v3 4/25 perf tools: Add AUX area tracing index
In reply to Adrian HunterAdd an index of AUX area tracing events within a perf.data file.
perf record uses a special user event PERF_RECORD_FINISHED_ROUND to enable sorting of events in chunks instead of having to sort all events altogether.
AUX area tracing events contain data that can span back to the very beginning of the recording period. i.e. they do not obey the rules of PERF_RECORD_FINISHED_ROUND.
By adding an index, AUX area tracing events can be found in advance and the PERF_RECORD_FINISHED_ROUND approach works as usual.
The index is recorded with the auxtrace feature in the perf.data file. A session reads the index but does not process it. An AUX area decoder can queue all the AUX area data in advance using auxtrace_queues__process_index() or otherwise process the index in some custom manner.
--- tools/perf/builtin-inject.c | 15 +++ tools/perf/builtin-record.c | 15 +++ tools/perf/util/auxtrace.c | 216 ++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/auxtrace.h | 35 +++++++ tools/perf/util/header.c | 31 ++++++- tools/perf/util/session.c | 2 + tools/perf/util/session.h | 1 + 7 files changed, 311 insertions(+), 4 deletions(-)
tools/perf/builtin-inject.c +15 -0
@@ -122,6 +122,18 @@ static s64 perf_event__repipe_auxtrace(struct perf_tool *tool, tool);int ret; +if (!inject->output.is_pipe) { +off_t offset; + + offset =lseek (inject->output.fd,0 ,SEEK_CUR ); +if (offset ==-1 ) +return -errno; + ret =auxtrace_index__auxtrace_event (&session->auxtrace_index, + event, offset); +if (ret <0 ) +return ret; + } +if (perf_data_file__is_pipe (session->file) || !session->one_mmap) { ret =output_bytes (inject, event, event->header.size);if (ret <0 )
@@ -487,6 +499,9 @@ static int __cmd_inject(struct perf_inject *inject) output_data_offset =4096 ; } +if (!inject->itrace_synth_opts.set) +auxtrace_index__free (&session->auxtrace_index); +if (!file_out->is_pipe)lseek (fd, output_data_offset,SEEK_SET );
tools/perf/builtin-record.c +15 -0
@@ -117,9 +117,24 @@ static int record__process_auxtrace(struct perf_tool *tool, size_t len1, void *data2, size_t len2) { struct record *rec = container_of(tool, struct record, tool); +struct perf_data_file *file = &rec->file;size_t padding;u8 pad[8 ] = {0 }; +if (!perf_data_file__is_pipe (file)) { +off_t file_offset; +int fd =perf_data_file__fd (file); +int err; + + file_offset =lseek (fd,0 ,SEEK_CUR ); +if (file_offset ==-1 ) +return -1 ; + err =auxtrace_index__auxtrace_event (&rec->session->auxtrace_index, + event, file_offset); +if (err) +return err; + } +/* event.auxtrace.size includes padding, see __auxtrace_mmap__read() */ padding = (len1 + len2) &7 ;if (padding)
tools/perf/util/auxtrace.c +216 -0
228 lines not on this page · raw message
tools/perf/util/auxtrace.h +35 -0
@@ -80,6 +80,32 @@ struct itrace_synth_opts { };/** +* struct auxtrace_index_entry - indexes a AUX area tracing event within a +* perf.data file. +* @file_offset: offset within the perf.data file +* @sz: size of the event +*/ +struct auxtrace_index_entry { +u64 file_offset; +u64 sz; +}; + +#define PERF_AUXTRACE_INDEX_ENTRY_COUNT 256 + +/** +* struct auxtrace_index - index of AUX area tracing events within a perf.data +* file. +* @list: linking a number of arrays of entries +* @nr: number of entries +* @entries: array of entries +*/ +struct auxtrace_index { +struct list_head list; +size_t nr; +struct auxtrace_index_entry entries[PERF_AUXTRACE_INDEX_ENTRY_COUNT ]; +}; + +/** * struct auxtrace - session callbacks to allow AUX area data decoding. * @process_event: lets the decoder see all session events * @flush_events: process any remaining data
@@ -321,6 +347,8 @@ int auxtrace_queues__add_event(struct auxtrace_queues *queues, union perf_event *event, off_t data_offset, struct auxtrace_buffer **buffer_ptr);void auxtrace_queues__free (struct auxtrace_queues *queues); +int auxtrace_queues__process_index (struct auxtrace_queues *queues, +struct perf_session *session);struct auxtrace_buffer *auxtrace_buffer__next (struct auxtrace_queue *queue,struct auxtrace_buffer *buffer);void *auxtrace_buffer__get_data (struct auxtrace_buffer *buffer,int fd);
@@ -361,6 +389,13 @@ int auxtrace_record__info_fill(struct auxtrace_record *itr,void auxtrace_record__free (struct auxtrace_record *itr);u64 auxtrace_record__reference (struct auxtrace_record *itr); +int auxtrace_index__auxtrace_event (struct list_head *head,union perf_event *event, +off_t file_offset); +int auxtrace_index__write (int fd,struct list_head *head); +int auxtrace_index__process (int fd,u64 size,struct perf_session *session, +bool needs_swap); +void auxtrace_index__free (struct list_head *head); +void auxtrace_synth_error (struct auxtrace_error_event *auxtrace_error,int type,int code,int cpu,pid_t pid,pid_t tid,u64 ip,const char *msg);
tools/perf/util/header.c +27 -4
@@ -869,11 +869,18 @@ static int write_branch_stack(int fd __maybe_unused,return 0 ; } -static int write_auxtrace (int fd__maybe_unused , -struct perf_header *h__maybe_unused , +static int write_auxtrace (int fd,struct perf_header *h,struct perf_evlist *evlist__maybe_unused ) { -return 0 ; +struct perf_session *session; +int err; + + session = container_of(h, struct perf_session, header); + + err =auxtrace_index__write (fd, &session->auxtrace_index); +if (err <0 ) +pr_err ("Failed to write auxtrace index\n" ); +return err; } static void print_hostname(struct perf_header *ph, int fd __maybe_unused,
@@ -1834,6 +1841,22 @@ out_free:return ret; } +static int process_auxtrace (struct perf_file_section *section, +struct perf_header *ph,int fd, +void *data__maybe_unused ) +{ +struct perf_session *session; +int err; + + session = container_of(ph, struct perf_session, header); + + err =auxtrace_index__process (fd, section->size, session, + ph->needs_swap); +if (err <0 ) +pr_err ("Failed to process auxtrace index\n" ); +return err; +} +struct feature_ops {int (*write)(int fd,struct perf_header *h,struct perf_evlist *evlist);void (*print)(struct perf_header *h,int fd,FILE *fp);
@@ -1874,7 +1897,7 @@ static const struct feature_ops feat_ops[HEADER_LAST_FEATURE] = {FEAT_OPA (HEADER_BRANCH_STACK , branch_stack),FEAT_OPP (HEADER_PMU_MAPPINGS , pmu_mappings),FEAT_OPP (HEADER_GROUP_DESC , group_desc), - FEAT_OPA(HEADER_AUXTRACE, auxtrace), + FEAT_OPP(HEADER_AUXTRACE, auxtrace), }; struct header_print_data {
tools/perf/util/session.c +2 -0
@@ -120,6 +120,7 @@ struct perf_session *perf_session__new(struct perf_data_file *file, session->repipe = repipe; session->tool = tool; +INIT_LIST_HEAD (&session->auxtrace_index);machines__init (&session->machines);ordered_events__init (&session->ordered_events, ordered_events__deliver_event);
@@ -187,6 +188,7 @@ static void perf_session_env__delete(struct perf_session_env *env)void perf_session__delete (struct perf_session *session) {auxtrace__free (session); +auxtrace_index__free (&session->auxtrace_index);perf_session__destroy_kernel_maps (session);perf_session__delete_threads (session);perf_session_env__delete (&session->header.env);
tools/perf/util/session.h +1 -0
@@ -24,6 +24,7 @@ struct perf_session {struct perf_evlist *evlist;struct auxtrace *auxtrace;struct itrace_synth_opts *itrace_synth_opts; +struct list_head auxtrace_index;struct trace_event tevent;bool repipe;bool one_mmap;
Signature · 1 line
1.9.1
Re: [PATCH V3 04/25] perf tools: Add AUX area tracing index
On Fri, Apr 24, 2015 at 10:29:46PM +0300, Adrian Hunter wrote:
SNIP
Quoted 5 lines
tools/perf/util/auxtrace.c +5
-0+ +int auxtrace_index__process (int fd,u64 size,struct perf_session *session, +bool needs_swap) +{ +struct list_head *head = &session->auxtrace_index;
tools/perf/util/auxtrace.c auxtrace_record__init(struct perf_evlist *evlist __maybe_unused, int *err) · line 676
Quoted 10 lines
tools/perf/util/auxtrace.c +10
-0+u64 nr; + +if (readn (fd, &nr,sizeof (u64)) !=sizeof (u64)) +return -1 ; + +if (needs_swap) + nr =bswap_64 (nr); + +if (sizeof (u64) + nr *sizeof (struct auxtrace_index_entry ) != size) +return -1 ;
so the total nr is only used to double check the data size is correct, it could be omited and you could use just the size of the section.. also the auxtrace_index__write would be shorter of one loop
but no big deal.. just asking ;-)
jirka
Adrian Hunter
reviewerRe: [PATCH V3 04/25] perf tools: Add AUX area tracing index
Quoted 24 lines · Jiri Olsa
On Fri, Apr 24, 2015 at 10:29:46PM +0300, Adrian Hunter wrote:
SNIP
Quoted 5 lines
tools/perf/util/auxtrace.c +5
-0+ +int auxtrace_index__process (int fd,u64 size,struct perf_session *session, +bool needs_swap) +{ +struct list_head *head = &session->auxtrace_index;tools/perf/util/auxtrace.c auxtrace_record__init(struct perf_evlist *evlist __maybe_unused, int *err) · line 676
Quoted 10 lines
tools/perf/util/auxtrace.c +10
-0+u64 nr; + +if (readn (fd, &nr,sizeof (u64)) !=sizeof (u64)) +return -1 ; + +if (needs_swap) + nr =bswap_64 (nr); + +if (sizeof (u64) + nr *sizeof (struct auxtrace_index_entry ) != size) +return -1 ;so the total nr is only used to double check the data size is correct, it could be omited and you could use just the size of the section.. also the
auxtrace_index__writewould be shorter of one loop
Quoted 1 line
but no big deal.. just asking ;-)
I would like to have it as a check that the file structure is the way it is meant to be.
Also I will change it to " > size" so that more stuff can be added to the section in the future.
Re: [PATCH V3 04/25] perf tools: Add AUX area tracing index
In reply to Adrian HunterOn Fri, Apr 24, 2015 at 10:29:46PM +0300, Adrian Hunter wrote:
SNIP
Quoted 13 lines
tools/perf/util/auxtrace.c +7
-0@@ -344,6 +344,33 @@ out_err:return err; } +static int auxtrace_queues__add_indexed_event (struct auxtrace_queues *queues, +struct perf_session *session, +off_t file_offset,size_t sz) +{ +union perf_event *event; +int err; +char buf[PERF_SAMPLE_MAX_SIZE ];
tools/perf/util/auxtrace.c out_err: · line 363
Quoted 10 lines
tools/perf/util/auxtrace.c +10
-0+ + err =perf_session__peek_event (session, file_offset, buf, +PERF_SAMPLE_MAX_SIZE , &event,NULL ); +if (err) +return err; + +if (event->header.type ==PERF_RECORD_AUXTRACE ) { +if (event->header.size !=sizeof (struct auxtrace_event ) || + event->header.size != sz) { + err = -EINVAL ;
getting lost in here
as per auxtrace_mmap__read it looks like we store PERF_RECORD_AUXTRACE event with:
ev.auxtrace.header.size = sizeof(ev.auxtrace);
and it's followed with more data with size:
ev.auxtrace.size = size + padding;
so why the check for 'event->header.size != sz' ?
jirka
Quoted 9 lines
tools/perf/util/auxtrace.c +9
-0+ goto out; + } + file_offset += event->header.size; + err =auxtrace_queues__add_event (queues, session, event, + file_offset,NULL ); + } +out: +return err; +}
SNIP
Adrian Hunter
reviewerRe: [PATCH V3 04/25] perf tools: Add AUX area tracing index
Quoted 30 lines · Jiri Olsa
On Fri, Apr 24, 2015 at 10:29:46PM +0300, Adrian Hunter wrote:
SNIP
Quoted 13 lines
tools/perf/util/auxtrace.c +7
-0@@ -344,6 +344,33 @@ out_err:return err; } +static int auxtrace_queues__add_indexed_event (struct auxtrace_queues *queues, +struct perf_session *session, +off_t file_offset,size_t sz) +{ +union perf_event *event; +int err; +char buf[PERF_SAMPLE_MAX_SIZE ];tools/perf/util/auxtrace.c out_err: · line 363
Quoted 10 lines
tools/perf/util/auxtrace.c +10
-0+ + err =perf_session__peek_event (session, file_offset, buf, +PERF_SAMPLE_MAX_SIZE , &event,NULL ); +if (err) +return err; + +if (event->header.type ==PERF_RECORD_AUXTRACE ) { +if (event->header.size !=sizeof (struct auxtrace_event ) || + event->header.size != sz) { + err = -EINVAL ;getting lost in here
Quoted 7 lines
as per
auxtrace_mmap__readit looks like we storePERF_RECORD_AUXTRACEevent with:ev.auxtrace.header.size = sizeof(ev.auxtrace);and it's followed with more data with size:
ev.auxtrace.size = size + padding;so why the check for '
event->header.size!= sz' ?
It checks the consistency of the file structure.
But it seems to me that the previous check could be:
event->header.size < sizeof(struct auxtrace_event)
which would allow for the event being made bigger in a backward compatible way.
Quoted 16 lines
jirka
Quoted 9 lines
tools/perf/util/auxtrace.c +9
-0+ goto out; + } + file_offset += event->header.size; + err =auxtrace_queues__add_event (queues, session, event, + file_offset,NULL ); + } +out: +return err; +}SNIP
Adrian Hunter
reviewerPATCH v3 5/25 perf tools: Hit all build ids when AUX area tracing
In reply to Adrian HunterWe need to include all buildids when a perf.data file contains AUX area tracing data because we do not decode the trace for that purpose because it would take too long.
--- tools/perf/builtin-buildid-list.c | 9 +++++++++ tools/perf/builtin-inject.c | 8 +++++++- tools/perf/builtin-record.c | 10 +++++++++- 3 files changed, 25 insertions(+), 2 deletions(-)
tools/perf/builtin-buildid-list.c +9 -0
@@ -69,6 +69,15 @@ static int perf_session__list_build_ids(bool force, bool with_hits) session =perf_session__new (&file, false, &build_id__mark_dso_hit_ops);if (session ==NULL )return -1 ; + +/* +* We take all buildids when the file contains AUX area tracing data +* because we do not decode the trace because it would take too long. +*/ +if (!perf_data_file__is_pipe (&file) && +perf_header__has_feat (&session->header,HEADER_AUXTRACE )) + with_hits = false; +/* * in pipe-mode, the only way to get the buildids is to parse * the record stream. Buildids are stored as RECORD_HEADER_BUILD_ID
tools/perf/builtin-inject.c +7 -1
@@ -27,6 +27,7 @@ struct perf_inject {struct perf_session *session;bool build_ids;bool sched_stat; +bool have_auxtrace;const char *input_name;struct perf_data_file output;u64 bytes_written;
@@ -122,6 +123,8 @@ static s64 perf_event__repipe_auxtrace(struct perf_tool *tool, tool);int ret; + inject->have_auxtrace = true; +if (!inject->output.is_pipe) {off_t offset;
@@ -508,9 +511,12 @@ static int __cmd_inject(struct perf_inject *inject) ret =perf_session__process_events (session);if (!file_out->is_pipe) { -if (inject->build_ids) +if (inject->build_ids) {perf_header__set_feat (&session->header,HEADER_BUILD_ID ); +if (inject->have_auxtrace) +dsos__hit_all (session); + }/* * The AUX areas have been removed and replaced with * synthesized hardware events, so clear the feature flag.
tools/perf/builtin-record.c +9 -1
@@ -620,8 +620,16 @@ out_child:if (!err && !file->is_pipe) { rec->session->header.data_size += rec->bytes_written; -if (!rec->no_buildid) +if (!rec->no_buildid) {process_buildids (rec); +/* +* We take all buildids when the file contains +* AUX area tracing data because we do not decode the +* trace because it would take too long. +*/ +if (rec->opts.full_auxtrace) +dsos__hit_all (rec->session); + }perf_session__write_header (rec->session, rec->evlist, fd, true); }
Signature · 1 line
1.9.1
Re: [PATCH V3 05/25] perf tools: Hit all build ids when AUX area tracing
Quoted 18 lines · Adrian Hunter
We need to include all buildids when a perf.data file contains AUX area tracing data because we do not decode the trace for that purpose because it would take too long.
Signed-off-by Adrian Hunter <[email protected]>--- tools/perf/builtin-buildid-list.c | 9 +++++++++ tools/perf/builtin-inject.c | 8 +++++++- tools/perf/builtin-record.c | 10 +++++++++- 3 files changed, 25 insertions(+), 2 deletions(-)tools/perf/builtin-buildid-list.c +0
-0@@ -69,6 +69,15 @@ static int perf_session__list_build_ids(bool force, bool with_hits) session =perf_session__new (&file, false, &build_id__mark_dso_hit_ops);
tools/perf/builtin-buildid-list.c static int perf_session__list_build_ids(bool force, bool with_hits) · line 79
Quoted 10 lines
tools/perf/builtin-buildid-list.c +8
-0if (session ==NULL )return -1 ; + +/* +* We take all buildids when the file contains AUX area tracing data +* because we do not decode the trace because it would take too long. +*/ +if (!perf_data_file__is_pipe (&file) && +perf_header__has_feat (&session->header,HEADER_AUXTRACE )) + with_hits = false;
when there's auxtrace in the perf.data, all the dsos would have hits (as per builtin-record.c change below) and be display anyway, so it seems we dont need this hunk?
jirka
SNIP
Quoted 26 lines
tools/perf/builtin-buildid-list.c +0
-0* synthesized hardware events, so clear the feature flag. tools/perf/builtin-record.c +9
-1@@ -620,8 +620,16 @@ out_child:if (!err && !file->is_pipe) { rec->session->header.data_size += rec->bytes_written; -if (!rec->no_buildid) +if (!rec->no_buildid) {process_buildids (rec); +/* +* We take all buildids when the file contains +* AUX area tracing data because we do not decode the +* trace because it would take too long. +*/ +if (rec->opts.full_auxtrace) +dsos__hit_all (rec->session); + }perf_session__write_header (rec->session, rec->evlist, fd, true); }Signature · 1 line
1.9.1
Adrian Hunter
reviewerRe: [PATCH V3 05/25] perf tools: Hit all build ids when AUX area tracing
Quoted 25 lines · Jiri Olsa
Quoted 24 lines · Adrian Hunter
We need to include all buildids when a perf.data file contains AUX area tracing data because we do not decode the trace for that purpose because it would take too long.
Signed-off-by Adrian Hunter <[email protected]>--- tools/perf/builtin-buildid-list.c | 9 +++++++++ tools/perf/builtin-inject.c | 8 +++++++- tools/perf/builtin-record.c | 10 +++++++++- 3 files changed, 25 insertions(+), 2 deletions(-)tools/perf/builtin-buildid-list.c +4
-0@@ -69,6 +69,15 @@ static int perf_session__list_build_ids(bool force, bool with_hits) session =perf_session__new (&file, false, &build_id__mark_dso_hit_ops);if (session ==NULL )return -1 ; + +/* +* We take all buildids when the file contains AUX area tracing data +* because we do not decode the trace because it would take too long.
Quoted 8 lines
tools/perf/builtin-buildid-list.c static int perf_session__list_build_ids(bool force, bool with_hits) · line 79
Quoted 4 lines
tools/perf/builtin-buildid-list.c +4
-0+*/ +if (!perf_data_file__is_pipe (&file) && +perf_header__has_feat (&session->header,HEADER_AUXTRACE )) + with_hits = false;when there's auxtrace in the perf.data, all the dsos would have hits (as per
builtin-record.cchange below) and be display anyway, so it seems we dont need this hunk?
When there's auxtrace in the perf.data file, then all dsos would be recorded with build ids in the build_id section.
This hunk causes:
1) no session processing to find hits
2) print all even if they have no hits
Quoted 33 lines
jirka
SNIP
Quoted 26 lines
tools/perf/builtin-buildid-list.c +0
-0* synthesized hardware events, so clear the feature flag. tools/perf/builtin-record.c +9
-1@@ -620,8 +620,16 @@ out_child:if (!err && !file->is_pipe) { rec->session->header.data_size += rec->bytes_written; -if (!rec->no_buildid) +if (!rec->no_buildid) {process_buildids (rec); +/* +* We take all buildids when the file contains +* AUX area tracing data because we do not decode the +* trace because it would take too long. +*/ +if (rec->opts.full_auxtrace) +dsos__hit_all (rec->session); + }perf_session__write_header (rec->session, rec->evlist, fd, true); }Signature · 1 line
1.9.1
Re: [PATCH V3 05/25] perf tools: Hit all build ids when AUX area tracing
Quoted 35 lines · Adrian Hunter
Quoted 25 lines · Jiri Olsa
Quoted 24 lines · Adrian Hunter
We need to include all buildids when a perf.data file contains AUX area tracing data because we do not decode the trace for that purpose because it would take too long.
Signed-off-by Adrian Hunter <[email protected]>--- tools/perf/builtin-buildid-list.c | 9 +++++++++ tools/perf/builtin-inject.c | 8 +++++++- tools/perf/builtin-record.c | 10 +++++++++- 3 files changed, 25 insertions(+), 2 deletions(-)tools/perf/builtin-buildid-list.c +4
-0@@ -69,6 +69,15 @@ static int perf_session__list_build_ids(bool force, bool with_hits) session =perf_session__new (&file, false, &build_id__mark_dso_hit_ops);if (session ==NULL )return -1 ; + +/* +* We take all buildids when the file contains AUX area tracing data +* because we do not decode the trace because it would take too long. Quoted 8 lines
tools/perf/builtin-buildid-list.c static int perf_session__list_build_ids(bool force, bool with_hits) · line 79
Quoted 4 lines
tools/perf/builtin-buildid-list.c +4
-0+*/ +if (!perf_data_file__is_pipe (&file) && +perf_header__has_feat (&session->header,HEADER_AUXTRACE )) + with_hits = false;when there's auxtrace in the perf.data, all the dsos would have hits (as per
builtin-record.cchange below) and be display anyway, so it seems we dont need this hunk?
Quoted 5 lines
When there's auxtrace in the perf.data file, then all dsos would be recorded with build ids in the
build_idsection.This hunk causes:
1) no session processing to find hits
ok, missed the perf_session__process_events call in here :-\
jirka
Adrian Hunter
reviewerPATCH v3 6/25 perf tools: Add build option NO_AUXTRACE to exclude AUX area tracing
In reply to Adrian HunterAdd build option NO_AUXTRACE to exclude compiling support for AUX area tracing. Support for both recording and processing is excluded and by implication any future additions such as Intel PT and Intel BTS will also not be compiled in with this option.
--- tools/perf/Makefile.perf | 2 + tools/perf/builtin-inject.c | 53 +++++++++++------- tools/perf/builtin-record.c | 13 +++++ tools/perf/config/Makefile | 5 ++ tools/perf/tests/make | 2 + tools/perf/util/Build | 2 +- tools/perf/util/auxtrace.h | 128 ++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 185 insertions(+), 20 deletions(-)
tools/perf/Makefile.perf +2 -0
@@ -73,6 +73,8 @@ include config/utilities.mak # for CTF data format. # # Define NO_LZMA if you do not want to support compressed (xz) kernel modules +# +# Define NO_AUXTRACE if you do not want AUX area tracing support ifeq ($(srctree),) srctree := $(patsubst %/,%,$(dir $(shell pwd)))
tools/perf/builtin-inject.c +34 -19
71 lines not on this page · raw message
tools/perf/builtin-record.c +13 -0
@@ -112,6 +112,8 @@ out:return rc; } +#ifdef HAVE_AUXTRACE_SUPPORT +static int record__process_auxtrace (struct perf_tool *tool,union perf_event *event,void *data1,size_t len1,void *data2,size_t len2)
@@ -165,6 +167,17 @@ static int record__auxtrace_mmap_read(struct record *rec, return 0; } +#else + +static inline +int record__auxtrace_mmap_read (struct record *rec__maybe_unused , +struct auxtrace_mmap *mm__maybe_unused ) +{ +return 0 ; +} + +#endif +static volatile int done =0 ;static volatile int signr =-1 ;static volatile int child_finished =0 ;
tools/perf/config/Makefile +5 -0
@@ -610,6 +610,11 @@ ifdef LIBBABELTRACE endif endif +ifndef NO_AUXTRACE + $(call detected,CONFIG_AUXTRACE) + CFLAGS += -DHAVE_AUXTRACE_SUPPORT +endif + # Among the variables below, these: # perfexecdir # template_dir
tools/perf/tests/make +2 -0
@@ -32,6 +32,7 @@ make_no_backtrace := NO_BACKTRACE=1 make_no_libnuma := NO_LIBNUMA=1 make_no_libaudit := NO_LIBAUDIT=1 make_no_libbionic := NO_LIBBIONIC=1 +make_no_auxtrace := NO_AUXTRACE=1 make_tags := tags make_cscope := cscope make_help := help
@@ -74,6 +75,7 @@ run += make_no_backtrace run += make_no_libnuma run += make_no_libaudit run += make_no_libbionic +run += make_no_auxtrace run += make_help run += make_doc run += make_perf_o
tools/perf/util/Build +1 -1
@@ -74,7 +74,7 @@ libperf-y += data.o libperf-$(CONFIG_X86) += tsc.o libperf-y += cloexec.o libperf-y += thread-stack.o -libperf-y += auxtrace.o +libperf-$(CONFIG_AUXTRACE) += auxtrace.o libperf-$(CONFIG_LIBELF) += symbol-elf.o libperf-$(CONFIG_LIBELF) += probe-event.o
tools/perf/util/auxtrace.h +128 -0
144 lines not on this page · raw message
Signature · 1 line
1.9.1
Re: [PATCH V3 06/25] perf tools: Add build option NO_AUXTRACE to exclude AUX area tracing
On Fri, Apr 24, 2015 at 10:29:48PM +0300, Adrian Hunter wrote:
SNIP
tools/perf/tests/make make_no_backtrace := NO_BACKTRACE=1 · line 35
Quoted 9 lines
tools/perf/tests/make +1
-0@@ -32,6 +32,7 @@ make_no_backtrace := NO_BACKTRACE=1 make_no_libnuma := NO_LIBNUMA=1 make_no_libaudit := NO_LIBAUDIT=1 make_no_libbionic := NO_LIBBIONIC=1 +make_no_auxtrace := NO_AUXTRACE=1
extra spaces ^^
tools/perf/tests/make run += make_no_backtrace · line 81
Quoted 11 lines
tools/perf/tests/make +1
-0make_tags := tags make_cscope := cscope make_help := help@@ -74,6 +75,7 @@ run += make_no_backtrace run += make_no_libnuma run += make_no_libaudit run += make_no_libbionic +run += make_no_auxtrace run += make_help run += make_doc run += make_perf_o
eeeey!! test update ;-)
please update also make_minimal test
thanks,
jirka
Adrian Hunter
reviewerPATCH v3 7/25 perf auxtrace: Add option to synthesize events for transactions
In reply to Adrian HunterAdd AUX area tracing option 'x' to synthesize events for transactions. This will be used by Intel PT to synthesize an event record for each TSX start, commit or abort.
--- tools/perf/Documentation/perf-inject.txt | 9 +++++---- tools/perf/Documentation/perf-report.txt | 9 +++++---- tools/perf/Documentation/perf-script.txt | 9 +++++---- tools/perf/util/auxtrace.c | 5 ++++- tools/perf/util/auxtrace.h | 2 ++ 5 files changed, 21 insertions(+), 13 deletions(-)
tools/perf/Documentation/perf-inject.txt +5 -4
@@ -52,11 +52,12 @@ OPTIONS b synthesize branches events c synthesize branches events (calls only) r synthesize branches events (returns only) + x synthesize transactions events e synthesize error events d create a debug log - g synthesize a call chain for instructions events + g synthesize a call chain (use with i or x) - The default is all events i.e. the same as --itrace=ibe + The default is all events i.e. the same as --itrace=ibxe In addition, the period (default 100000) for instructions events can be specified in units of:
@@ -67,8 +68,8 @@ OPTIONS us microseconds ns nanoseconds (default) - Also the call chain size (default 16, max. 1024) for instructions - events can be specified. + Also the call chain size (default 16, max. 1024) for instructions or + transactions events can be specified. SEE ALSO --------
tools/perf/Documentation/perf-report.txt +5 -4
@@ -330,11 +330,12 @@ OPTIONS b synthesize branches events c synthesize branches events (calls only) r synthesize branches events (returns only) + x synthesize transactions events e synthesize error events d create a debug log - g synthesize a call chain for instructions events + g synthesize a call chain (use with i or x) - The default is all events i.e. the same as --itrace=ibe + The default is all events i.e. the same as --itrace=ibxe In addition, the period (default 100000) for instructions events can be specified in units of:
@@ -345,8 +346,8 @@ OPTIONS us microseconds ns nanoseconds (default) - Also the call chain size (default 16, max. 1024) for instructions - events can be specified. + Also the call chain size (default 16, max. 1024) for instructions or + transactions events can be specified. To disable decoding entirely, use --no-itrace.
tools/perf/Documentation/perf-script.txt +5 -4
@@ -235,11 +235,12 @@ OPTIONS b synthesize branches events c synthesize branches events (calls only) r synthesize branches events (returns only) + x synthesize transactions events e synthesize error events d create a debug log - g synthesize a call chain for instructions events + g synthesize a call chain (use with i or x) - The default is all events i.e. the same as --itrace=ibe + The default is all events i.e. the same as --itrace=ibxe In addition, the period (default 100000) for instructions events can be specified in units of:
@@ -250,8 +251,8 @@ OPTIONS us microseconds ns nanoseconds (default) - Also the call chain size (default 16, max. 1024) for instructions - events can be specified. + Also the call chain size (default 16, max. 1024) for instructions or + transactions events can be specified. To disable decoding entirely, use --no-itrace.
tools/perf/util/auxtrace.c +4 -1
@@ -889,6 +889,7 @@ void itrace_synth_opts__set_default(struct itrace_synth_opts *synth_opts) { synth_opts->instructions = true; synth_opts->branches = true; + synth_opts->transactions = true; synth_opts->errors = true; synth_opts->period_type =PERF_ITRACE_DEFAULT_PERIOD_TYPE ; synth_opts->period =PERF_ITRACE_DEFAULT_PERIOD ;
@@ -961,6 +962,9 @@ int itrace_parse_synth_opts(const struct option *opt, const char *str,case 'b' : synth_opts->branches = true;break ; +case 'x' : + synth_opts->transactions = true; +break ;case 'e' : synth_opts->errors = true;break ;
@@ -976,7 +980,6 @@ int itrace_parse_synth_opts(const struct option *opt, const char *str, synth_opts->returns = true;break ;case 'g' : - synth_opts->instructions = true; synth_opts->callchain = true; synth_opts->callchain_sz =PERF_ITRACE_DEFAULT_CALLCHAIN_SZ ;
tools/perf/util/auxtrace.h +2 -0
@@ -54,6 +54,7 @@ enum itrace_period_type {* because 'perf inject' will write it out * @instructions: whether to synthesize 'instructions' events * @branches: whether to synthesize 'branches' events +* @transactions: whether to synthesize events for transactions * @errors: whether to synthesize decoder error events * @dont_decode: whether to skip decoding entirely * @log: write a decoding log
@@ -69,6 +70,7 @@ struct itrace_synth_opts {bool inject;bool instructions;bool branches; +bool transactions;bool errors;bool dont_decode;bool log;
Signature · 1 line
1.9.1
Re: [PATCH V3 07/25] perf auxtrace: Add option to synthesize events for transactions
Quoted 33 lines · Adrian Hunter
Add AUX area tracing option 'x' to synthesize events for transactions. This will be used by Intel PT to synthesize an event record for each TSX start, commit or abort.
Signed-off-by Adrian Hunter <[email protected]>--- tools/perf/Documentation/perf-inject.txt | 9 +++++---- tools/perf/Documentation/perf-report.txt | 9 +++++---- tools/perf/Documentation/perf-script.txt | 9 +++++---- tools/perf/util/auxtrace.c | 5 ++++- tools/perf/util/auxtrace.h | 2 ++ 5 files changed, 21 insertions(+), 13 deletions(-)tools/perf/Documentation/perf-inject.txt +3
-2@@ -52,11 +52,12 @@ OPTIONS b synthesize branches events c synthesize branches events (calls only) r synthesize branches events (returns only) + x synthesize transactions events e synthesize error events d create a debug log - g synthesize a call chain for instructions events + g synthesize a call chain (use with i or x) - The default is all events i.e. the same as --itrace=ibe + The default is all events i.e. the same as --itrace=ibxe In addition, the period (default 100000) for instructions events can be specified in units of:
tools/perf/Documentation/perf-inject.txt OPTIONS · line 72
Quoted 7 lines
tools/perf/Documentation/perf-inject.txt +2
-2@@ -67,8 +68,8 @@ OPTIONS us microseconds ns nanoseconds (default) - Also the call chain size (default 16, max. 1024) for instructions - events can be specified. + Also the call chain size (default 16, max. 1024) for instructions or + transactions events can be specified.
Do you want to carry on with updating 3 places of the same doc? I wonder it'd be better to have perf-auxtrace.txt for auxtrace details.
jirka
Adrian Hunter
reviewerPATCH v3 8/25 perf tools: Add support for PERF_RECORD_AUX
In reply to Adrian HunterAdd support for the PERF_RECORD_AUX event type.
--- tools/perf/builtin-inject.c | 1 + tools/perf/util/event.c | 21 +++++++++++++++++++++ tools/perf/util/event.h | 13 +++++++++++++ tools/perf/util/machine.c | 10 ++++++++++ tools/perf/util/machine.h | 2 ++ tools/perf/util/session.c | 15 +++++++++++++++ tools/perf/util/tool.h | 1 + 7 files changed, 63 insertions(+)
tools/perf/builtin-inject.c +1 -0
@@ -558,6 +558,7 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused) .fork = perf_event__repipe, .exit = perf_event__repipe, .lost = perf_event__repipe, + .aux = perf_event__repipe, .read = perf_event__repipe_sample, .throttle = perf_event__repipe, .unthrottle = perf_event__repipe,
tools/perf/util/event.c +21 -0
@@ -23,6 +23,7 @@ static const char *perf_event__names[] = { [PERF_RECORD_FORK] = "FORK", [PERF_RECORD_READ] = "READ", [PERF_RECORD_SAMPLE] = "SAMPLE", + [PERF_RECORD_AUX] = "AUX", [PERF_RECORD_HEADER_ATTR] = "ATTR", [PERF_RECORD_HEADER_EVENT_TYPE] = "EVENT_TYPE", [PERF_RECORD_HEADER_TRACING_DATA] = "TRACING_DATA",
@@ -695,6 +696,14 @@ int perf_event__process_lost(struct perf_tool *tool __maybe_unused,return machine__process_lost_event (machine, event, sample); } +int perf_event__process_aux (struct perf_tool *tool__maybe_unused , +union perf_event *event, +struct perf_sample *sample__maybe_unused , +struct machine *machine) +{ +return machine__process_aux_event (machine, event); +} +size_t perf_event__fprintf_mmap (union perf_event *event,FILE *fp) { return fprintf(fp, " %d/%d: [%#" PRIx64 "(%#" PRIx64 ") @ %#" PRIx64 "]: %c %s\n",
@@ -758,6 +767,15 @@ int perf_event__process_exit(struct perf_tool *tool __maybe_unused,return machine__process_exit_event (machine, event, sample); } +size_t perf_event__fprintf_aux (union perf_event *event,FILE *fp) +{ +return fprintf (fp," offset: %#" PRIx64" size: %#" PRIx64" flags: %#" PRIx64" [%s%s]\n" , + event->aux.aux_offset, event->aux.aux_size, + event->aux.flags, + event->aux.flags &PERF_AUX_FLAG_TRUNCATED ?"T" :"" , + event->aux.flags &PERF_AUX_FLAG_OVERWRITE ?"O" :"" ); +} +size_t perf_event__fprintf (union perf_event *event,FILE *fp) { size_t ret = fprintf(fp, "PERF_RECORD_%s",
@@ -777,6 +795,9 @@ size_t perf_event__fprintf(union perf_event *event, FILE *fp)case PERF_RECORD_MMAP2 : ret +=perf_event__fprintf_mmap2 (event, fp);break ; +case PERF_RECORD_AUX : + ret +=perf_event__fprintf_aux (event, fp); +break ;default : ret +=fprintf (fp,"\n" ); }
tools/perf/util/event.h +13 -0
@@ -323,6 +323,13 @@ struct auxtrace_error_event {char msg[MAX_AUXTRACE_ERROR_MSG ]; }; +struct aux_event { +struct perf_event_header header; +u64 aux_offset; +u64 aux_size; +u64 flags; +}; +union perf_event {struct perf_event_header header;struct mmap_event mmap;
@@ -341,6 +348,7 @@ union perf_event {struct auxtrace_info_event auxtrace_info;struct auxtrace_event auxtrace;struct auxtrace_error_event auxtrace_error; +struct aux_event aux; };void perf_event__print_totals (void );
@@ -376,6 +384,10 @@ int perf_event__process_lost(struct perf_tool *tool,union perf_event *event, struct perf_sample *sample, struct machine *machine); +int perf_event__process_aux (struct perf_tool *tool, +union perf_event *event, +struct perf_sample *sample, +struct machine *machine); int perf_event__process_mmap(struct perf_tool *tool, union perf_event *event, struct perf_sample *sample,
@@ -433,6 +445,7 @@ size_t perf_event__fprintf_comm(union perf_event *event, FILE *fp);size_t perf_event__fprintf_mmap (union perf_event *event,FILE *fp);size_t perf_event__fprintf_mmap2 (union perf_event *event,FILE *fp);size_t perf_event__fprintf_task (union perf_event *event,FILE *fp); +size_t perf_event__fprintf_aux (union perf_event *event,FILE *fp);size_t perf_event__fprintf (union perf_event *event,FILE *fp); u64 kallsyms__get_function_start(const char *kallsyms_filename,
tools/perf/util/machine.c +10 -0
@@ -486,6 +486,14 @@ machine__module_dso(struct machine *machine, struct kmod_path *m,return dso; } +int machine__process_aux_event (struct machine *machine__maybe_unused , +union perf_event *event) +{ +if (dump_trace) +perf_event__fprintf_aux (event, stdout); +return 0 ; +} +struct map *machine__new_module (struct machine *machine,u64 start,const char *filename) {
@@ -1331,6 +1339,8 @@ int machine__process_event(struct machine *machine, union perf_event *event, ret =machine__process_exit_event (machine, event, sample);break ;case PERF_RECORD_LOST : ret =machine__process_lost_event (machine, event, sample);break ; +case PERF_RECORD_AUX : + ret =machine__process_aux_event (machine, event);break ;default : ret =-1 ;break ;
tools/perf/util/machine.h +2 -0
@@ -81,6 +81,8 @@ int machine__process_fork_event(struct machine *machine, union perf_event *event struct perf_sample *sample);int machine__process_lost_event (struct machine *machine,union perf_event *event,struct perf_sample *sample); +int machine__process_aux_event (struct machine *machine, +union perf_event *event);int machine__process_mmap_event (struct machine *machine,union perf_event *event,struct perf_sample *sample); int machine__process_mmap2_event(struct machine *machine, union perf_event *event,
tools/perf/util/session.c +15 -0
@@ -325,6 +325,8 @@ void perf_tool__fill_defaults(struct perf_tool *tool) tool->exit = process_event_stub;if (tool->lost ==NULL ) tool->lost = perf_event__process_lost; +if (tool->aux ==NULL ) + tool->aux = perf_event__process_aux;if (tool->read ==NULL ) tool->read = process_event_sample_stub;if (tool->throttle ==NULL )
@@ -443,6 +445,16 @@ static void perf_event__read_swap(union perf_event *event, bool sample_id_all)swap_sample_id_all (event, &event->read +1 ); } +static void perf_event__aux_swap (union perf_event *event,bool sample_id_all) +{ + event->aux.aux_offset =bswap_64 (event->aux.aux_offset); + event->aux.aux_size =bswap_64 (event->aux.aux_size); + event->aux.flags =bswap_64 (event->aux.flags); + +if (sample_id_all) +swap_sample_id_all (event, &event->aux +1 ); +} +static void perf_event__throttle_swap (union perf_event *event,bool sample_id_all) {
@@ -580,6 +592,7 @@ static perf_event__swap_op perf_event__swap_ops[] = { [PERF_RECORD_THROTTLE] = perf_event__throttle_swap, [PERF_RECORD_UNTHROTTLE] = perf_event__throttle_swap, [PERF_RECORD_SAMPLE] = perf_event__all64_swap, + [PERF_RECORD_AUX] = perf_event__aux_swap, [PERF_RECORD_HEADER_ATTR] = perf_event__hdr_attr_swap, [PERF_RECORD_HEADER_EVENT_TYPE] = perf_event__event_type_swap, [PERF_RECORD_HEADER_TRACING_DATA] = perf_event__tracing_data_swap,
@@ -1029,6 +1042,8 @@ static int machines__deliver_event(struct machines *machines,return tool->throttle (tool, event, sample, machine);case PERF_RECORD_UNTHROTTLE :return tool->unthrottle (tool, event, sample, machine); +case PERF_RECORD_AUX : +return tool->aux (tool, event, sample, machine);default : ++evlist->stats.nr_unknown_events;return -1 ;
tools/perf/util/tool.h +1 -0
@@ -43,6 +43,7 @@ struct perf_tool { fork, exit, lost, + aux, throttle, unthrottle;event_attr_op attr;
Signature · 1 line
1.9.1
Re: [PATCH V3 08/25] perf tools: Add support for PERF_RECORD_AUX
Quoted 1 line · Adrian Hunter
Add support for the
PERF_RECORD_AUXevent type.
what is this event for? please update the changelog
jirka
Quoted 225 lines
Signed-off-by Adrian Hunter <[email protected]>--- tools/perf/builtin-inject.c | 1 + tools/perf/util/event.c | 21 +++++++++++++++++++++ tools/perf/util/event.h | 13 +++++++++++++ tools/perf/util/machine.c | 10 ++++++++++ tools/perf/util/machine.h | 2 ++ tools/perf/util/session.c | 15 +++++++++++++++ tools/perf/util/tool.h | 1 + 7 files changed, 63 insertions(+)tools/perf/builtin-inject.c +1
-0@@ -558,6 +558,7 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused) .fork = perf_event__repipe, .exit = perf_event__repipe, .lost = perf_event__repipe, + .aux = perf_event__repipe, .read = perf_event__repipe_sample, .throttle = perf_event__repipe, .unthrottle = perf_event__repipe,tools/perf/util/event.c +21
-0@@ -23,6 +23,7 @@ static const char *perf_event__names[] = { [PERF_RECORD_FORK] = "FORK", [PERF_RECORD_READ] = "READ", [PERF_RECORD_SAMPLE] = "SAMPLE", + [PERF_RECORD_AUX] = "AUX", [PERF_RECORD_HEADER_ATTR] = "ATTR", [PERF_RECORD_HEADER_EVENT_TYPE] = "EVENT_TYPE", [PERF_RECORD_HEADER_TRACING_DATA] = "TRACING_DATA",@@ -695,6 +696,14 @@ int perf_event__process_lost(struct perf_tool *tool __maybe_unused,return machine__process_lost_event (machine, event, sample); } +int perf_event__process_aux (struct perf_tool *tool__maybe_unused , +union perf_event *event, +struct perf_sample *sample__maybe_unused , +struct machine *machine) +{ +return machine__process_aux_event (machine, event); +} +size_t perf_event__fprintf_mmap (union perf_event *event,FILE *fp) { return fprintf(fp, " %d/%d: [%#" PRIx64 "(%#" PRIx64 ") @ %#" PRIx64 "]: %c %s\n",@@ -758,6 +767,15 @@ int perf_event__process_exit(struct perf_tool *tool __maybe_unused,return machine__process_exit_event (machine, event, sample); } +size_t perf_event__fprintf_aux (union perf_event *event,FILE *fp) +{ +return fprintf (fp," offset: %#" PRIx64" size: %#" PRIx64" flags: %#" PRIx64" [%s%s]\n" , + event->aux.aux_offset, event->aux.aux_size, + event->aux.flags, + event->aux.flags &PERF_AUX_FLAG_TRUNCATED ?"T" :"" , + event->aux.flags &PERF_AUX_FLAG_OVERWRITE ?"O" :"" ); +} +size_t perf_event__fprintf (union perf_event *event,FILE *fp) { size_t ret = fprintf(fp, "PERF_RECORD_%s",@@ -777,6 +795,9 @@ size_t perf_event__fprintf(union perf_event *event, FILE *fp)case PERF_RECORD_MMAP2 : ret +=perf_event__fprintf_mmap2 (event, fp);break ; +case PERF_RECORD_AUX : + ret +=perf_event__fprintf_aux (event, fp); +break ;default : ret +=fprintf (fp,"\n" ); }tools/perf/util/event.h +13
-0@@ -323,6 +323,13 @@ struct auxtrace_error_event {char msg[MAX_AUXTRACE_ERROR_MSG ]; }; +struct aux_event { +struct perf_event_header header; +u64 aux_offset; +u64 aux_size; +u64 flags; +}; +union perf_event {struct perf_event_header header;struct mmap_event mmap;@@ -341,6 +348,7 @@ union perf_event {struct auxtrace_info_event auxtrace_info;struct auxtrace_event auxtrace;struct auxtrace_error_event auxtrace_error; +struct aux_event aux; };void perf_event__print_totals (void );@@ -376,6 +384,10 @@ int perf_event__process_lost(struct perf_tool *tool,union perf_event *event, struct perf_sample *sample, struct machine *machine); +int perf_event__process_aux (struct perf_tool *tool, +union perf_event *event, +struct perf_sample *sample, +struct machine *machine); int perf_event__process_mmap(struct perf_tool *tool, union perf_event *event, struct perf_sample *sample,@@ -433,6 +445,7 @@ size_t perf_event__fprintf_comm(union perf_event *event, FILE *fp);size_t perf_event__fprintf_mmap (union perf_event *event,FILE *fp);size_t perf_event__fprintf_mmap2 (union perf_event *event,FILE *fp);size_t perf_event__fprintf_task (union perf_event *event,FILE *fp); +size_t perf_event__fprintf_aux (union perf_event *event,FILE *fp);size_t perf_event__fprintf (union perf_event *event,FILE *fp); u64 kallsyms__get_function_start(const char *kallsyms_filename,tools/perf/util/machine.c +10
-0@@ -486,6 +486,14 @@ machine__module_dso(struct machine *machine, struct kmod_path *m,return dso; } +int machine__process_aux_event (struct machine *machine__maybe_unused , +union perf_event *event) +{ +if (dump_trace) +perf_event__fprintf_aux (event, stdout); +return 0 ; +} +struct map *machine__new_module (struct machine *machine,u64 start,const char *filename) {@@ -1331,6 +1339,8 @@ int machine__process_event(struct machine *machine, union perf_event *event, ret =machine__process_exit_event (machine, event, sample);break ;case PERF_RECORD_LOST : ret =machine__process_lost_event (machine, event, sample);break ; +case PERF_RECORD_AUX : + ret =machine__process_aux_event (machine, event);break ;default : ret =-1 ;break ;tools/perf/util/machine.h +2
-0@@ -81,6 +81,8 @@ int machine__process_fork_event(struct machine *machine, union perf_event *event struct perf_sample *sample);int machine__process_lost_event (struct machine *machine,union perf_event *event,struct perf_sample *sample); +int machine__process_aux_event (struct machine *machine, +union perf_event *event);int machine__process_mmap_event (struct machine *machine,union perf_event *event,struct perf_sample *sample); int machine__process_mmap2_event(struct machine *machine, union perf_event *event,tools/perf/util/session.c +15
-0@@ -325,6 +325,8 @@ void perf_tool__fill_defaults(struct perf_tool *tool) tool->exit = process_event_stub;if (tool->lost ==NULL ) tool->lost = perf_event__process_lost; +if (tool->aux ==NULL ) + tool->aux = perf_event__process_aux;if (tool->read ==NULL ) tool->read = process_event_sample_stub;if (tool->throttle ==NULL )@@ -443,6 +445,16 @@ static void perf_event__read_swap(union perf_event *event, bool sample_id_all)swap_sample_id_all (event, &event->read +1 ); } +static void perf_event__aux_swap (union perf_event *event,bool sample_id_all) +{ + event->aux.aux_offset =bswap_64 (event->aux.aux_offset); + event->aux.aux_size =bswap_64 (event->aux.aux_size); + event->aux.flags =bswap_64 (event->aux.flags); + +if (sample_id_all) +swap_sample_id_all (event, &event->aux +1 ); +} +static void perf_event__throttle_swap (union perf_event *event,bool sample_id_all) {@@ -580,6 +592,7 @@ static perf_event__swap_op perf_event__swap_ops[] = { [PERF_RECORD_THROTTLE] = perf_event__throttle_swap, [PERF_RECORD_UNTHROTTLE] = perf_event__throttle_swap, [PERF_RECORD_SAMPLE] = perf_event__all64_swap, + [PERF_RECORD_AUX] = perf_event__aux_swap, [PERF_RECORD_HEADER_ATTR] = perf_event__hdr_attr_swap, [PERF_RECORD_HEADER_EVENT_TYPE] = perf_event__event_type_swap, [PERF_RECORD_HEADER_TRACING_DATA] = perf_event__tracing_data_swap,@@ -1029,6 +1042,8 @@ static int machines__deliver_event(struct machines *machines,return tool->throttle (tool, event, sample, machine);case PERF_RECORD_UNTHROTTLE :return tool->unthrottle (tool, event, sample, machine); +case PERF_RECORD_AUX : +return tool->aux (tool, event, sample, machine);default : ++evlist->stats.nr_unknown_events;return -1 ;tools/perf/util/tool.h +1
-0@@ -43,6 +43,7 @@ struct perf_tool { fork, exit, lost, + aux, throttle, unthrottle;event_attr_op attr;Signature · 1 line
1.9.1
Adrian Hunter
reviewerPATCH v3 9/25 perf tools: Add support for PERF_RECORD_ITRACE_START
In reply to Adrian HunterAdd support for the PERF_RECORD_ITRACE_START event type. This event can be used to determine the pid and tid that are running when Instruction Tracing starts. Generally that information would come from a sched_switch event but, at the start, no sched_switch events may yet have been recorded.
--- tools/perf/builtin-inject.c | 1 + tools/perf/util/event.c | 18 ++++++++++++++++++ tools/perf/util/event.h | 11 +++++++++++ tools/perf/util/machine.c | 11 +++++++++++ tools/perf/util/machine.h | 2 ++ tools/perf/util/session.c | 15 +++++++++++++++ tools/perf/util/tool.h | 1 + 7 files changed, 59 insertions(+)
tools/perf/builtin-inject.c +1 -0
@@ -559,6 +559,7 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused) .exit = perf_event__repipe, .lost = perf_event__repipe, .aux = perf_event__repipe, + .itrace_start = perf_event__repipe, .read = perf_event__repipe_sample, .throttle = perf_event__repipe, .unthrottle = perf_event__repipe,
tools/perf/util/event.c +18 -0
@@ -24,6 +24,7 @@ static const char *perf_event__names[] = { [PERF_RECORD_READ] = "READ", [PERF_RECORD_SAMPLE] = "SAMPLE", [PERF_RECORD_AUX] = "AUX", + [PERF_RECORD_ITRACE_START] = "ITRACE_START", [PERF_RECORD_HEADER_ATTR] = "ATTR", [PERF_RECORD_HEADER_EVENT_TYPE] = "EVENT_TYPE", [PERF_RECORD_HEADER_TRACING_DATA] = "TRACING_DATA",
@@ -704,6 +705,14 @@ int perf_event__process_aux(struct perf_tool *tool __maybe_unused,return machine__process_aux_event (machine, event); } +int perf_event__process_itrace_start (struct perf_tool *tool__maybe_unused , +union perf_event *event, +struct perf_sample *sample__maybe_unused , +struct machine *machine) +{ +return machine__process_itrace_start_event (machine, event); +} +size_t perf_event__fprintf_mmap (union perf_event *event,FILE *fp) { return fprintf(fp, " %d/%d: [%#" PRIx64 "(%#" PRIx64 ") @ %#" PRIx64 "]: %c %s\n",
@@ -776,6 +785,12 @@ size_t perf_event__fprintf_aux(union perf_event *event, FILE *fp) event->aux.flags & PERF_AUX_FLAG_OVERWRITE ? "O" : ""); } +size_t perf_event__fprintf_itrace_start (union perf_event *event,FILE *fp) +{ +return fprintf (fp," pid: %u tid: %u\n" , + event->itrace_start.pid, event->itrace_start.tid); +} +size_t perf_event__fprintf (union perf_event *event,FILE *fp) { size_t ret = fprintf(fp, "PERF_RECORD_%s",
@@ -798,6 +813,9 @@ size_t perf_event__fprintf(union perf_event *event, FILE *fp)case PERF_RECORD_AUX : ret +=perf_event__fprintf_aux (event, fp);break ; +case PERF_RECORD_ITRACE_START : + ret +=perf_event__fprintf_itrace_start (event, fp); +break ;default : ret +=fprintf (fp,"\n" ); }
tools/perf/util/event.h +11 -0
@@ -330,6 +330,11 @@ struct aux_event {u64 flags; }; +struct itrace_start_event { +struct perf_event_header header; +u32 pid, tid; +}; +union perf_event {struct perf_event_header header;struct mmap_event mmap;
@@ -349,6 +354,7 @@ union perf_event {struct auxtrace_event auxtrace;struct auxtrace_error_event auxtrace_error;struct aux_event aux; +struct itrace_start_event itrace_start; };void perf_event__print_totals (void );
@@ -388,6 +394,10 @@ int perf_event__process_aux(struct perf_tool *tool,union perf_event *event, struct perf_sample *sample, struct machine *machine); +int perf_event__process_itrace_start (struct perf_tool *tool, +union perf_event *event, +struct perf_sample *sample, +struct machine *machine); int perf_event__process_mmap(struct perf_tool *tool, union perf_event *event, struct perf_sample *sample,
@@ -446,6 +456,7 @@ size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp);size_t perf_event__fprintf_mmap2 (union perf_event *event,FILE *fp);size_t perf_event__fprintf_task (union perf_event *event,FILE *fp);size_t perf_event__fprintf_aux (union perf_event *event,FILE *fp); +size_t perf_event__fprintf_itrace_start (union perf_event *event,FILE *fp);size_t perf_event__fprintf (union perf_event *event,FILE *fp); u64 kallsyms__get_function_start(const char *kallsyms_filename,
tools/perf/util/machine.c +11 -0
@@ -494,6 +494,14 @@ int machine__process_aux_event(struct machine *machine __maybe_unused,return 0 ; } +int machine__process_itrace_start_event (struct machine *machine__maybe_unused , +union perf_event *event) +{ +if (dump_trace) +perf_event__fprintf_itrace_start (event, stdout); +return 0 ; +} +struct map *machine__new_module (struct machine *machine,u64 start,const char *filename) {
@@ -1341,6 +1349,9 @@ int machine__process_event(struct machine *machine, union perf_event *event, ret =machine__process_lost_event (machine, event, sample);break ;case PERF_RECORD_AUX : ret =machine__process_aux_event (machine, event);break ; +case PERF_RECORD_ITRACE_START : + ret =machine__process_itrace_start_event (machine, event); +break ;default : ret =-1 ;break ;
tools/perf/util/machine.h +2 -0
@@ -83,6 +83,8 @@ int machine__process_lost_event(struct machine *machine, union perf_event *event struct perf_sample *sample);int machine__process_aux_event (struct machine *machine,union perf_event *event); +int machine__process_itrace_start_event (struct machine *machine, +union perf_event *event);int machine__process_mmap_event (struct machine *machine,union perf_event *event,struct perf_sample *sample); int machine__process_mmap2_event(struct machine *machine, union perf_event *event,
tools/perf/util/session.c +15 -0
@@ -327,6 +327,8 @@ void perf_tool__fill_defaults(struct perf_tool *tool) tool->lost = perf_event__process_lost;if (tool->aux ==NULL ) tool->aux = perf_event__process_aux; +if (tool->itrace_start ==NULL ) + tool->itrace_start = perf_event__process_itrace_start;if (tool->read ==NULL ) tool->read = process_event_sample_stub;if (tool->throttle ==NULL )
@@ -455,6 +457,16 @@ static void perf_event__aux_swap(union perf_event *event, bool sample_id_all)swap_sample_id_all (event, &event->aux +1 ); } +static void perf_event__itrace_start_swap (union perf_event *event, +bool sample_id_all) +{ + event->itrace_start.pid =bswap_32 (event->itrace_start.pid); + event->itrace_start.tid =bswap_32 (event->itrace_start.tid); + +if (sample_id_all) +swap_sample_id_all (event, &event->itrace_start +1 ); +} +static void perf_event__throttle_swap (union perf_event *event,bool sample_id_all) {
@@ -593,6 +605,7 @@ static perf_event__swap_op perf_event__swap_ops[] = { [PERF_RECORD_UNTHROTTLE] = perf_event__throttle_swap, [PERF_RECORD_SAMPLE] = perf_event__all64_swap, [PERF_RECORD_AUX] = perf_event__aux_swap, + [PERF_RECORD_ITRACE_START] = perf_event__itrace_start_swap, [PERF_RECORD_HEADER_ATTR] = perf_event__hdr_attr_swap, [PERF_RECORD_HEADER_EVENT_TYPE] = perf_event__event_type_swap, [PERF_RECORD_HEADER_TRACING_DATA] = perf_event__tracing_data_swap,
@@ -1044,6 +1057,8 @@ static int machines__deliver_event(struct machines *machines,return tool->unthrottle (tool, event, sample, machine);case PERF_RECORD_AUX :return tool->aux (tool, event, sample, machine); +case PERF_RECORD_ITRACE_START : +return tool->itrace_start (tool, event, sample, machine);default : ++evlist->stats.nr_unknown_events;return -1 ;
tools/perf/util/tool.h +1 -0
@@ -44,6 +44,7 @@ struct perf_tool { exit, lost, aux, + itrace_start, throttle, unthrottle;event_attr_op attr;
Signature · 1 line
1.9.1
Adrian Hunter
reviewerPATCH v3 10/25 perf tools: Add AUX area tracing Snapshot Mode
In reply to Adrian HunterAdd support for making snapshots of
AUX area tracing data.
--- tools/perf/perf.h | 3 ++ tools/perf/util/auxtrace.c | 85 ++++++++++++++++++++++++++++++++++++++++------ tools/perf/util/auxtrace.h | 41 ++++++++++++++++++++++ 3 files changed, 119 insertions(+), 10 deletions(-)
tools/perf/perf.h +3 -0
@@ -55,6 +55,7 @@ struct record_opts {bool sample_intr_regs;bool running_time;bool full_auxtrace; +bool auxtrace_snapshot_mode;unsigned int freq;unsigned int mmap_pages;unsigned int auxtrace_mmap_pages;
@@ -62,6 +63,8 @@ struct record_opts {u64 branch_stack;u64 default_interval;u64 user_interval; +size_t auxtrace_snapshot_size; +const char *auxtrace_snapshot_opts;bool sample_transaction;unsigned initial_delay;bool use_clockid;
tools/perf/util/auxtrace.c +75 -10
127 lines not on this page · raw message
tools/perf/util/auxtrace.h +41 -0
77 lines not on this page · raw message
Signature · 1 line
1.9.1
Adrian Hunter
reviewerPATCH v3 11/25 perf record: Add AUX area tracing Snapshot Mode support
In reply to Adrian HunterAdd a new option and support for Instruction Tracing Snapshot Mode. When the new option is selected, no AUX area tracing data is captured until a signal (SIGUSR2) is received.
--- tools/perf/Documentation/perf-record.txt | 7 ++ tools/perf/builtin-record.c | 144 ++++++++++++++++++++++++++----- tools/perf/util/auxtrace.h | 11 +++ tools/perf/util/parse-options.h | 4 + 4 files changed, 145 insertions(+), 21 deletions(-)
tools/perf/Documentation/perf-record.txt +7 -0
@@ -259,6 +259,13 @@ records. See clock_gettime(). In particular CLOCK_MONOTONIC and CLOCK_MONOTONIC_RAW are supported, some events might also allow CLOCK_BOOTTIME, CLOCK_REALTIME and CLOCK_TAI. +-S:: +--snapshot:: +Select AUX area tracing Snapshot Mode. This option is valid only with an +AUX area tracing event. Optionally the number of bytes to capture per +snapshot can be specified. In Snapshot Mode, trace data is captured only when +signal SIGUSR2 is received. + SEE ALSO -------- linkperf:perf-stat[1], linkperf:perf-list[1]
tools/perf/builtin-record.c +123 -21
231 lines not on this page · raw message
tools/perf/util/auxtrace.h +11 -0
@@ -564,6 +564,17 @@ int itrace_parse_synth_opts(const struct option *opt __maybe_unused, }static inline +int auxtrace_parse_snapshot_options (struct auxtrace_record *itr__maybe_unused , +struct record_opts *opts__maybe_unused , +const char *str) +{ +if (!str) +return 0 ; +pr_err ("AUX area tracing not supported\n" ); +return -EINVAL ; +} + +static inline int auxtrace__process_event(struct perf_session *session __maybe_unused, union perf_event *event __maybe_unused, struct perf_sample *sample __maybe_unused,
tools/perf/util/parse-options.h +4 -0
@@ -123,6 +123,10 @@ struct option {#define OPT_LONG (s, l, v, h) { .type = OPTION_LONG, .short_name = (s), .long_name = (l), .value = check_vtype(v, long *), .help = (h) }#define OPT_U64 (s, l, v, h) { .type = OPTION_U64, .short_name = (s), .long_name = (l), .value = check_vtype(v, u64 *), .help = (h) }#define OPT_STRING (s, l, v, a, h) { .type = OPTION_STRING, .short_name = (s), .long_name = (l), .value = check_vtype(v, const char **), (a), .help = (h) } +#define OPT_STRING_OPTARG (s, l, v, a, h, d) \ + { .type = OPTION_STRING, .short_name = (s), .long_name = (l), \ + .value = check_vtype(v, const char **), (a), .help = (h), \ + .flags = PARSE_OPT_OPTARG, .defval = (intptr_t)(d) }#define OPT_STRING_NOEMPTY (s, l, v, a, h) { .type = OPTION_STRING, .short_name = (s), .long_name = (l), .value = check_vtype(v, const char **), (a), .help = (h), .flags = PARSE_OPT_NOEMPTY}#define OPT_DATE (s, l, v, h) \ { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), .argh = "time", .help = (h), .callback = parse_opt_approxidate_cb }
Signature · 1 line
1.9.1
Re: [PATCH V3 11/25] perf record: Add AUX area tracing Snapshot Mode support
On Fri, Apr 24, 2015 at 10:29:53PM +0300, Adrian Hunter wrote:
SNIP
Quoted 21 lines
tools/perf/builtin-record.c +3
-2char msg[512 ];@@ -238,7 +302,8 @@ try_again: }if (perf_evlist__mmap_ex (evlist, opts->mmap_pages, false, - opts->auxtrace_mmap_pages, false) <0 ) { + opts->auxtrace_mmap_pages, + opts->auxtrace_snapshot_mode) <0 ) {if (errno ==EPERM ) {pr_err ("Permission error mapping pages.\n" "Consider increasing "@@ -349,7 +414,7 @@ static int record__mmap_read_all(struct record *rec) } } -if (mm->base && +if (mm->base && !rec->opts.auxtrace_snapshot_mode &&record__auxtrace_mmap_read (rec, mm) !=0 ) { rc =-1 ; goto out;
tools/perf/builtin-record.c static void workload_exec_failed_signal(int signo __maybe_unused, · line 472
Quoted 4 lines
tools/perf/builtin-record.c +1
-0@@ -404,6 +469,8 @@ static void workload_exec_failed_signal(int signo __maybe_unused, child_finished =1 ; } +static void snapshot_sig_handler (int sig);
seems there's no need for forward declaration,
you can define the function right here, no?
jirka
Adrian Hunter
reviewerRe: [PATCH V3 11/25] perf record: Add AUX area tracing Snapshot Mode support
Quoted 28 lines · Jiri Olsa
On Fri, Apr 24, 2015 at 10:29:53PM +0300, Adrian Hunter wrote:
SNIP
Quoted 24 lines
tools/perf/builtin-record.c +3
-2char msg[512 ];@@ -238,7 +302,8 @@ try_again: }if (perf_evlist__mmap_ex (evlist, opts->mmap_pages, false, - opts->auxtrace_mmap_pages, false) <0 ) { + opts->auxtrace_mmap_pages, + opts->auxtrace_snapshot_mode) <0 ) {if (errno ==EPERM ) {pr_err ("Permission error mapping pages.\n" "Consider increasing "@@ -349,7 +414,7 @@ static int record__mmap_read_all(struct record *rec) } } -if (mm->base && +if (mm->base && !rec->opts.auxtrace_snapshot_mode &&record__auxtrace_mmap_read (rec, mm) !=0 ) { rc =-1 ; goto out;@@ -404,6 +469,8 @@ static void workload_exec_failed_signal(int signo __maybe_unused, child_finished =1 ; }
Quoted 4 lines
tools/perf/builtin-record.c static void workload_exec_failed_signal(int signo __maybe_unused, · line 472
Quoted 1 line
tools/perf/builtin-record.c +1
-0+static void snapshot_sig_handler (int sig);seems there's no need for forward declaration,
you can define the function right here, no?
snapshot_sig_handler is dependent on "record" so the forward declaration does seem to be needed.
Re: [PATCH V3 11/25] perf record: Add AUX area tracing Snapshot Mode support
Quoted 29 lines · Adrian Hunter
Quoted 28 lines · Jiri Olsa
On Fri, Apr 24, 2015 at 10:29:53PM +0300, Adrian Hunter wrote:
SNIP
Quoted 24 lines
tools/perf/builtin-record.c +3
-2char msg[512 ];@@ -238,7 +302,8 @@ try_again: }if (perf_evlist__mmap_ex (evlist, opts->mmap_pages, false, - opts->auxtrace_mmap_pages, false) <0 ) { + opts->auxtrace_mmap_pages, + opts->auxtrace_snapshot_mode) <0 ) {if (errno ==EPERM ) {pr_err ("Permission error mapping pages.\n" "Consider increasing "@@ -349,7 +414,7 @@ static int record__mmap_read_all(struct record *rec) } } -if (mm->base && +if (mm->base && !rec->opts.auxtrace_snapshot_mode &&record__auxtrace_mmap_read (rec, mm) !=0 ) { rc =-1 ; goto out;@@ -404,6 +469,8 @@ static void workload_exec_failed_signal(int signo __maybe_unused, child_finished =1 ; }
Quoted 7 lines
Quoted 4 lines
tools/perf/builtin-record.c static void workload_exec_failed_signal(int signo __maybe_unused, · line 472
Quoted 1 line
tools/perf/builtin-record.c +1
-0+static void snapshot_sig_handler (int sig);seems there's no need for forward declaration,
you can define the function right here, no?
snapshot_sig_handleris dependent on "record" so the forward declaration does seem to be needed.
missed the record bit, ok
jirka
Adrian Hunter
reviewerPATCH v3 12/25 perf auxtrace: Add Intel PT as an AUX area tracing type
In reply to Adrian HunterAdd the Intel Processor Trace type
constant PERF_AUXTRACE_INTEL_PT.
--- tools/perf/util/auxtrace.c | 1 + tools/perf/util/auxtrace.h | 1 + 2 files changed, 2 insertions(+)
tools/perf/util/auxtrace.c +1 -0
@@ -885,6 +885,7 @@ int perf_event__process_auxtrace_info(struct perf_tool *tool __maybe_unused,fprintf (stdout," type: %u\n" , type);switch (type) { +case PERF_AUXTRACE_INTEL_PT :case PERF_AUXTRACE_UNKNOWN :default :return -EINVAL ;
tools/perf/util/auxtrace.h +1 -0
@@ -39,6 +39,7 @@ struct events_stats;enum auxtrace_type {PERF_AUXTRACE_UNKNOWN , +PERF_AUXTRACE_INTEL_PT , };enum itrace_period_type {
Signature · 1 line
1.9.1
Adrian Hunter
reviewerPATCH v3 13/25 perf tools: Add Intel PT packet decoder
In reply to Adrian HunterAdd support for decoding Intel Processor Trace
packets.
--- tools/perf/util/Build | 1 + tools/perf/util/intel-pt-decoder/Build | 1 + .../util/intel-pt-decoder/intel-pt-pkt-decoder.c | 400 +++++++++++++++++++++ .../util/intel-pt-decoder/intel-pt-pkt-decoder.h | 64 ++++ 4 files changed, 466 insertions(+) create mode 100644 tools/perf/util/intel-pt-decoder/Build create mode 100644 tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c create mode 100644 tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.h
tools/perf/util/Build +1 -0
@@ -75,6 +75,7 @@ libperf-$(CONFIG_X86) += tsc.o libperf-y += cloexec.o libperf-y += thread-stack.o libperf-$(CONFIG_AUXTRACE) += auxtrace.o +libperf-$(CONFIG_AUXTRACE) += intel-pt-decoder/ libperf-$(CONFIG_LIBELF) += symbol-elf.o libperf-$(CONFIG_LIBELF) += probe-event.o
tools/perf/util/intel-pt-decoder/Build new file +1 -0
@@ -0,0 +1 @@ +libperf-$(CONFIG_AUXTRACE) += intel-pt-pkt-decoder.o
tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c new file +400 -0
400 lines not on this page · raw message
tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.h new file +64 -0
64 lines not on this page · raw message
Signature · 1 line
1.9.1
Adrian Hunter
reviewerPATCH v3 14/25 perf tools: Add Intel PT instruction decoder
In reply to Adrian HunterAdd support for decoding instructions for Intel
Processor Trace. The kernel x86 instruction
decoder is used for this.
--- tools/build/Makefile.build | 2 + tools/perf/.gitignore | 2 + tools/perf/Makefile.perf | 6 +- tools/perf/util/intel-pt-decoder/Build | 15 +- .../util/intel-pt-decoder/intel-pt-insn-decoder.c | 246 +++++++++++++++++++++ .../util/intel-pt-decoder/intel-pt-insn-decoder.h | 65 ++++++ 6 files changed, 333 insertions(+), 3 deletions(-) create mode 100644 tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c create mode 100644 tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.h
tools/build/Makefile.build +2 -0
@@ -57,6 +57,8 @@ quiet_cmd_cc_i_c = CPP $@ quiet_cmd_cc_s_c = AS $@ cmd_cc_s_c = $(CC) $(c_flags) -S -o $@ $< +quiet_cmd_gen = GEN $@ + # Link agregate command # If there's nothing to link, create empty $@ object. quiet_cmd_ld_multi = LD $@
tools/perf/.gitignore +2 -0
@@ -28,3 +28,5 @@ config.mak.autogen *-flex.* *.pyc *.pyo +util/intel-pt-decoder/inat-tables.c +util/intel-pt-decoder/inat.c
tools/perf/Makefile.perf +4 -2
@@ -122,6 +122,7 @@ INSTALL = install FLEX = flex BISON = bison STRIP = strip +AWK = awk LIB_DIR = $(srctree)/tools/lib/api/ TRACE_EVENT_DIR = $(srctree)/tools/lib/traceevent/
@@ -272,7 +273,7 @@ strip: $(PROGRAMS) $(OUTPUT)perf PERF_IN := $(OUTPUT)perf-in.o -export srctree OUTPUT RM CC LD AR CFLAGS V BISON FLEX +export srctree OUTPUT RM CC LD AR CFLAGS V BISON FLEX AWK build := -f $(srctree)/tools/build/Makefile.build dir=. obj $(PERF_IN): $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h FORCE
@@ -532,7 +533,8 @@ clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean config-clean $(Q)find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete $(Q)$(RM) .config-detected $(call QUIET_CLEAN, core-progs) $(RM) $(ALL_PROGRAMS) perf perf-read-vdso32 perf-read-vdsox32 - $(call QUIET_CLEAN, core-gen) $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope* $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)FEATURE-DUMP $(OUTPUT)util/*-bison* $(OUTPUT)util/*-flex* + $(call QUIET_CLEAN, core-gen) $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope* $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)FEATURE-DUMP $(OUTPUT)util/*-bison* $(OUTPUT)util/*-flex* \ + $(OUTPUT)util/intel-pt-decoder/inat.c $(OUTPUT)util/intel-pt-decoder/inat-tables.c $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean $(python-clean)
tools/perf/util/intel-pt-decoder/Build +14 -1
@@ -1 +1,14 @@ -libperf-$(CONFIG_AUXTRACE) += intel-pt-pkt-decoder.o +libperf-$(CONFIG_AUXTRACE) += intel-pt-pkt-decoder.o intel-pt-insn-decoder.o + +inat_tables_script = ../../arch/x86/tools/gen-insn-attr-x86.awk +inat_tables_maps = ../../arch/x86/lib/x86-opcode-map.txt + +$(OUTPUT)util/intel-pt-decoder/inat-tables.c: $(inat_tables_script) $(inat_tables_maps) + @$(call echo-cmd,gen)$(AWK) -f $(inat_tables_script) $(inat_tables_maps) > $@ || rm -f $@ + +$(OUTPUT)util/intel-pt-decoder/inat.c: + @$(call echo-cmd,gen)cp ../../arch/x86/lib/inat.c $(OUTPUT)util/intel-pt-decoder/inat.c + +$(OUTPUT)util/intel-pt-decoder/intel-pt-insn-decoder.o: $(OUTPUT)util/intel-pt-decoder/inat.c $(OUTPUT)util/intel-pt-decoder/inat-tables.c + +CFLAGS_intel-pt-insn-decoder.o += -I../../arch/x86/include -I$(OUTPUT)util/intel-pt-decoder -I../../arch/x86/lib
tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c new file +246 -0
246 lines not on this page · raw message
tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.h new file +65 -0
65 lines not on this page · raw message
Signature · 1 line
1.9.1
Adrian Hunter
reviewerPATCH v3 15/25 perf tools: Add Intel PT log
In reply to Adrian HunterAdd a facility to log Intel Processor Trace
decoding. The log is intended for debugging
purposes only.
The log file name is "intel_pt.log" and is
opened in the current directory.
--- tools/perf/util/intel-pt-decoder/Build | 2 +- tools/perf/util/intel-pt-decoder/intel-pt-log.c | 155 ++++++++++++++++++++++++ tools/perf/util/intel-pt-decoder/intel-pt-log.h | 52 ++++++++ 3 files changed, 208 insertions(+), 1 deletion(-) create mode 100644 tools/perf/util/intel-pt-decoder/intel-pt-log.c create mode 100644 tools/perf/util/intel-pt-decoder/intel-pt-log.h
tools/perf/util/intel-pt-decoder/Build +1 -1
@@ -1,4 +1,4 @@ -libperf-$(CONFIG_AUXTRACE) += intel-pt-pkt-decoder.o intel-pt-insn-decoder.o +libperf-$(CONFIG_AUXTRACE) += intel-pt-pkt-decoder.o intel-pt-insn-decoder.o intel-pt-log.o inat_tables_script = ../../arch/x86/tools/gen-insn-attr-x86.awk inat_tables_maps = ../../arch/x86/lib/x86-opcode-map.txt
tools/perf/util/intel-pt-decoder/intel-pt-log.c new file +155 -0
155 lines not on this page · raw message
tools/perf/util/intel-pt-decoder/intel-pt-log.h new file +52 -0
52 lines not on this page · raw message
Signature · 1 line
1.9.1
Adrian Hunter
reviewerPATCH v3 16/25 perf tools: Add Intel PT decoder
In reply to Adrian HunterAdd support for decoding an Intel Processor Trace.
--- tools/perf/util/intel-pt-decoder/Build | 2 +- .../perf/util/intel-pt-decoder/intel-pt-decoder.c | 1738 ++++++++++++++++++++ .../perf/util/intel-pt-decoder/intel-pt-decoder.h | 89 + 3 files changed, 1828 insertions(+), 1 deletion(-) create mode 100644 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c create mode 100644 tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
tools/perf/util/intel-pt-decoder/Build +1 -1
@@ -1,4 +1,4 @@ -libperf-$(CONFIG_AUXTRACE) += intel-pt-pkt-decoder.o intel-pt-insn-decoder.o intel-pt-log.o +libperf-$(CONFIG_AUXTRACE) += intel-pt-pkt-decoder.o intel-pt-insn-decoder.o intel-pt-log.o intel-pt-decoder.o inat_tables_script = ../../arch/x86/tools/gen-insn-attr-x86.awk inat_tables_maps = ../../arch/x86/lib/x86-opcode-map.txt
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c new file +1738 -0
1,738 lines not on this page · raw message
tools/perf/util/intel-pt-decoder/intel-pt-decoder.h new file +89 -0
89 lines not on this page · raw message
Signature · 1 line
1.9.1
Adrian Hunter
reviewerPATCH v3 17/25 perf tools: Add Intel PT support
In reply to Adrian HunterAdd support for Intel Processor Trace.
--- tools/perf/arch/x86/util/Build | 2 + tools/perf/arch/x86/util/intel-pt.c | 752 ++++++++++++++ tools/perf/util/Build | 1 + tools/perf/util/intel-pt.c | 1891 +++++++++++++++++++++++++++++++++++ tools/perf/util/intel-pt.h | 57 ++ 5 files changed, 2703 insertions(+) create mode 100644 tools/perf/arch/x86/util/intel-pt.c create mode 100644 tools/perf/util/intel-pt.c create mode 100644 tools/perf/util/intel-pt.h
tools/perf/arch/x86/util/Build +2 -0
@@ -6,3 +6,5 @@ libperf-$(CONFIG_DWARF) += dwarf-regs.o libperf-$(CONFIG_LIBUNWIND) += unwind-libunwind.o libperf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o + +libperf-$(CONFIG_AUXTRACE) += intel-pt.o
tools/perf/arch/x86/util/intel-pt.c new file +752 -0
752 lines not on this page · raw message
tools/perf/util/Build +1 -0
@@ -76,6 +76,7 @@ libperf-y += cloexec.o libperf-y += thread-stack.o libperf-$(CONFIG_AUXTRACE) += auxtrace.o libperf-$(CONFIG_AUXTRACE) += intel-pt-decoder/ +libperf-$(CONFIG_AUXTRACE) += intel-pt.o libperf-$(CONFIG_LIBELF) += symbol-elf.o libperf-$(CONFIG_LIBELF) += probe-event.o
tools/perf/util/intel-pt.c new file +1891 -0
1,891 lines not on this page · raw message
tools/perf/util/intel-pt.h new file +57 -0
57 lines not on this page · raw message
Signature · 1 line
1.9.1
Adrian Hunter
reviewerPATCH v3 18/25 perf tools: Take Intel PT into use
In reply to Adrian HunterTo record an AUX area, the weak functionauxtrace_record__init() must be implemented.
Equally to decode an AUX area, the
AUX area tracing type must be added to theperf_event__process_auxtrace_info() function.
This patch makes those two changes plus hooks
up default config for the intel_pt PMU. Also
some brief documentation is provided for
using the tools with intel_pt.
--- tools/perf/Documentation/intel-pt.txt | 467 ++++++++++++++++++++++++++++++++++ tools/perf/arch/x86/util/Build | 2 + tools/perf/arch/x86/util/auxtrace.c | 38 +++ tools/perf/arch/x86/util/pmu.c | 15 ++ tools/perf/util/auxtrace.c | 5 +- 5 files changed, 526 insertions(+), 1 deletion(-) create mode 100644 tools/perf/Documentation/intel-pt.txt create mode 100644 tools/perf/arch/x86/util/auxtrace.c create mode 100644 tools/perf/arch/x86/util/pmu.c
tools/perf/Documentation/intel-pt.txt new file +467 -0
@@ -0,0 +1,467 @@ +Intel Processor Trace +===================== + +perf record +=========== + +new event +--------- + +The Intel PT kernel driver creates a new PMU for Intel PT. PMU events are +selected by providing the PMU name followed by the "config" separated by slashes. +An enhancement has been made to allow default "config" e.g. the option + + -e intel_pt// + +will use a default config value. Currently that is the same as + + -e intel_pt/tsc,noretcomp=0/ + +which is the same as + + -e intel_pt/tsc=1,noretcomp=0/ + +The config terms are listed in /sys/devices/intel_pt/format. They are bit +fields within the config member of the struct perf_event_attr which is +passed to the kernel by the perf_event_open system call. They correspond to bit +fields in the IA32_RTIT_CTL MSR. Here is a list of them and their definitions: + + $ for f in `ls /sys/devices/intel_pt/format`;do + > echo $f + > cat /sys/devices/intel_pt/format/$f + > done + noretcomp + config:11 + tsc + config:10 + +Note that the default config must be overridden for each term i.e. + + -e intel_pt/noretcomp=0/ + +is the same as: + + -e intel_pt/tsc=1,noretcomp=0/ + +So, to disable TSC packets use: + + -e intel_pt/tsc=0/ + +It is also possible to specify the config value explicitly: + + -e intel_pt/config=0x400/ + +Note that, as with all events, the event is suffixed with event modifiers: + + u userspace + k kernel + h hypervisor + G guest + H host + p precise ip + +'h', 'G' and 'H' are for virtualization which is not supported by Intel PT. +'p' is also not relevant to Intel PT. So only options 'u' and 'k' are +meaningful for Intel PT. + +perf_event_attr is displayed if the -vv option is used e.g. + + ------------------------------------------------------------ + perf_event_attr: + type 6 + size 112 + config 0x400 + { sample_period, sample_freq } 1 + sample_type IP|TID|TIME|CPU|IDENTIFIER + read_format ID + disabled 1 + inherit 1 + exclude_kernel 1 + exclude_hv 1 + enable_on_exec 1 + sample_id_all 1 + ------------------------------------------------------------ + sys_perf_event_open: pid 31104 cpu 0 group_fd -1 flags 0x8 + sys_perf_event_open: pid 31104 cpu 1 group_fd -1 flags 0x8 + sys_perf_event_open: pid 31104 cpu 2 group_fd -1 flags 0x8 + sys_perf_event_open: pid 31104 cpu 3 group_fd -1 flags 0x8 + ------------------------------------------------------------ + + +new snapshot option +------------------- + +To select snapshot mode a new option has been added: + + -S + +Optionally it can be followed by the snapshot size e.g. + + -S0x100000 + +The default snapshot size is the auxtrace mmap size. If neither auxtrace mmap size +nor snapshot size is specified, then the default is 4MiB for privileged users +(or if /proc/sys/kernel/perf_event_paranoid < 0), 128KiB for unprivileged users. +If an unprivileged user does not specify mmap pages, the mmap pages will be +reduced as described in the 'new auxtrace mmap size option' section below. + +The snapshot size is displayed if the option -vv is used e.g. + + Intel PT snapshot size: %zu + + +new auxtrace mmap size option +--------------------------- + +Intel PT buffer size is specified by an addition to the -m option e.g. + + -m,16 + +selects a buffer size of 16 pages i.e. 64KiB. + +Note that the existing functionality of -m is unchanged. The auxtrace mmap size +is specified by the optional addition of a comma and the value. + +The default auxtrace mmap size for Intel PT is 4MiB/page_size for privileged users +(or if /proc/sys/kernel/perf_event_paranoid < 0), 128KiB for unprivileged users. +If an unprivileged user does not specify mmap pages, the mmap pages will be +reduced from the default 512KiB/page_size to 256KiB/page_size, otherwise the +user is likely to get an error as they exceed their mlock limit (Max locked +memory as shown in /proc/self/limits). Note that perf does not count the first +512KiB (actually /proc/sys/kernel/perf_event_mlock_kb minus 1 page) per cpu +against the mlock limit so an unprivileged user is allowed 512KiB per cpu plus +their mlock limit (which defaults to 64KiB but is not multiplied by the number +of cpus). + +In full-trace mode, powers of two are allowed for buffer size, with a minimum +size of 2 pages. In snapshot mode, it is the same but the minimum size is +1 page. + +The mmap size and auxtrace mmap size are displayed if the -vv option is used e.g. + + mmap length 528384 + auxtrace mmap length 4198400 + + +Intel PT modes of operation +--------------------------- + +Intel PT can be used in 2 modes: + full-trace mode + snapshot mode + +Full-trace mode traces continuously e.g. + + perf record -e intel_pt//u uname + +Snapshot mode captures the available data when a signal is sent e.g. + + perf record -v -e intel_pt//u -S ./loopy 1000000000 & + [1] 11435 + kill -USR2 11435 + Recording AUX area tracing snapshot + +Note that the signal sent is SIGUSR2. +Note that "Recording AUX area tracing snapshot" is displayed because the -v +option is used. + +None of the 3 modes can be used together. + + +Buffer handling +--------------- + +There may be buffer limitations (i.e. single ToPa entry) which means that actual +buffer sizes are limited to powers of 2 up to 4MiB (MAX_ORDER). In order to +provide other sizes, and in particular an arbitrarily large size, multiple +buffers are logically concatenated. However an interrupt must be used to switch +between buffers. That has two potential problems: + a) the interrupt may not be handled in time so that the current buffer + becomes full and some trace data is lost. + b) the interrupts may slow the system and affect the performance + results. + +If trace data is lost, the driver sets 'truncated' in the PERF_RECORD_AUX event +which the tools report as an error. + +In full-trace mode, the driver waits for data to be copied out before allowing +the (logical) buffer to wrap-around. If data is not copied out quickly enough, +again 'truncated' is set in the PERF_RECORD_AUX event. If the driver has to +wait, the intel_pt event gets disabled. Because it is difficult to know when +that happens, perf tools always re-enable the intel_pt event after copying out +data. + + +Intel PT and build ids +---------------------- + +By default "perf record" post-processes the event stream to find all build ids +for executables for all addresses sampled. Deliberately, Intel PT is not +decoded for that purpose (it would take too long). Instead the build ids for +all executables encountered (due to mmap, comm or task events) are included +in the perf.data file. + +To see buildids included in the perf.data file use the command: + + perf buildid-list + +If the perf.data file contains Intel PT data, that is the same as: + + perf buildid-list --with-hits + + +Snapshot mode and event disabling +--------------------------------- + +In order to make a snapshot, the intel_pt event is disabled using an IOCTL, +namely PERF_EVENT_IOC_DISABLE. However doing that can also disable the +collection of side-band information. In order to prevent that, a dummy +software event has been introduced that permits tracking events (like mmaps) to +continue to be recorded while intel_pt is disabled. That is important to ensure +there is complete side-band information to allow the decoding of subsequent +snapshots. + +A test has been created for that. To find the test: + + perf test list + ... + 23: Test using a dummy software event to keep tracking + +To run the test: + + perf test 23 + 23: Test using a dummy software event to keep tracking : Ok + + +perf record modes (nothing new here) +------------------------------------ + +perf record essentially operates in one of three modes: + per thread + per cpu + workload only + +"per thread" mode is selected by -t or by --per-thread (with -p or -u or just a +workload). +"per cpu" is selected by -C or -a. +"workload only" mode is selected by not using the other options but providing a +command to run (i.e. the workload). + +In per-thread mode an exact list of threads is traced. There is no inheritance. +Each thread has its own event buffer. + +In per-cpu mode all processes (or processes from the selected cgroup i.e. -G +option, or processes selected with -p or -u) are traced. Each cpu has its own +buffer. Inheritance is allowed. + +In workload-only mode, the workload is traced but with per-cpu buffers. +Inheritance is allowed. Note that you can now trace a workload in per-thread +mode by using the --per-thread option. + + +Privileged vs non-privileged users +---------------------------------- + +Unless /proc/sys/kernel/perf_event_paranoid is set to -1, unprivileged users +have memory limits imposed upon them. That affects what buffer sizes they can +have as outlined above. + +Unless /proc/sys/kernel/perf_event_paranoid is set to -1, unprivileged users are +not permitted to use tracepoints which means there is insufficient side-band +information to decode Intel PT in per-cpu mode, and potentially workload-only +mode too if the workload creates new processes. + +Note also, that to use tracepoints, read-access to debugfs is required. So if +debugfs is not mounted or the user does not have read-access, it will again not +be possible to decode Intel PT in per-cpu mode. + + +sched_switch tracepoint +----------------------- + +The sched_switch tracepoint is used to provide side-band data for Intel PT +decoding. sched_switch events are automatically added. e.g. the second event +shown below + + $ perf record -vv -e intel_pt//u uname + ------------------------------------------------------------ + perf_event_attr: + type 6 + size 112 + config 0x400 + { sample_period, sample_freq } 1 + sample_type IP|TID|TIME|CPU|IDENTIFIER + read_format ID + disabled 1 + inherit 1 + exclude_kernel 1 + exclude_hv 1 + enable_on_exec 1 + sample_id_all 1 + ------------------------------------------------------------ + sys_perf_event_open: pid 31104 cpu 0 group_fd -1 flags 0x8 + sys_perf_event_open: pid 31104 cpu 1 group_fd -1 flags 0x8 + sys_perf_event_open: pid 31104 cpu 2 group_fd -1 flags 0x8 + sys_perf_event_open: pid 31104 cpu 3 group_fd -1 flags 0x8 + ------------------------------------------------------------ + perf_event_attr: + type 2 + size 112 + config 0x108 + { sample_period, sample_freq } 1 + sample_type IP|TID|TIME|CPU|PERIOD|RAW|IDENTIFIER + read_format ID + inherit 1 + sample_id_all 1 + exclude_guest 1 + ------------------------------------------------------------ + sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 + sys_perf_event_open: pid -1 cpu 1 group_fd -1 flags 0x8 + sys_perf_event_open: pid -1 cpu 2 group_fd -1 flags 0x8 + sys_perf_event_open: pid -1 cpu 3 group_fd -1 flags 0x8 + ------------------------------------------------------------ + perf_event_attr: + type 1 + size 112 + config 0x9 + { sample_period, sample_freq } 1 + sample_type IP|TID|TIME|IDENTIFIER + read_format ID + disabled 1 + inherit 1 + exclude_kernel 1 + exclude_hv 1 + mmap 1 + comm 1 + enable_on_exec 1 + task 1 + sample_id_all 1 + mmap2 1 + comm_exec 1 + ------------------------------------------------------------ + sys_perf_event_open: pid 31104 cpu 0 group_fd -1 flags 0x8 + sys_perf_event_open: pid 31104 cpu 1 group_fd -1 flags 0x8 + sys_perf_event_open: pid 31104 cpu 2 group_fd -1 flags 0x8 + sys_perf_event_open: pid 31104 cpu 3 group_fd -1 flags 0x8 + mmap size 528384B + AUX area mmap length 4194304 + perf event ring buffer mmapped per cpu + Synthesizing auxtrace information + Linux + [ perf record: Woken up 1 times to write data ] + [ perf record: Captured and wrote 0.042 MB perf.data ] + +Note, the sched_switch event is only added if the user is permitted to use it +and only in per-cpu mode. + +Note also, the sched_switch event is only added if TSC packets are requested. +That is because, in the absence of timing information, the sched_switch events +cannot be matched against the Intel PT trace. + + +perf script +=========== + +By default, perf script will decode trace data found in the perf.data file. +This can be further controlled by new option --itrace. + + +New AUX area option +---------------------------- + +Having no option is the same as + + --itrace + +which, in turn, is the same as + + --itrace=ibxe + +The letters are: + + i synthesize "instructions" events + b synthesize "branches" events + x synthesize "transactions" events + c synthesize branches events (calls only) + r synthesize branches events (returns only) + e synthesize tracing error events + d create a debug log + g synthesize a call chain (use with i or x) + +"Instructions" events look like they were recorded by "perf record -e +instructions". + +"Branches" events look like they were recorded by "perf record -e branches". "c" +and "r" can be combined to get calls and returns. + +"Transactions" events correspond to the start or end of transactions. The +'flags' field can be used in perf script to determine whether the event is a +tranasaction start, commit or abort. + +Error events are new. They show where the decoder lost the trace. Error events +are quite important. Users must know if what they are seeing is a complete +picture or not. + +The "d" option will cause the creation of a file "intel_pt.log" containing all +decoded packets and instructions. Note that this option slows down the decoder +and that the resulting file may be very large. + +In addition, the period of the "instructions" event can be specified. e.g. + + --itrace=i10us + +sets the period to 10us i.e. one instruction sample is synthesized for each 10 +microseconds of trace. Alternatives to "us" are "ms" (milliseconds), +"ns" (nanoseconds), "t" (TSC ticks) or "i" (instructions). + +"ms", "us" and "ns" are converted to TSC ticks. + +The timing information included with Intel PT does not give the time of every +instruction. Consequently, for the purpose of sampling, the decoder estimates +the time since the last timing packet based on 1 tick per instruction. The time +on the sample is *not* adjusted and reflects the last known value of TSC. + +For Intel PT, the default period is 100us. + +Also the call chain size (default 16, max. 1024) for instructions or +transactions events can be specified. e.g. + + --itrace=ig32 + --itrace=xg32 + +To disable trace decoding entirely, use the option --no-itrace. + + +dump option +----------- + +perf script has an option (-D) to "dump" the events i.e. display the binary +data. + +When -D is used, Intel PT packets are displayed. The packet decoder does not +pay attention to PSB packets, but just decodes the bytes - so the packets seen +by the actual decoder may not be identical in places where the data is corrupt. +One example of that would be when the buffer-switching interrupt has been too +slow, and the buffer has been filled completely. In that case, the last packet +in the buffer might be truncated and immediately followed by a PSB as the trace +continues in the next buffer. + +To disable the display of Intel PT packets, combine the -D option with +--no-itrace. + + +perf report +=========== + +By default, perf report will decode trace data found in the perf.data file. +This can be further controlled by new option --itrace exactly the same as +perf script, with the exception that the default is --itrace=ge. + + +perf inject +=========== + +perf inject also accepts the --itrace option in which case tracing data is +removed and replaced with the synthesized events. e.g. + + perf inject --itrace -i perf.data -o perf.data.new
tools/perf/arch/x86/util/Build +2 -0
@@ -1,5 +1,6 @@ libperf-y += header.o libperf-y += tsc.o +libperf-y += pmu.o libperf-y += kvm-stat.o libperf-$(CONFIG_DWARF) += dwarf-regs.o
@@ -7,4 +8,5 @@ libperf-$(CONFIG_DWARF) += dwarf-regs.o libperf-$(CONFIG_LIBUNWIND) += unwind-libunwind.o libperf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o +libperf-$(CONFIG_AUXTRACE) += auxtrace.o libperf-$(CONFIG_AUXTRACE) += intel-pt.o
tools/perf/arch/x86/util/auxtrace.c new file +38 -0
@@ -0,0 +1,38 @@ +/* +* auxtrace.c: AUX area tracing support +* Copyright (c) 2013-2014, Intel Corporation. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +*/ + +#include "../../util/header.h" +#include "../../util/auxtrace.h" +#include "../../util/intel-pt.h" + +struct auxtrace_record *auxtrace_record__init (struct perf_evlist *evlist__maybe_unused , +int *err) +{ +char buffer[64 ]; +int ret; + + *err =0 ; + + ret =get_cpuid (buffer,sizeof (buffer)); +if (ret) { + *err = ret; +return NULL ; + } + +if (!strncmp (buffer,"GenuineIntel," ,13 )) +return intel_pt_recording_init (err); + +return NULL ; +}
tools/perf/arch/x86/util/pmu.c new file +15 -0
@@ -0,0 +1,15 @@ +#include <string.h> + +#include <linux/perf_event.h> + +#include "../../util/intel-pt.h" +#include "../../util/pmu.h" + +struct perf_event_attr *perf_pmu__get_default_config (struct perf_pmu *pmu__maybe_unused ) +{ +#ifdef HAVE_AUXTRACE_SUPPORT +if (!strcmp (pmu->name,INTEL_PT_PMU_NAME )) +return intel_pt_pmu_default_config (pmu); +#endif +return NULL ; +}
tools/perf/util/auxtrace.c +4 -1
@@ -47,6 +47,8 @@#include "debug.h" #include "parse-options.h" +#include "intel-pt.h" +int auxtrace_mmap__mmap (struct auxtrace_mmap *mm,struct auxtrace_mmap_params *mp,void *userpg,int fd)
@@ -877,7 +879,7 @@ static bool auxtrace__dont_decode(struct perf_session *session)int perf_event__process_auxtrace_info (struct perf_tool *tool__maybe_unused ,union perf_event *event, -struct perf_session *session__maybe_unused ) +struct perf_session *session) {enum auxtrace_type type = event->auxtrace_info.type;
@@ -886,6 +888,7 @@ int perf_event__process_auxtrace_info(struct perf_tool *tool __maybe_unused,switch (type) {case PERF_AUXTRACE_INTEL_PT : +return intel_pt_process_auxtrace_info (event, session);case PERF_AUXTRACE_UNKNOWN :default :return -EINVAL ;
Signature · 1 line
1.9.1
Adrian Hunter
reviewerPATCH v3 19/25 perf tools: Allow auxtrace data alignment
In reply to Adrian HunterAllow auxtrace data to be a multiple of
something other than page size. That is
needed for BTS where the buffer contains
24-byte records.
--- tools/perf/util/auxtrace.c | 7 +++++++ tools/perf/util/auxtrace.h | 1 + 2 files changed, 8 insertions(+)
tools/perf/util/auxtrace.c +7 -0
@@ -1187,6 +1187,13 @@ static int __auxtrace_mmap__read(struct auxtrace_mmap *mm, data2 =NULL ; } +if (itr->alignment) { +unsigned int unwanted = len1 % itr->alignment; + + len1 -= unwanted; + size -= unwanted; + } +/* padding must be written by fn() e.g. record__process_auxtrace() */ padding = size &7 ;if (padding)
tools/perf/util/auxtrace.h +1 -0
@@ -304,6 +304,7 @@ struct auxtrace_record { const char *str);u64 (*reference)(struct auxtrace_record *itr);int (*read_finish)(struct auxtrace_record *itr,int idx); +unsigned int alignment; };#ifdef HAVE_AUXTRACE_SUPPORT
Signature · 1 line
1.9.1
Adrian Hunter
reviewerPATCH v3 20/25 perf tools: Add Intel BTS support
In reply to Adrian Hunter--- tools/perf/Documentation/intel-bts.txt | 69 +++ tools/perf/arch/x86/util/Build | 1 + tools/perf/arch/x86/util/auxtrace.c | 49 +- tools/perf/arch/x86/util/intel-bts.c | 458 +++++++++++++++++++ tools/perf/util/Build | 1 + tools/perf/util/auxtrace.c | 3 + tools/perf/util/auxtrace.h | 1 + tools/perf/util/intel-bts.c | 790 +++++++++++++++++++++++++++++++++ tools/perf/util/intel-bts.h | 43 ++ 9 files changed, 1413 insertions(+), 2 deletions(-) create mode 100644 tools/perf/Documentation/intel-bts.txt create mode 100644 tools/perf/arch/x86/util/intel-bts.c create mode 100644 tools/perf/util/intel-bts.c create mode 100644 tools/perf/util/intel-bts.h
tools/perf/Documentation/intel-bts.txt new file +69 -0
@@ -0,0 +1,69 @@ +Intel Branch Trace Store +======================== + +perf record +=========== + +new event +--------- + +The Intel BTS kernel driver creates a new PMU for Intel BTS. The perf record +option is: + + -e intel_bts// + +Currently Intel BTS is limited to per-thread tracing so the --per-thread option +is also needed. + + +snapshot option +--------------- + +The snapshot option is the same as Intel PT (refer Intel PT documentation). + + +auxtrace mmap size option +----------------------- + +The mmap size option is the same as Intel PT (refer Intel PT documentation). + + +perf script +=========== + +By default, perf script will decode trace data found in the perf.data file. +This can be further controlled by option --itrace. The --itrace option is +the same as Intel PT (refer Intel PT documentation) except that neither +"instructions" events nor "transactions" events (and consequently call +chains) are supported. + +To disable trace decoding entirely, use the option --no-itrace. + + +dump option +----------- + +perf script has an option (-D) to "dump" the events i.e. display the binary +data. + +When -D is used, Intel BTS packets are displayed. + +To disable the display of Intel BTS packets, combine the -D option with +--no-itrace. + + +perf report +=========== + +By default, perf report will decode trace data found in the perf.data file. +This can be further controlled by new option --itrace exactly the same as +perf script. + + +perf inject +=========== + +perf inject also accepts the --itrace option in which case tracing data is +removed and replaced with the synthesized events. e.g. + + perf inject --itrace -i perf.data -o perf.data.new
tools/perf/arch/x86/util/Build +1 -0
@@ -10,3 +10,4 @@ libperf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o libperf-$(CONFIG_AUXTRACE) += auxtrace.o libperf-$(CONFIG_AUXTRACE) += intel-pt.o +libperf-$(CONFIG_AUXTRACE) += intel-bts.o
tools/perf/arch/x86/util/auxtrace.c +47 -2
65 lines not on this page · raw message
tools/perf/arch/x86/util/intel-bts.c new file +458 -0
458 lines not on this page · raw message
tools/perf/util/Build +1 -0
@@ -77,6 +77,7 @@ libperf-y += thread-stack.o libperf-$(CONFIG_AUXTRACE) += auxtrace.o libperf-$(CONFIG_AUXTRACE) += intel-pt-decoder/ libperf-$(CONFIG_AUXTRACE) += intel-pt.o +libperf-$(CONFIG_AUXTRACE) += intel-bts.o libperf-$(CONFIG_LIBELF) += symbol-elf.o libperf-$(CONFIG_LIBELF) += probe-event.o
tools/perf/util/auxtrace.c +3 -0
@@ -48,6 +48,7 @@#include "parse-options.h" #include "intel-pt.h" +#include "intel-bts.h" int auxtrace_mmap__mmap(struct auxtrace_mmap *mm, struct auxtrace_mmap_params *mp,
@@ -889,6 +890,8 @@ int perf_event__process_auxtrace_info(struct perf_tool *tool __maybe_unused,switch (type) {case PERF_AUXTRACE_INTEL_PT :return intel_pt_process_auxtrace_info (event, session); +case PERF_AUXTRACE_INTEL_BTS : +return intel_bts_process_auxtrace_info (event, session);case PERF_AUXTRACE_UNKNOWN :default :return -EINVAL ;
tools/perf/util/auxtrace.h +1 -0
@@ -40,6 +40,7 @@ struct events_stats;enum auxtrace_type {PERF_AUXTRACE_UNKNOWN ,PERF_AUXTRACE_INTEL_PT , +PERF_AUXTRACE_INTEL_BTS , };enum itrace_period_type {
tools/perf/util/intel-bts.c new file +790 -0
790 lines not on this page · raw message
tools/perf/util/intel-bts.h new file +43 -0
43 lines not on this page · raw message
Signature · 1 line
1.9.1
Adrian Hunter
reviewerPATCH v3 21/25 perf tools: Output sample flags and insn_len from intel_pt
In reply to Adrian Hunterintel_pt synthesizes samples. Fill in the new flags and insn_len members with instruction information.
--- tools/perf/util/intel-pt.c | 4 ++++ 1 file changed, 4 insertions(+)
tools/perf/util/intel-pt.c +4 -0
@@ -876,6 +876,8 @@ static int intel_pt_synth_branch_sample(struct intel_pt_queue *ptq) sample.stream_id = ptq->pt->branches_id; sample.period =1 ; sample.cpu = ptq->cpu; + sample.flags = ptq->flags; + sample.insn_len = ptq->insn_len;if (pt->branches_filter && !(pt->branches_filter & ptq->flags))return 0 ;
@@ -918,6 +920,8 @@ static int intel_pt_synth_instruction_sample(struct intel_pt_queue *ptq) sample.stream_id = ptq->pt->instructions_id; sample.period = ptq->pt->instructions_sample_period; sample.cpu = ptq->cpu; + sample.flags = ptq->flags; + sample.insn_len = ptq->insn_len;if (pt->synth_opts.callchain) { thread_stack__sample(ptq->thread, ptq->chain,
Signature · 1 line
1.9.1
Adrian Hunter
reviewerPATCH v3 22/25 perf tools: Output sample flags and insn_len from intel_bts
In reply to Adrian Hunterintel_bts synthesizes samples. Fill in the new flags and insn_len members with instruction information.
--- tools/perf/util/intel-bts.c | 127 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 123 insertions(+), 4 deletions(-)
tools/perf/util/intel-bts.c +123 -4
@@ -30,6 +30,7 @@#include "debug.h" #include "tsc.h" #include "auxtrace.h" +#include "intel-pt-decoder/intel-pt-insn-decoder.h" #include "intel-bts.h" #define MAX_TIMESTAMP (~0ULL)
@@ -55,6 +56,7 @@ struct intel_bts {bool cap_user_time_zero;struct itrace_synth_opts synth_opts;bool sample_branches; +u32 branches_filter;u64 branches_sample_type;u64 branches_id;size_t branches_event_size;
@@ -71,6 +73,8 @@ struct intel_bts_queue {pid_t tid;int cpu;u64 time; +struct intel_pt_insn intel_pt_insn; +u32 sample_flags; };struct branch {
@@ -278,6 +282,8 @@ static int intel_bts_synth_branch_sample(struct intel_bts_queue *btsq, sample.stream_id = btsq->bts->branches_id; sample.period =1 ; sample.cpu = btsq->cpu; + sample.flags = btsq->sample_flags; + sample.insn_len = btsq->intel_pt_insn.length;if (bts->synth_opts.inject) { event.sample.header.size = bts->branches_event_size;
@@ -297,11 +303,116 @@ static int intel_bts_synth_branch_sample(struct intel_bts_queue *btsq,return ret; } +static int intel_bts_get_next_insn (struct intel_bts_queue *btsq,u64 ip) +{ +struct machine *machine = btsq->bts->machine; +struct thread *thread; +struct addr_location al; +unsigned char buf[1024 ]; +size_t bufsz; +ssize_t len; +int x86_64; +uint8_t cpumode; + + bufsz =intel_pt_insn_max_size (); + +if (machine__kernel_ip (machine, ip)) + cpumode =PERF_RECORD_MISC_KERNEL ; +else + cpumode =PERF_RECORD_MISC_USER ; + + thread =machine__find_thread (machine,-1 , btsq->tid); +if (!thread) +return -1 ; + +thread__find_addr_map (thread, cpumode,MAP__FUNCTION , ip, &al); +if (!al.map || !al.map->dso) +return -1 ; + + len =dso__data_read_addr (al.map->dso, al.map, machine, ip, buf, bufsz); +if (len <=0 ) +return -1 ; + +/* Load maps to ensure dso->is_64_bit has been updated */ +map__load (al.map, machine->symbol_filter); + + x86_64 = al.map->dso->is_64_bit; + +if (intel_pt_get_insn (buf, len, x86_64, &btsq->intel_pt_insn)) +return -1 ; + +return 0 ; +} + +static int intel_bts_synth_error (struct intel_bts *bts,int cpu,pid_t pid, +pid_t tid,u64 ip) +{ +union perf_event event; +const char *msg ="Failed to get instruction" ; +int code =EILSEQ ; +int err; + +auxtrace_synth_error (&event.auxtrace_error,PERF_AUXTRACE_ERROR_ITRACE , + code, cpu, pid, tid, ip, msg); + + err =perf_session__deliver_synth_event (bts->session, &event,NULL ); +if (err) +pr_err ("Intel BTS: failed to deliver error event, error %d\n" , + err); + +return err; +} + +static int intel_bts_get_branch_type (struct intel_bts_queue *btsq, +struct branch *branch) +{ +int err; + +if (!branch->from) { +if (branch->to) + btsq->sample_flags =PERF_IP_FLAG_BRANCH | +PERF_IP_FLAG_TRACE_BEGIN ; +else + btsq->sample_flags =0 ; + btsq->intel_pt_insn.length =0 ; + }else if (!branch->to) { + btsq->sample_flags =PERF_IP_FLAG_BRANCH | +PERF_IP_FLAG_TRACE_END ; + btsq->intel_pt_insn.length =0 ; + }else { + err =intel_bts_get_next_insn (btsq, branch->from); +if (err) { + btsq->sample_flags =0 ; + btsq->intel_pt_insn.length =0 ; +if (!btsq->bts->synth_opts.errors) +return 0 ; + err =intel_bts_synth_error (btsq->bts, btsq->cpu, + btsq->pid, btsq->tid, + branch->from); +return err; + } + btsq->sample_flags =intel_pt_insn_type (btsq->intel_pt_insn.op); +/* Check for an async branch into the kernel */ +if (!machine__kernel_ip (btsq->bts->machine, branch->from) && +machine__kernel_ip (btsq->bts->machine, branch->to) && + btsq->sample_flags != (PERF_IP_FLAG_BRANCH | +PERF_IP_FLAG_CALL | +PERF_IP_FLAG_SYSCALLRET )) + btsq->sample_flags =PERF_IP_FLAG_BRANCH | +PERF_IP_FLAG_CALL | +PERF_IP_FLAG_ASYNC | +PERF_IP_FLAG_INTERRUPT ; + } + +return 0 ; +} +static int intel_bts_process_buffer (struct intel_bts_queue *btsq,struct auxtrace_buffer *buffer) {struct branch *branch; -size_t sz; +size_t sz, bsz =sizeof (struct branch ); +u32 filter = btsq->bts->branches_filter;int err =0 ;if (buffer->use_data) {
@@ -315,14 +426,15 @@ static int intel_bts_process_buffer(struct intel_bts_queue *btsq,if (!btsq->bts->sample_branches)return 0 ; -while (sz >sizeof (struct branch )) { +for (; sz > bsz; branch +=1 , sz -= bsz) {if (!branch->from && !branch->to)continue ; +intel_bts_get_branch_type (btsq, branch); +if (filter && !(filter & btsq->sample_flags)) +continue ; err =intel_bts_synth_branch_sample (btsq, branch);if (err)break ; - branch +=1 ; - sz -=sizeof (struct branch ); }return err; }
@@ -768,6 +880,13 @@ int intel_bts_process_auxtrace_info(union perf_event *event,else itrace_synth_opts__set_default (&bts->synth_opts); +if (bts->synth_opts.calls) + bts->branches_filter |=PERF_IP_FLAG_CALL |PERF_IP_FLAG_ASYNC | +PERF_IP_FLAG_TRACE_END ; +if (bts->synth_opts.returns) + bts->branches_filter |=PERF_IP_FLAG_RETURN | +PERF_IP_FLAG_TRACE_BEGIN ; + err =intel_bts_synth_events (bts, session);if (err) goto err_free_queues;
Signature · 1 line
1.9.1
Adrian Hunter
reviewerPATCH v3 23/25 perf tools: Intel PT to always update thread stack trace number
In reply to Adrian HunterThe enhanced thread stack is used by higher layers but still requires the trace number. The trace number is used to distinguish discontinuous sections of trace (for example from Snapshot mode or Sample mode), which cause the thread stack to be flushed.
--- tools/perf/util/intel-pt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/util/intel-pt.c +3 -1
@@ -265,7 +265,7 @@ static int intel_pt_get_trace(struct intel_pt_buffer *b, void *data)if (!old_buffer || ptq->pt->sampling_mode || (ptq->pt->snapshot_mode && !buffer->consecutive)) { b->consecutive = false; - b->trace_nr = buffer->buffer_nr; + b->trace_nr = buffer->buffer_nr +1 ; }else { b->consecutive = true; }
@@ -1065,6 +1065,8 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)thread_stack__event (ptq->thread, ptq->flags, state->from_ip, state->to_ip, ptq->insn_len, state->trace_nr); + else + thread_stack__set_trace_nr(ptq->thread, state->trace_nr);if (pt->sample_branches) { err =intel_pt_synth_branch_sample (ptq);
Signature · 1 line
1.9.1
Adrian Hunter
reviewerPATCH v3 24/25 perf tools: Intel BTS to always update thread stack trace number
In reply to Adrian HunterThe enhanced thread stack is used by higher layers but still requires the trace number. The trace number is used to distinguish discontinuous sections of trace (for example from Snapshot mode or Sample mode), which cause the thread stack to be flushed.
--- tools/perf/util/intel-bts.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
tools/perf/util/intel-bts.c +14 -4
@@ -27,6 +27,8 @@#include "machine.h" #include "session.h" #include "util.h" +#include "thread.h" +#include "thread-stack.h" #include "debug.h" #include "tsc.h" #include "auxtrace.h"
@@ -441,19 +443,22 @@ static int intel_bts_process_buffer(struct intel_bts_queue *btsq,static int intel_bts_process_queue (struct intel_bts_queue *btsq,u64 *timestamp) { -struct auxtrace_buffer *buffer = btsq->buffer; +struct auxtrace_buffer *buffer = btsq->buffer, *old_buffer = buffer;struct auxtrace_queue *queue; +struct thread *thread;int err;if (btsq->done)return 1 ;if (btsq->pid ==-1 ) { -struct thread *thread; - - thread =machine__find_thread (btsq->bts->machine,-1 , btsq->tid); + thread =machine__find_thread (btsq->bts->machine,-1 , + btsq->tid);if (thread) btsq->pid = thread->pid_; + }else { + thread =machine__findnew_thread (btsq->bts->machine, btsq->pid, + btsq->tid); } queue = &btsq->bts->queues.queue_array[btsq->queue_nr];
@@ -483,6 +488,11 @@ static int intel_bts_process_queue(struct intel_bts_queue *btsq, u64 *timestamp) intel_bts_do_fix_overlap(queue, buffer))return -ENOMEM ; +if (!btsq->bts->synth_opts.callchain && thread && + (!old_buffer || btsq->bts->sampling_mode || + (btsq->bts->snapshot_mode && !buffer->consecutive))) +thread_stack__set_trace_nr (thread, buffer->buffer_nr +1 ); + err =intel_bts_process_buffer (btsq, buffer);auxtrace_buffer__drop_data (buffer);
Signature · 1 line
1.9.1
Adrian Hunter
reviewerPATCH v3 25/25 perf tools: Add example call-graph script
In reply to Adrian Hunter--- .../scripts/python/call-graph-from-postgresql.py | 285 +++++++++++++++++++++ 1 file changed, 285 insertions(+) create mode 100644 tools/perf/scripts/python/call-graph-from-postgresql.py
tools/perf/scripts/python/call-graph-from-postgresql.py new file +285 -0
@@ -0,0 +1,285 @@ +#!/usr/bin/python2 +# call-graph-from-postgresql.py: create call-graph from postgresql database +# Copyright (c) 2014, Intel Corporation. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms and conditions of the GNU General Public License, +# version 2, as published by the Free Software Foundation. +# +# This program is distributed in the hope it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. + +import sys +from PySide.QtCore import * +from PySide.QtGui import * +from PySide.QtSql import * +from decimal import * + +class TreeItem(): + + def __init__(self, db, row, parent_item): + self.db = db + self.row = row + self.parent_item = parent_item + self.query_done = False; + self.child_count = 0 + self.child_items = [] + self.data = ["", "", "", "", "", "", ""] + self.comm_id = 0 + self.thread_id = 0 + self.call_path_id = 1 + self.branch_count = 0 + self.time = 0 + if not parent_item: + self.setUpRoot() + + def setUpRoot(self): + self.query_done = True + query = QSqlQuery(self.db) + ret = query.exec_('SELECT id, comm FROM comms') + if not ret: + raise Exception("Query failed: " + query.lastError().text()) + while query.next(): + if not query.value(0): + continue + child_item = TreeItem(self.db, self.child_count, self) + self.child_items.append(child_item) + self.child_count += 1 + child_item.setUpLevel1(query.value(0), query.value(1)) + + def setUpLevel1(self, comm_id, comm): + self.query_done = True; + self.comm_id = comm_id + self.data[0] = comm + self.child_items = [] + self.child_count = 0 + query = QSqlQuery(self.db) + ret = query.exec_('SELECT thread_id, ( SELECT pid FROM threads WHERE id = thread_id ), ( SELECT tid FROM threads WHERE id = thread_id ) FROM comm_threads WHERE comm_id = ' + str(comm_id)) + if not ret: + raise Exception("Query failed: " + query.lastError().text()) + while query.next(): + child_item = TreeItem(self.db, self.child_count, self) + self.child_items.append(child_item) + self.child_count += 1 + child_item.setUpLevel2(comm_id, query.value(0), query.value(1), query.value(2)) + + def setUpLevel2(self, comm_id, thread_id, pid, tid): + self.comm_id = comm_id + self.thread_id = thread_id + self.data[0] = str(pid) + ":" + str(tid) + + def getChildItem(self, row): + return self.child_items[row] + + def getParentItem(self): + return self.parent_item + + def getRow(self): + return self.row + + def timePercent(self, b): + if not self.time: + return "0.0" + x = (b * Decimal(100)) / self.time + return str(x.quantize(Decimal('.1'), rounding=ROUND_HALF_UP)) + + def branchPercent(self, b): + if not self.branch_count: + return "0.0" + x = (b * Decimal(100)) / self.branch_count + return str(x.quantize(Decimal('.1'), rounding=ROUND_HALF_UP)) + + def addChild(self, call_path_id, name, dso, count, time, branch_count): + child_item = TreeItem(self.db, self.child_count, self) + child_item.comm_id = self.comm_id + child_item.thread_id = self.thread_id + child_item.call_path_id = call_path_id + child_item.branch_count = branch_count + child_item.time = time + child_item.data[0] = name + if dso == "[kernel.kallsyms]": + dso = "[kernel]" + child_item.data[1] = dso + child_item.data[2] = str(count) + child_item.data[3] = str(time) + child_item.data[4] = self.timePercent(time) + child_item.data[5] = str(branch_count) + child_item.data[6] = self.branchPercent(branch_count) + self.child_items.append(child_item) + self.child_count += 1 + + def selectCalls(self): + self.query_done = True; + query = QSqlQuery(self.db) + ret = query.exec_('SELECT id, call_path_id, branch_count, call_time, return_time, ' + '( SELECT name FROM symbols WHERE id = ( SELECT symbol_id FROM call_paths WHERE id = call_path_id ) ), ' + '( SELECT short_name FROM dsos WHERE id = ( SELECT dso_id FROM symbols WHERE id = ( SELECT symbol_id FROM call_paths WHERE id = call_path_id ) ) ), ' + '( SELECT ip FROM call_paths where id = call_path_id ) ' + 'FROM calls WHERE parent_call_path_id = ' + str(self.call_path_id) + ' AND comm_id = ' + str(self.comm_id) + ' AND thread_id = ' + str(self.thread_id) + + 'ORDER BY call_path_id') + if not ret: + raise Exception("Query failed: " + query.lastError().text()) + last_call_path_id = 0 + name = "" + dso = "" + count = 0 + branch_count = 0 + total_branch_count = 0 + time = 0 + total_time = 0 + while query.next(): + if query.value(1) == last_call_path_id: + count += 1 + branch_count += query.value(2) + time += query.value(4) - query.value(3) + else: + if count: + self.addChild(last_call_path_id, name, dso, count, time, branch_count) + last_call_path_id = query.value(1) + name = query.value(5) + dso = query.value(6) + count = 1 + total_branch_count += branch_count + total_time += time + branch_count = query.value(2) + time = query.value(4) - query.value(3) + if count: + self.addChild(last_call_path_id, name, dso, count, time, branch_count) + total_branch_count += branch_count + total_time += time + # Top level does not have time or branch count, so fix that here + if total_branch_count > self.branch_count: + self.branch_count = total_branch_count + if self.branch_count: + for child_item in self.child_items: + child_item.data[6] = self.branchPercent(child_item.branch_count) + if total_time > self.time: + self.time = total_time + if self.time: + for child_item in self.child_items: + child_item.data[4] = self.timePercent(child_item.time) + + def childCount(self): + if not self.query_done: + self.selectCalls() + return self.child_count + + def columnCount(self): + return 7 + + def columnHeader(self, column): + headers = ["Call Path", "Object", "Count ", "Time (ns) ", "Time (%) ", "Branch Count ", "Branch Count (%) "] + return headers[column] + + def getData(self, column): + return self.data[column] + +class TreeModel(QAbstractItemModel): + + def __init__(self, db, parent=None): + super(TreeModel, self).__init__(parent) + self.db = db + self.root = TreeItem(db, 0, None) + + def columnCount(self, parent): + return self.root.columnCount() + + def rowCount(self, parent): + if parent.isValid(): + parent_item = parent.internalPointer() + else: + parent_item = self.root + return parent_item.childCount() + + def headerData(self, section, orientation, role): + if role == Qt.TextAlignmentRole: + if section > 1: + return Qt.AlignRight + if role != Qt.DisplayRole: + return None + if orientation != Qt.Horizontal: + return None + return self.root.columnHeader(section) + + def parent(self, child): + child_item = child.internalPointer() + if child_item is self.root: + return QModelIndex() + parent_item = child_item.getParentItem() + return self.createIndex(parent_item.getRow(), 0, parent_item) + + def index(self, row, column, parent): + if parent.isValid(): + parent_item = parent.internalPointer() + else: + parent_item = self.root + child_item = parent_item.getChildItem(row) + return self.createIndex(row, column, child_item) + + def data(self, index, role): + if role == Qt.TextAlignmentRole: + if index.column() > 1: + return Qt.AlignRight + if role != Qt.DisplayRole: + return None + index_item = index.internalPointer() + return index_item.getData(index.column()) + +class MainWindow(QMainWindow): + + def __init__(self, db, dbname, parent=None): + super(MainWindow, self).__init__(parent) + + self.setObjectName("MainWindow") + self.setWindowTitle("Call Graph: " + dbname) + self.move(100, 100) + self.resize(800, 600) + style = self.style() + icon = style.standardIcon(QStyle.SP_MessageBoxInformation) + self.setWindowIcon(icon); + + self.model = TreeModel(db) + + self.view = QTreeView() + self.view.setModel(self.model) + + self.setCentralWidget(self.view) + +if __name__ == '__main__': + if (len(sys.argv) < 2): + print >> sys.stderr, "Usage is: call-graph-from-postgresql.py <database name>" + raise Exception("Too few arguments") + + dbname = sys.argv[1] + + db = QSqlDatabase.addDatabase('QPSQL') + + opts = dbname.split() + for opt in opts: + if '=' in opt: + opt = opt.split('=') + if opt[0] == 'hostname': + db.setHostName(opt[1]) + elif opt[0] == 'port': + db.setPort(int(opt[1])) + elif opt[0] == 'username': + db.setUserName(opt[1]) + elif opt[0] == 'password': + db.setPassword(opt[1]) + elif opt[0] == 'dbname': + dbname = opt[1] + else: + dbname = opt + + db.setDatabaseName(dbname) + if not db.open(): + raise Exception("Failed to open database " + dbname + " error: " + db.lastError().text()) + + app = QApplication(sys.argv) + window = MainWindow(db, dbname) + window.show() + err = app.exec_() + db.close() + sys.exit(err)
Signature · 1 line
1.9.1
Arnaldo Carvalho de Melo
maintainerEm Fri, Apr 24, 2015 at 10:29:42PM +0300, Adrian Hunter escreveu:
Quoted 9 lines
Hi
Here is V3 patches for the introduction of an abstraction for using the AUX area and Instruction tracing.
The patches can also be found here:
Quoted 7 lines
An example perf.data file and build id archive can be found here:
http://git.infradead.org/~ahunter/tfr/
There is also a tar of the 3 most relevant files with debugging symbols. These need to be placed in under the correct paths in
/usr/lib/debugto get symbols.
Thanks a lot for making those files available, I'll try and push a first batch from what is in perf/core by now, the try those files, and then apply some more, hopefully finishing the outstanding ones over the weekend.
- Arnaldo
Quoted 202 lines
Changes in V3:
New patch:
perf tools: Amend mmap ref counting for the AUX area mmapMove some code under arch:
perf tools: Add Intel PT support
perf tools: Add Intel BTS supportUpdated documentation:
perf report: Add Instruction Tracing support
perf auxtrace: Add option to synthesize events for transactions perf tools: Take Intel PT into use
perf tools: Add Intel BTS supportPatches already applied:
perf header: Add AUX area tracing feature
perf evlist: Add support for mmapping an AUX area buffer
perf tools: Add user events for AUX area tracing
perf tools: Add support for AUX area recording
perf record: Add basic AUX area tracing support
perf record: Extend -m option for AUX area tracing mmap pages perf tools: Add a user event for AUX area tracing errors
perf session: Add hooks to allow transparent decoding of AUX area tracing data perf session: Add instruction tracing options
perf auxtrace: Add helpers for AUX area tracing errors
perf auxtrace: Add helpers for queuing AUX area tracing data perf auxtrace: Add a heap for sorting AUX area tracing queues perf auxtrace: Add processing for AUX area tracing events
perf auxtrace: Add a hashtable for caching
perf tools: Add member to struct dso for an instruction cache perf script: Add Instruction Tracing support
perf inject: Re-pipe AUX area tracing events
perf inject: Add Instruction Tracing support
perf script: Add field option 'flags' to print sample flags
perf tools: Addaux_watermarkmember of structperf_event_attrChanges in V2:
Get rid of
MIN()
perf auxtrace: Add helpers for AUX area tracing errors perf inject: Re-pipe AUX area tracing events
perf tools: Add build optionNO_AUXTRACEto exclude AUX area tracingIntel BTS can be used on most recent Intel CPUs. Intel PT is available on Broadwell.
Examples:
Trace 'ls' with Intel BTS userspace only
perf record --per-thread -e intel_bts//u ls perf report
perf scriptTrace 'ls' with Intel BTS kernel and userspace
~/libexec/perf-core/perf-with-kcore record bts-ls --per-thread -e intel_bts// -- ls ~/libexec/perf-core/perf-with-kcore report bts-ls ~/libexec/perf-core/perf-with-kcore script bts-ls
Trace 'ls' with Intel PT userspace only
perf record -e intel_pt//u ls
perf report
perf scriptTrace 'ls' with Intel PT kernel and userspace
~/libexec/perf-core/perf-with-kcore record pt-ls -e intel_pt// -- ls ~/libexec/perf-core/perf-with-kcore report pt-ls ~/libexec/perf-core/perf-with-kcore script pt-ls
The abstraction has two separate aspects:
1. recording AUX area data
2. processing AUX area dataRecording consists of mmapping a separate buffer and copying the data into the perf.data file. The buffer is an AUX area buffer. The data is written preceded by a new user event
PERF_RECORD_AUXTRACE. The data is too big to fit in the event but follows immediately afterward. Session processing has to skip to get to the next event header in a similar fashion to the existingPERF_RECORD_HEADER_TRACING_DATA
event. The main recording patches are:perf evlist: Add support for mmapping an AUX area buffer perf tools: Add user events for AUX area tracing perf tools: Add support for AUX area recording perf record: Add basic AUX area tracing support
Processing consists of providing hooks in session processing to enable a decoder to see all the events and deliver synthesized events transparently into the event stream. The main processing patch is:
perf session: Add hooks to allow transparent decoding of AUX area tracing data
Adrian Hunter (25):
perf tools: Amend mmap ref counting for the AUX area mmap perf script: Always allow fields 'addr' and 'cpu' for auxtrace perf report: Add Instruction Tracing support
perf tools: Add AUX area tracing index
perf tools: Hit all build ids when AUX area tracing
perf tools: Add build optionNO_AUXTRACEto exclude AUX area tracing perf auxtrace: Add option to synthesize events for transactions perf tools: Add support forPERF_RECORD_AUX
perf tools: Add support forPERF_RECORD_ITRACE_STARTperf tools: Add AUX area tracing Snapshot Mode
perf record: Add AUX area tracing Snapshot Mode support perf auxtrace: Add Intel PT as an AUX area tracing type perf tools: Add Intel PT packet decoder
perf tools: Add Intel PT instruction decoder
perf tools: Add Intel PT log
perf tools: Add Intel PT decoder
perf tools: Add Intel PT support
perf tools: Take Intel PT into use
perf tools: Allow auxtrace data alignment
perf tools: Add Intel BTS support
perf tools: Output sample flags andinsn_lenfromintel_ptperf tools: Output sample flags andinsn_lenfromintel_btsperf tools: Intel PT to always update thread stack trace number perf tools: Intel BTS to always update thread stack trace number perf tools: Add example call-graph scripttools/build/Makefile.build | 2 + tools/perf/.gitignore | 2 + tools/perf/Documentation/intel-bts.txt | 69 + tools/perf/Documentation/intel-pt.txt | 467 +++++ tools/perf/Documentation/perf-inject.txt | 9 +- tools/perf/Documentation/perf-record.txt | 7 + tools/perf/Documentation/perf-report.txt | 28 + tools/perf/Documentation/perf-script.txt | 9 +- tools/perf/Makefile.perf | 8 +- tools/perf/arch/x86/util/Build | 5 + tools/perf/arch/x86/util/auxtrace.c | 83 + tools/perf/arch/x86/util/intel-bts.c | 458 +++++ tools/perf/arch/x86/util/intel-pt.c | 752 ++++++++ tools/perf/arch/x86/util/pmu.c | 15 + tools/perf/builtin-buildid-list.c | 9 + tools/perf/builtin-inject.c | 78 +- tools/perf/builtin-record.c | 172 +- tools/perf/builtin-report.c | 11 + tools/perf/builtin-script.c | 29 +- tools/perf/config/Makefile | 5 + tools/perf/perf.h | 3 + .../scripts/python/call-graph-from-postgresql.py | 285 +++ tools/perf/tests/make | 2 + tools/perf/util/Build | 5 +- tools/perf/util/auxtrace.c | 322 +++- tools/perf/util/auxtrace.h | 220 +++ tools/perf/util/event.c | 39 + tools/perf/util/event.h | 24 + tools/perf/util/evlist.c | 2 +- tools/perf/util/header.c | 31 +- tools/perf/util/intel-bts.c | 919 ++++++++++ tools/perf/util/intel-bts.h | 43 + tools/perf/util/intel-pt-decoder/Build | 14 + .../perf/util/intel-pt-decoder/intel-pt-decoder.c | 1738 ++++++++++++++++++ .../perf/util/intel-pt-decoder/intel-pt-decoder.h | 89 + .../util/intel-pt-decoder/intel-pt-insn-decoder.c | 246 +++ .../util/intel-pt-decoder/intel-pt-insn-decoder.h | 65 + tools/perf/util/intel-pt-decoder/intel-pt-log.c | 155 ++ tools/perf/util/intel-pt-decoder/intel-pt-log.h | 52 + .../util/intel-pt-decoder/intel-pt-pkt-decoder.c | 400 +++++ .../util/intel-pt-decoder/intel-pt-pkt-decoder.h | 64 + tools/perf/util/intel-pt.c | 1897 ++++++++++++++++++++ tools/perf/util/intel-pt.h | 57 + tools/perf/util/machine.c | 21 + tools/perf/util/machine.h | 4 + tools/perf/util/parse-options.h | 4 + tools/perf/util/session.c | 32 + tools/perf/util/session.h | 1 + tools/perf/util/tool.h | 2 + 49 files changed, 8882 insertions(+), 72 deletions(-) create mode 100644 tools/perf/Documentation/intel-bts.txt create mode 100644 tools/perf/Documentation/intel-pt.txt create mode 100644 tools/perf/arch/x86/util/auxtrace.c create mode 100644 tools/perf/arch/x86/util/intel-bts.c create mode 100644 tools/perf/arch/x86/util/intel-pt.c create mode 100644 tools/perf/arch/x86/util/pmu.c create mode 100644 tools/perf/scripts/python/call-graph-from-postgresql.py create mode 100644 tools/perf/util/intel-bts.c create mode 100644 tools/perf/util/intel-bts.h create mode 100644 tools/perf/util/intel-pt-decoder/Build create mode 100644 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c create mode 100644 tools/perf/util/intel-pt-decoder/intel-pt-decoder.h create mode 100644 tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c create mode 100644 tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.h create mode 100644 tools/perf/util/intel-pt-decoder/intel-pt-log.c create mode 100644 tools/perf/util/intel-pt-decoder/intel-pt-log.h create mode 100644 tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c create mode 100644 tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.h create mode 100644 tools/perf/util/intel-pt.c create mode 100644 tools/perf/util/intel-pt.hRegards
Adrian
Arnaldo Carvalho de Melo
maintainerEm Fri, Apr 24, 2015 at 10:29:42PM +0300, Adrian Hunter escreveu:
Quoted 4 lines
Hi
Here is V3 patches for the introduction of an abstraction for using the AUX area and Instruction tracing.
Applied the first three, waiting for reaction to Jiri's comments to continue.
- Arnaldo