perf script: Few trivial fixes
cover perf script: Few trivial fixes
First patch fixes perf output field hint. Second and third fixes crash when used in a piped mode.
Ravi Bangoria (3):
perf script: Add missing output fields in a hint perf script: Fix crash because of missing evsel->priv perf script: Fix crash because of missing feat_op[] entry
tools/perf/builtin-script.c | 19 +++++++++++++++++-- tools/perf/util/header.c | 7 ++++++- 2 files changed, 23 insertions(+), 3 deletions(-)
Signature · 1 line
2.14.4
PATCH 1/3 perf script: Add missing output fields in a hint
Few fields are missing in a perf script -F hint. Add them.
--- tools/perf/builtin-script.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
tools/perf/builtin-script.c +3 -2
@@ -3113,8 +3113,9 @@ int cmd_script(int argc, const char **argv) "+field to add and -field to remove." "Valid types: hw,sw,trace,raw,synth. " "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso," - "addr,symoff,period,iregs,uregs,brstack,brstacksym,flags," - "bpf-output,callindent,insn,insnlen,brstackinsn,synth,phys_addr", + "addr,symoff,srcline,period,iregs,uregs,brstack," + "brstacksym,flags,bpf-output,brstackinsn,brstackoff," + "callindent,insn,insnlen,synth,phys_addr,metric,misc", parse_output_fields),OPT_BOOLEAN ('a' ,"all-cpus" , &system_wide, "system-wide collection from all CPUs"),
Signature · 1 line
2.14.4
PATCH 2/3 perf script: Fix crash because of missing evsel->priv
In reply to Ravi Bangoriaperf script in pipped mode is crashing because evsel->priv is not set properly. Fix it.
Before:
# ./perf record -o - -- ls | ./perf script
Segmentation fault (core dumped)After:
# ./perf record -o - -- ls | ./perf script ls 2282 1031.731974: 250000 cpu-clock:uhH: 7effe4b3d29e ls 2282 1031.732222: 250000 cpu-clock:uhH: 7effe4b3a650
--- tools/perf/builtin-script.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
tools/perf/builtin-script.c +14 -0
@@ -1822,6 +1822,7 @@ static int process_attr(struct perf_tool *tool, union perf_event *event,struct perf_evlist *evlist;struct perf_evsel *evsel, *pos;int err; +static struct perf_evsel_script *es; err =perf_event__process_attr (tool, event, pevlist);if (err)
@@ -1830,6 +1831,19 @@ static int process_attr(struct perf_tool *tool, union perf_event *event, evlist = *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 && evsel->attr.type !=PERF_TYPE_SYNTH )return 0 ;
Signature · 1 line
2.14.4
Arnaldo Carvalho de Melo
maintainerRe: [PATCH 2/3] perf script: Fix crash because of missing evsel->priv
Em Wed, Jun 20, 2018 at 07:00:29PM +0530, Ravi Bangoria escreveu:
Quoted 7 lines
perf script in pipped mode is crashing because
evsel->privis not set properly. Fix it.Before:
# ./perf record -o - -- ls | ./perf script Segmentation fault (core dumped)
Quoted 7 lines
After:
# ./perf record -o - -- ls | ./perf script ls 2282 1031.731974: 250000 cpu-clock:uhH: 7effe4b3d29e ls 2282 1031.732222: 250000 cpu-clock:uhH: 7effe4b3a650Signed-off-by Ravi Bangoria <[email protected]>Fixes a14390fde64e ("perf script: Allow creating per-event dump files")
Humm, this cset doesn't set evsel->priv to a 'struct perf_evsel_script' object, will check which one does to continue review.
- Arnaldo
Quoted 38 lines
--- tools/perf/builtin-script.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)tools/perf/builtin-script.c +14
-0@@ -1822,6 +1822,7 @@ static int process_attr(struct perf_tool *tool, union perf_event *event,struct perf_evlist *evlist;struct perf_evsel *evsel, *pos;int err; +static struct perf_evsel_script *es; err =perf_event__process_attr (tool, event, pevlist);if (err)@@ -1830,6 +1831,19 @@ static int process_attr(struct perf_tool *tool, union perf_event *event, evlist = *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 && evsel->attr.type !=PERF_TYPE_SYNTH )return 0 ;Signature · 1 line
2.14.4
Re: [PATCH 2/3] perf script: Fix crash because of missing evsel->priv
Hi Arnaldo,
Quoted 13 lines · Arnaldo Carvalho de Melo
Em Wed, Jun 20, 2018 at 07:00:29PM +0530, Ravi Bangoria escreveu:
Quoted 12 lines
perf script in pipped mode is crashing because
evsel->privis not set properly. Fix it.Before:
# ./perf record -o - -- ls | ./perf script Segmentation fault (core dumped)After:
# ./perf record -o - -- ls | ./perf script ls 2282 1031.731974: 250000 cpu-clock:uhH: 7effe4b3d29e ls 2282 1031.732222: 250000 cpu-clock:uhH: 7effe4b3a650
Quoted 5 lines
Quoted 2 lines
Signed-off-by Ravi Bangoria <[email protected]>Fixes a14390fde64e ("perf script: Allow creating per-event dump files")Humm, this cset doesn't set
evsel->privto a 'structperf_evsel_script' object, will check which one does to continue review.
Possible. Actually, git bisect led me to this commit.
Ravi
Re: [PATCH 2/3] perf script: Fix crash because of missing evsel->priv
In reply to Arnaldo Carvalho de MeloHi Arnaldo,
Quoted 13 lines · Arnaldo Carvalho de Melo
Em Wed, Jun 20, 2018 at 07:00:29PM +0530, Ravi Bangoria escreveu:
Quoted 12 lines
perf script in pipped mode is crashing because
evsel->privis not set properly. Fix it.Before:
# ./perf record -o - -- ls | ./perf script Segmentation fault (core dumped)After:
# ./perf record -o - -- ls | ./perf script ls 2282 1031.731974: 250000 cpu-clock:uhH: 7effe4b3d29e ls 2282 1031.732222: 250000 cpu-clock:uhH: 7effe4b3a650
Quoted 5 lines
Quoted 2 lines
Signed-off-by Ravi Bangoria <[email protected]>Fixes a14390fde64e ("perf script: Allow creating per-event dump files")Humm, this cset doesn't set
evsel->privto a 'structperf_evsel_script' object, will check which one does to continue review.
So, it's not about setting evsel->priv to 'struct perf_evsel_script', but it's about setting proper output stream, either file or stdout. When 'struct perf_evsel_script' was not introduced, we were setting evsel->priv to output stream. So I think, this commit missed to set evsel->priv properly in pipped case. Ex, below patch applied _directly_ on top of a14390fde64e fixes the issue.
------
tools/perf/builtin-script.c +3 -0
@@ -1645,6 +1645,9 @@ static int process_attr(struct perf_tool *tool, union perf_event *event, evlist = *pevlist; evsel =perf_evlist__last (*pevlist); +if (!evsel->priv) + evsel->priv = stdout; +if (evsel->attr.type >=PERF_TYPE_MAX && evsel->attr.type !=PERF_TYPE_SYNTH )return 0 ;
------
To me this commit seems to be the bad. Please let me know if that is not the case. I'll change the last patch as you suggested an post v2 soon.
Thanks,
Ravi
PATCH 3/3 perf script: Fix crash because of missing feat_op[] entry
In reply to Ravi Bangoriaperf_event__process_feature() tries to access feat_ops[feat].process which is not defined for feat = HEADER_LAST_FEATURE and thus perf is crashing. Add dummy entry for HEADER_LAST_FEATURE in the feat_ops.
Before:
# ./perf record -o - ls | ./perf script Segmentation fault (core dumped)
After:
# ./perf record -o - ls | ./perf script ls 7031 4392.099856: 250000 cpu-clock:uhH: 7f5e0ce7cd60 ls 7031 4392.100355: 250000 cpu-clock:uhH: 7f5e0c706ef7
--- tools/perf/util/header.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
tools/perf/util/header.c +6 -1
@@ -2555,14 +2555,18 @@ struct feature_ops { }/* feature_ops not implemented: */ +#define write_last_feature NULL +#define print_tracing_data NULL#define print_build_id NULL +#define print_last_feature NULL#define process_branch_stack NULL#define process_stat NULL +#define process_last_feature NULL -static const struct feature_ops feat_ops[HEADER_LAST_FEATURE ] = { +static const struct feature_ops feat_ops[HEADER_LAST_FEATURE +1 ] = {FEAT_OPN (TRACING_DATA , tracing_data, false),FEAT_OPN (BUILD_ID , build_id, false),FEAT_OPR (HOSTNAME , hostname, false),
@@ -2585,6 +2589,7 @@ static const struct feature_ops feat_ops[HEADER_LAST_FEATURE] = {FEAT_OPN (CACHE , cache, true),FEAT_OPR (SAMPLE_TIME , sample_time, false),FEAT_OPR (MEM_TOPOLOGY , mem_topology, true), + FEAT_OPN(LAST_FEATURE, last_feature, false), }; struct header_print_data {
Signature · 1 line
2.14.4
Arnaldo Carvalho de Melo
maintainerRe: [PATCH 3/3] perf script: Fix crash because of missing feat_op[] entry
Em Wed, Jun 20, 2018 at 07:00:30PM +0530, Ravi Bangoria escreveu:
Quoted 3 lines
perf_event__process_feature()tries to access feat_ops[feat].process which is not defined for feat =HEADER_LAST_FEATUREand thus perf is crashing. Add dummy entry forHEADER_LAST_FEATUREin thefeat_ops.
Humm, first impression is that we should check for HEADER_LAST_FEATURE and not try to access that array slot, as it is just a marker, not an actual feature.
- Arnaldo
Quoted 49 lines
Before:
# ./perf record -o - ls | ./perf script Segmentation fault (core dumped)After:
# ./perf record -o - ls | ./perf script ls 7031 4392.099856: 250000 cpu-clock:uhH: 7f5e0ce7cd60 ls 7031 4392.100355: 250000 cpu-clock:uhH: 7f5e0c706ef7Signed-off-by Ravi Bangoria <[email protected]>Fixes 57b5de463925 ("perf report: Support forced leader feature in pipe mode")--- tools/perf/util/header.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)tools/perf/util/header.c +6
-1@@ -2555,14 +2555,18 @@ struct feature_ops { }/* feature_ops not implemented: */ +#define write_last_feature NULL +#define print_tracing_data NULL#define print_build_id NULL +#define print_last_feature NULL#define process_branch_stack NULL#define process_stat NULL +#define process_last_feature NULL -static const struct feature_ops feat_ops[HEADER_LAST_FEATURE ] = { +static const struct feature_ops feat_ops[HEADER_LAST_FEATURE +1 ] = {FEAT_OPN (TRACING_DATA , tracing_data, false),FEAT_OPN (BUILD_ID , build_id, false),FEAT_OPR (HOSTNAME , hostname, false),@@ -2585,6 +2589,7 @@ static const struct feature_ops feat_ops[HEADER_LAST_FEATURE] = {FEAT_OPN (CACHE , cache, true),FEAT_OPR (SAMPLE_TIME , sample_time, false),FEAT_OPR (MEM_TOPOLOGY , mem_topology, true), + FEAT_OPN(LAST_FEATURE, last_feature, false), }; struct header_print_data {Signature · 1 line
2.14.4
Re: [PATCH 3/3] perf script: Fix crash because of missing feat_op[] entry
Hi Arnaldo,
Quoted 8 lines · Arnaldo Carvalho de Melo
Em Wed, Jun 20, 2018 at 07:00:30PM +0530, Ravi Bangoria escreveu:
Quoted 3 lines
perf_event__process_feature()tries to access feat_ops[feat].process which is not defined for feat =HEADER_LAST_FEATUREand thus perf is crashing. Add dummy entry forHEADER_LAST_FEATUREin thefeat_ops.Humm, first impression is that we should check for
HEADER_LAST_FEATUREand not try to access that array slot, as it is just a marker, not an actual feature.
Sure. Let me try to handle it inside perf_event__process_feature() itself. May be something like below.
-----
tools/perf/util/header.c +4 -1
@@ -3461,6 +3461,10 @@ int perf_event__process_feature(struct perf_tool *tool,return -1 ; } +/* HEADER_LAST_FEATURE is just a marker. Ignore it. */ +if (feat ==HEADER_LAST_FEATURE ) +return 0 ; +if (!feat_ops[feat].process)return 0 ; -----
Thanks,
Ravi