Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a3af66f5 authored by Ravi Bangoria's avatar Ravi Bangoria Committed by Arnaldo Carvalho de Melo
Browse files

perf script: Fix crash because of missing evsel->priv



'perf script' in piped mode is crashing because evsel->priv is not set
properly. Fix it.

Before:

  # perf record -o - -- ls | perf script
  <SNIP 'ls' output>
    Segmentation fault (core dumped)
  #

After:

  # perf record -o - -- ls | perf script
  <SNIP 'ls' output>
  ls 2282 1031.731974:  250000 cpu-clock:uhH:  7effe4b3d29e
  ls 2282 1031.732222:  250000 cpu-clock:uhH:  7effe4b3a650
  #

Signed-off-by: default avatarRavi Bangoria <ravi.bangoria@linux.ibm.com>
Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: David Carrillo-Cisneros <davidcc@google.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Fixes: a14390fd ("perf script: Allow creating per-event dump files")
Link: http://lkml.kernel.org/r/20180625124220.6434-3-ravi.bangoria@linux.ibm.com


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 10e9cec9
Loading
Loading
Loading
Loading
+14 −0
Original line number Original line Diff line number Diff line
@@ -1834,6 +1834,7 @@ static int process_attr(struct perf_tool *tool, union perf_event *event,
	struct perf_evlist *evlist;
	struct perf_evlist *evlist;
	struct perf_evsel *evsel, *pos;
	struct perf_evsel *evsel, *pos;
	int err;
	int err;
	static struct perf_evsel_script *es;


	err = perf_event__process_attr(tool, event, pevlist);
	err = perf_event__process_attr(tool, event, pevlist);
	if (err)
	if (err)
@@ -1842,6 +1843,19 @@ static int process_attr(struct perf_tool *tool, union perf_event *event,
	evlist = *pevlist;
	evlist = *pevlist;
	evsel = perf_evlist__last(*pevlist);
	evsel = perf_evlist__last(*pevlist);


	if (!evsel->priv) {
		if (scr->per_event_dump) {
			evsel->priv = perf_evsel_script__new(evsel,
						scr->session->data);
		} else {
			es = zalloc(sizeof(*es));
			if (!es)
				return -ENOMEM;
			es->fp = stdout;
			evsel->priv = es;
		}
	}

	if (evsel->attr.type >= PERF_TYPE_MAX &&
	if (evsel->attr.type >= PERF_TYPE_MAX &&
	    evsel->attr.type != PERF_TYPE_SYNTH)
	    evsel->attr.type != PERF_TYPE_SYNTH)
		return 0;
		return 0;