diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-11-09 14:04:26 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-11-16 12:49:53 -0500 |
commit | fa48c892645dfd3159e5aa6eb9cefd00d5cb347a (patch) | |
tree | eb6244d4faf57cd82647dffbb6dca7409d5f8a52 /tools/perf/builtin-script.c | |
parent | 60dbcd2532dd7eec2f1e23a37b80ff85d8fb2953 (diff) |
perf script: Fix --per-event-dump for auxtrace synth evsels
When processing PERF_RECORD_AUXTRACE_INFO several perf_evsel entries
will be synthesized and inserted into session->evlist, eventually ending
in perf_script.tool.sample(), which ends up calling builtin-script.c's
process_event(), that expects evsel->priv to be a perf_evsel_script
object with a valid FILE pointer in fp.
So we need to intercept the processing of PERF_RECORD_AUXTRACE_INFO and
then setup evsel->priv for these newly created perf_evsel instances, do
it to fix the segfault in process_event() trying to use a NULL for that
FILE pointer.
Reported-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
Cc: Wang Nan <wangnan0@huawei.com>
Cc: yuzhoujian <yuzhoujian@didichuxing.com>
Fixes: a14390fde64e ("perf script: Allow creating per-event dump files")
Link: http://lkml.kernel.org/n/tip-bthnur8r8de01gxvn2qayx6e@git.kernel.org
[ Merge fix by Ravi Bangoria before pushing upstream to preserv bisectability ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/builtin-script.c')
-rw-r--r-- | tools/perf/builtin-script.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 68f36dc0344f..9b43bda45a41 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c | |||
@@ -1955,6 +1955,16 @@ static int perf_script__fopen_per_event_dump(struct perf_script *script) | |||
1955 | struct perf_evsel *evsel; | 1955 | struct perf_evsel *evsel; |
1956 | 1956 | ||
1957 | evlist__for_each_entry(script->session->evlist, evsel) { | 1957 | evlist__for_each_entry(script->session->evlist, evsel) { |
1958 | /* | ||
1959 | * Already setup? I.e. we may be called twice in cases like | ||
1960 | * Intel PT, one for the intel_pt// and dummy events, then | ||
1961 | * for the evsels syntheized from the auxtrace info. | ||
1962 | * | ||
1963 | * Ses perf_script__process_auxtrace_info. | ||
1964 | */ | ||
1965 | if (evsel->priv != NULL) | ||
1966 | continue; | ||
1967 | |||
1958 | evsel->priv = perf_evsel_script__new(evsel, script->session->data); | 1968 | evsel->priv = perf_evsel_script__new(evsel, script->session->data); |
1959 | if (evsel->priv == NULL) | 1969 | if (evsel->priv == NULL) |
1960 | goto out_err_fclose; | 1970 | goto out_err_fclose; |
@@ -2838,6 +2848,25 @@ int process_cpu_map_event(struct perf_tool *tool __maybe_unused, | |||
2838 | return set_maps(script); | 2848 | return set_maps(script); |
2839 | } | 2849 | } |
2840 | 2850 | ||
2851 | #ifdef HAVE_AUXTRACE_SUPPORT | ||
2852 | static int perf_script__process_auxtrace_info(struct perf_tool *tool, | ||
2853 | union perf_event *event, | ||
2854 | struct perf_session *session) | ||
2855 | { | ||
2856 | int ret = perf_event__process_auxtrace_info(tool, event, session); | ||
2857 | |||
2858 | if (ret == 0) { | ||
2859 | struct perf_script *script = container_of(tool, struct perf_script, tool); | ||
2860 | |||
2861 | ret = perf_script__setup_per_event_dump(script); | ||
2862 | } | ||
2863 | |||
2864 | return ret; | ||
2865 | } | ||
2866 | #else | ||
2867 | #define perf_script__process_auxtrace_info 0 | ||
2868 | #endif | ||
2869 | |||
2841 | int cmd_script(int argc, const char **argv) | 2870 | int cmd_script(int argc, const char **argv) |
2842 | { | 2871 | { |
2843 | bool show_full_info = false; | 2872 | bool show_full_info = false; |
@@ -2866,7 +2895,7 @@ int cmd_script(int argc, const char **argv) | |||
2866 | .feature = perf_event__process_feature, | 2895 | .feature = perf_event__process_feature, |
2867 | .build_id = perf_event__process_build_id, | 2896 | .build_id = perf_event__process_build_id, |
2868 | .id_index = perf_event__process_id_index, | 2897 | .id_index = perf_event__process_id_index, |
2869 | .auxtrace_info = perf_event__process_auxtrace_info, | 2898 | .auxtrace_info = perf_script__process_auxtrace_info, |
2870 | .auxtrace = perf_event__process_auxtrace, | 2899 | .auxtrace = perf_event__process_auxtrace, |
2871 | .auxtrace_error = perf_event__process_auxtrace_error, | 2900 | .auxtrace_error = perf_event__process_auxtrace_error, |
2872 | .stat = perf_event__process_stat_event, | 2901 | .stat = perf_event__process_stat_event, |