perf diff: Fix segfault on perf diff -o N option
Namhyung Kim
maintainerPATCH 1/2 perf diff: Fix segfault on perf diff -o N option
The -o/--order option is to select column number to sort a diff result. It does the job by adding a hpp field at the beginning of the sort list. But it should not be added to the output field list as it has no callbacks required by a output field.
During the setup_sorting(), the perf_hpp__setup_output_field() appends given sort keys to the output field if it's not there already.
Originally it was checked by the fmt->list being non-empty. But commit 3f931f2c4274 changed it to check the ->equal callback. Anyway we don't need to add the pseudo hpp field to the output field list since it won't be used for output. So just skip fields if they have no ->color or
->entry callbacks.
--- tools/perf/ui/hist.c | 4 ++++ 1 file changed, 4 insertions(+)
tools/perf/ui/hist.c +4 -0
@@ -560,6 +560,10 @@ void perf_hpp__setup_output_field(struct perf_hpp_list *list)perf_hpp_list__for_each_sort_list (list, fmt) {struct perf_hpp_fmt *pos; +/* skip sort-only fields ("sort_compute" in perf diff) */ +if (!fmt->entry && !fmt->color) +continue ; +perf_hpp_list__for_each_format (list, pos) {if (fmt_equal (fmt, pos)) goto next;
Signature · 1 line
2.11.0
Namhyung Kim
maintainerPATCH 2/2 perf diff: Fix -o/--order option behavior (again)
The commit 21e6d8428664 changed list_add() to perf_hpp__register_sort_field(). However this resulted in a behavior change since the field was added to the tail instead of the head. So the -o option is mostly ignored due to its order in the list.
This patch fixes it by adding perf_hpp__prepend_sort_field().
--- tools/perf/builtin-diff.c | 2 +- tools/perf/ui/hist.c | 6 ++++++ tools/perf/util/hist.h | 7 +++++++ 3 files changed, 14 insertions(+), 1 deletion(-)
tools/perf/builtin-diff.c +1 -1
@@ -1199,7 +1199,7 @@ static int ui_init(void)BUG_ON (1 ); } -perf_hpp__register_sort_field (fmt); +perf_hpp__prepend_sort_field (fmt);return 0 ; }
tools/perf/ui/hist.c +6 -0
@@ -521,6 +521,12 @@ void perf_hpp_list__register_sort_field(struct perf_hpp_list *list,list_add_tail (&format->sort_list, &list->sorts); } +void perf_hpp_list__prepend_sort_field (struct perf_hpp_list *list, +struct perf_hpp_fmt *format) +{ +list_add (&format->sort_list, &list->sorts); +} +void perf_hpp__column_unregister (struct perf_hpp_fmt *format) {list_del (&format->list);
tools/perf/util/hist.h +7 -0
@@ -283,6 +283,8 @@ void perf_hpp_list__column_register(struct perf_hpp_list *list, struct perf_hpp_fmt *format);void perf_hpp_list__register_sort_field (struct perf_hpp_list *list,struct perf_hpp_fmt *format); +void perf_hpp_list__prepend_sort_field (struct perf_hpp_list *list, +struct perf_hpp_fmt *format);static inline void perf_hpp__column_register (struct perf_hpp_fmt *format) {
@@ -294,6 +296,11 @@ static inline void perf_hpp__register_sort_field(struct perf_hpp_fmt *format)perf_hpp_list__register_sort_field (&perf_hpp_list, format); } +static inline void perf_hpp__prepend_sort_field (struct perf_hpp_fmt *format) +{ +perf_hpp_list__prepend_sort_field (&perf_hpp_list, format); +} +#define perf_hpp_list__for_each_format (_list, format) \ list_for_each_entry(format, &(_list)->fields, list)
Signature · 1 line
2.11.0
Re: [PATCH 2/2] perf diff: Fix -o/--order option behavior (again)
Quoted 9 lines · Namhyung Kim
The commit
21e6d8428664changedlist_add()toperf_hpp__register_sort_field(). However this resulted in a behavior change since the field was added to the tail instead of the head. So the -o option is mostly ignored due to its order in the list.This patch fixes it by adding
perf_hpp__prepend_sort_field().Fixes 21e6d8428664 ("perf diff: Use perf_hpp__register_sort_field interface")Signed-off-by Namhyung Kim <[email protected]>
thanks,
jirka
tip-bot for Namhyung Kim
merge bot[tip:perf/urgent] perf diff: Fix -o/--order option behavior (again)
In reply to Namhyung Kimperf diff: Fix -o/--order option behavior (again)
Commit-ID: a1c9f97f0b64e6337d9cfcc08c134450934fdd90 Gitweb: http://git.kernel.org/tip/a1c9f97f0b64e6337d9cfcc08c134450934fdd90 Author: Namhyung Kim <[email protected]> AuthorDate: Wed, 18 Jan 2017 14:14:57 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 2 Feb 2017 11:39:09 -0300
perf diff: Fix -o/--order option behavior (again)
Commit 21e6d8428664 ("perf diff: Use perf_hpp__register_sort_field interface") changed list_add() to perf_hpp__register_sort_field().
This resulted in a behavior change since the field was added to the tail instead of the head. So the -o option is mostly ignored due to its order in the list.
This patch fixes it by adding perf_hpp__prepend_sort_field().
--- tools/perf/builtin-diff.c | 2 +- tools/perf/ui/hist.c | 6 ++++++ tools/perf/util/hist.h | 7 +++++++ 3 files changed, 14 insertions(+), 1 deletion(-)
tools/perf/builtin-diff.c +1 -1
@@ -1199,7 +1199,7 @@ static int ui_init(void)BUG_ON (1 ); } -perf_hpp__register_sort_field (fmt); +perf_hpp__prepend_sort_field (fmt);return 0 ; }
tools/perf/ui/hist.c +6 -0
@@ -521,6 +521,12 @@ void perf_hpp_list__register_sort_field(struct perf_hpp_list *list,list_add_tail (&format->sort_list, &list->sorts); } +void perf_hpp_list__prepend_sort_field (struct perf_hpp_list *list, +struct perf_hpp_fmt *format) +{ +list_add (&format->sort_list, &list->sorts); +} +void perf_hpp__column_unregister (struct perf_hpp_fmt *format) {list_del (&format->list);
tools/perf/util/hist.h +7 -0
@@ -283,6 +283,8 @@ void perf_hpp_list__column_register(struct perf_hpp_list *list, struct perf_hpp_fmt *format);void perf_hpp_list__register_sort_field (struct perf_hpp_list *list,struct perf_hpp_fmt *format); +void perf_hpp_list__prepend_sort_field (struct perf_hpp_list *list, +struct perf_hpp_fmt *format);static inline void perf_hpp__column_register (struct perf_hpp_fmt *format) {
@@ -294,6 +296,11 @@ static inline void perf_hpp__register_sort_field(struct perf_hpp_fmt *format)perf_hpp_list__register_sort_field (&perf_hpp_list, format); } +static inline void perf_hpp__prepend_sort_field (struct perf_hpp_fmt *format) +{ +perf_hpp_list__prepend_sort_field (&perf_hpp_list, format); +} +#define perf_hpp_list__for_each_format (_list, format) \ list_for_each_entry(format, &(_list)->fields, list)
Quoted 8 lines · Namhyung Kim
The -o/--order option is to select column number to sort a diff result. It does the job by adding a hpp field at the beginning of the sort list. But it should not be added to the output field list as it has no callbacks required by a output field.
During the
setup_sorting(), theperf_hpp__setup_output_field()appends given sort keys to the output field if it's not there already.
Quoted 8 lines
Originally it was checked by the
fmt->listbeing non-empty. But commit3f931f2c4274changed it to check the ->equal callback. Anyway we don't need to add the pseudo hpp field to the output field list since it won't be used for output. So just skip fields if they have no ->color or
->entry callbacks.Fixes 3f931f2c4274 ("perf hists: Make hpp setup function generic")Signed-off-by Namhyung Kim <[email protected]>
thanks,
jirka
Quoted 22 lines
--- tools/perf/ui/hist.c | 4 ++++ 1 file changed, 4 insertions(+)tools/perf/ui/hist.c +4
-0@@ -560,6 +560,10 @@ void perf_hpp__setup_output_field(struct perf_hpp_list *list)perf_hpp_list__for_each_sort_list (list, fmt) {struct perf_hpp_fmt *pos; +/* skip sort-only fields ("sort_compute" in perf diff) */ +if (!fmt->entry && !fmt->color) +continue ; +perf_hpp_list__for_each_format (list, pos) {if (fmt_equal (fmt, pos)) goto next;Signature · 1 line
2.11.0
Namhyung Kim
maintainerHi Arnaldo,
Could you please consider merging it to the perf/urgent?
Thanks,
Namhyung
Quoted 38 lines · Namhyung Kim
The -o/--order option is to select column number to sort a diff result. It does the job by adding a hpp field at the beginning of the sort list. But it should not be added to the output field list as it has no callbacks required by a output field.
During the
setup_sorting(), theperf_hpp__setup_output_field()appends given sort keys to the output field if it's not there already.Originally it was checked by the
fmt->listbeing non-empty. But commit3f931f2c4274changed it to check the ->equal callback. Anyway we don't need to add the pseudo hpp field to the output field list since it won't be used for output. So just skip fields if they have no ->color or
->entry callbacks.Fixes 3f931f2c4274 ("perf hists: Make hpp setup function generic")Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/ui/hist.c | 4 ++++ 1 file changed, 4 insertions(+)tools/perf/ui/hist.c +4
-0@@ -560,6 +560,10 @@ void perf_hpp__setup_output_field(struct perf_hpp_list *list)perf_hpp_list__for_each_sort_list (list, fmt) {struct perf_hpp_fmt *pos; +/* skip sort-only fields ("sort_compute" in perf diff) */ +if (!fmt->entry && !fmt->color) +continue ; +perf_hpp_list__for_each_format (list, pos) {if (fmt_equal (fmt, pos)) goto next;Signature · 1 line
2.11.0
Arnaldo Carvalho de Melo
maintainerEm Thu, Feb 02, 2017 at 11:43:03AM +0900, Namhyung Kim escreveu:
Quoted 3 lines
Hi Arnaldo,
Could you please consider merging it to the perf/urgent?
Fell thru the cracks, applied to perf/urgent, thanks for the reminder!
- Arnaldo
Quoted 43 lines
Thanks,
NamhyungQuoted 38 lines · Namhyung Kim
The -o/--order option is to select column number to sort a diff result. It does the job by adding a hpp field at the beginning of the sort list. But it should not be added to the output field list as it has no callbacks required by a output field.
During the
setup_sorting(), theperf_hpp__setup_output_field()appends given sort keys to the output field if it's not there already.Originally it was checked by the
fmt->listbeing non-empty. But commit3f931f2c4274changed it to check the ->equal callback. Anyway we don't need to add the pseudo hpp field to the output field list since it won't be used for output. So just skip fields if they have no ->color or
->entry callbacks.Fixes 3f931f2c4274 ("perf hists: Make hpp setup function generic")Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/ui/hist.c | 4 ++++ 1 file changed, 4 insertions(+)tools/perf/ui/hist.c +4
-0@@ -560,6 +560,10 @@ void perf_hpp__setup_output_field(struct perf_hpp_list *list)perf_hpp_list__for_each_sort_list (list, fmt) {struct perf_hpp_fmt *pos; +/* skip sort-only fields ("sort_compute" in perf diff) */ +if (!fmt->entry && !fmt->color) +continue ; +perf_hpp_list__for_each_format (list, pos) {if (fmt_equal (fmt, pos)) goto next;Signature · 1 line
2.11.0
tip-bot for Namhyung Kim
merge bot[tip:perf/urgent] perf diff: Fix segfault on 'perf diff -o N' option
In reply to Namhyung Kimperf diff: Fix segfault on 'perf diff -o N' option
Commit-ID: 8381cdd0e32dd748bd34ca3ace476949948bd793 Gitweb: http://git.kernel.org/tip/8381cdd0e32dd748bd34ca3ace476949948bd793 Author: Namhyung Kim <[email protected]> AuthorDate: Wed, 18 Jan 2017 14:14:56 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 2 Feb 2017 11:39:04 -0300
perf diff: Fix segfault on 'perf diff -o N' option
The -o/--order option is to select column number to sort a diff result.
It does the job by adding a hpp field at the beginning of the sort list. But it should not be added to the output field list as it has no callbacks required by a output field.
During the setup_sorting(), the perf_hpp__setup_output_field() appends the given sort keys to the output field if it's not there already.
Originally it was checked by fmt->list being non-empty. But commit 3f931f2c4274 ("perf hists: Make hpp setup function generic") changed it to check the ->equal callback.
Anyways, we don't need to add the pseudo hpp field to the output field list since it won't be used for output. So just skip fields if they have no ->color or ->entry callbacks.
--- tools/perf/ui/hist.c | 4 ++++ 1 file changed, 4 insertions(+)
tools/perf/ui/hist.c +4 -0
@@ -560,6 +560,10 @@ void perf_hpp__setup_output_field(struct perf_hpp_list *list)perf_hpp_list__for_each_sort_list (list, fmt) {struct perf_hpp_fmt *pos; +/* skip sort-only fields ("sort_compute" in perf diff) */ +if (!fmt->entry && !fmt->color) +continue ; +perf_hpp_list__for_each_format (list, pos) {if (fmt_equal (fmt, pos)) goto next;