perf tools: Add all matching dynamic sort keys for field name
Namhyung Kim
maintainerPATCH v3 1/5 perf tools: Add all matching dynamic sort keys for field name
When a perf.data file has multiple events, it's likely to be similar (tracepoint) events. In that case, they might have same field name so add all of them to sort keys instead of bailing out.
In addition, it contains a trivial whitespace fix at callsite of add_all_dynamic_fields().
--- tools/perf/util/sort.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)
tools/perf/util/sort.c +28 -1
@@ -1965,6 +1965,28 @@ static int add_all_dynamic_fields(struct perf_evlist *evlist, bool raw_trace)return 0 ; } +static int add_all_matching_fields (struct perf_evlist *evlist, +char *field_name,bool raw_trace) +{ +int ret = -ESRCH ; +struct perf_evsel *evsel; +struct format_field *field; + +evlist__for_each (evlist, evsel) { +if (evsel->attr.type !=PERF_TYPE_TRACEPOINT ) +continue ; + + field =pevent_find_any_field (evsel->tp_format, field_name); +if (field ==NULL ) +continue ; + + ret =__dynamic_dimension__add (evsel, field, raw_trace); +if (ret <0 ) +break ; + } +return ret; +} +static int add_dynamic_entry (struct perf_evlist *evlist,const char *tok) {char *str, *event_name, *field_name, *opt_name;
@@ -1995,7 +2017,12 @@ static int add_dynamic_entry(struct perf_evlist *evlist, const char *tok) }if (!strcmp (field_name,"trace_fields" )) { - ret =add_all_dynamic_fields (evlist ,raw_trace); + ret =add_all_dynamic_fields (evlist, raw_trace); + goto out; + } + +if (event_name ==NULL ) { + ret =add_all_matching_fields (evlist, field_name, raw_trace); goto out; }
Signature · 1 line
2.6.4
Namhyung Kim
maintainerPATCH v3 2/5 perf tools: Add document for dynamic sort keys
--- tools/perf/Documentation/perf-report.txt | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
tools/perf/Documentation/perf-report.txt +24 -0
@@ -117,6 +117,30 @@ OPTIONS And default sort keys are changed to comm, dso_from, symbol_from, dso_to and symbol_to, see '--branch-stack'. + If the data file has tracepoint event(s), following (dynamic) sort keys + are also available: + trace, trace_fields, [<event>.]<field>[/raw] + + - trace: pretty printed trace output in a single column + - trace_fields: fields in tracepoints in separate columns + - <field name>: optional event and field name for a specific field + + The last form consists of event and field names. If event name is + omitted, it searches all events for matching field name. The matched + field will be shown only for the event has the field. The event name + supports substring match so user doesn't need to specify full subsystem + and event name everytime. For example, 'sched:sched_switch' event can + be shortened to 'switch' as long as it's not ambiguous. Also event can + be specified by its index (starting from 1) preceded by the '%'. + So '%1' is the first event, '%2' is the second, and so on. + + The field name can have '/raw' suffix which disables pretty printing + and shows raw field value like hex numbers. The --raw-trace option + has the same effect for all dynamic sort keys. + + The default sort keys are changed to 'trace' if all events in the data + file are tracepoint. + -F:: --fields=:: Specify output field - multiple keys can be specified in CSV format.
Signature · 1 line
2.6.4
Namhyung Kim
maintainerPATCH v3 5/5 perf evlist: Add --trace-fields option to show trace fields
In reply to Namhyung KimTo use dynamic sort keys, it might be good to add an option to see the list of field names.
$ perf evlist -i perf.data.sched sched:sched_switch sched:sched_stat_wait sched:sched_stat_sleep sched:sched_stat_iowait sched:sched_stat_runtime sched:sched_process_fork sched:sched_wakeup sched:sched_wakeup_new sched:sched_migrate_task # Tip: use 'perf evlist --trace-fields' to show fields for tracepoint events
$ perf evlist -i perf.data.sched --trace-fields sched:sched_switch: trace_fields=prev_comm,prev_pid,prev_prio,prev_state,next_comm,next_pid,next_prio sched:sched_stat_wait: trace_fields=comm,pid,delay sched:sched_stat_sleep: trace_fields=comm,pid,delay sched:sched_stat_iowait: trace_fields=comm,pid,delay sched:sched_stat_runtime: trace_fields=comm,pid,runtime,vruntime sched:sched_process_fork: trace_fields=parent_comm,parent_pid,child_comm,child_pid sched:sched_wakeup: trace_fields=comm,pid,prio,success,target_cpu sched:sched_wakeup_new: trace_fields=comm,pid,prio,success,target_cpu sched:sched_migrate_task: trace_fields=comm,pid,prio,orig_cpu,dest_cpu
--- tools/perf/Documentation/perf-evlist.txt | 3 +++ tools/perf/builtin-evlist.c | 11 ++++++++++- tools/perf/util/evsel.c | 23 +++++++++++++++++++++++ tools/perf/util/evsel.h | 1 + 4 files changed, 37 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-evlist.txt +3 -0
@@ -32,6 +32,9 @@ OPTIONS --group:: Show event group information. +--trace-fields:: + Show tracepoint field names. + SEE ALSO -------- linkperf:perf-record[1], linkperf:perf-list[1],
tools/perf/builtin-evlist.c +10 -1
@@ -26,14 +26,22 @@ static int __cmd_evlist(const char *file_name, struct perf_attr_details *details .mode = PERF_DATA_MODE_READ, .force = details->force, }; +bool has_tracepoint = false; session =perf_session__new (&file,0 ,NULL );if (session ==NULL )return -1 ; -evlist__for_each (session->evlist, pos) +evlist__for_each (session->evlist, pos) {perf_evsel__fprintf (pos, details, stdout); +if (pos->attr.type ==PERF_TYPE_TRACEPOINT ) + has_tracepoint = true; + } + +if (has_tracepoint && !details->trace_fields) +printf ("# Tip: use 'perf evlist --trace-fields' to show fields for tracepoint events\n" ); +perf_session__delete (session);return 0 ; }
@@ -49,6 +57,7 @@ int cmd_evlist(int argc, const char **argv, const char *prefix __maybe_unused)OPT_BOOLEAN ('g' ,"group" , &details.event_group,"Show event group information" ),OPT_BOOLEAN ('f' ,"force" , &details.force,"don't complain, do it" ), +OPT_BOOLEAN (0 ,"trace-fields" , &details.trace_fields,"Show tracepoint fields" ),OPT_END () }; const char * const evlist_usage[] = {
tools/perf/util/evsel.c +23 -0
@@ -2298,6 +2298,29 @@ int perf_evsel__fprintf(struct perf_evsel *evsel, printed +=comma_fprintf (fp, &first," %s=%" PRIu64, term, (u64 )evsel->attr.sample_freq); } + +if (details->trace_fields) { +struct format_field *field; + +if (evsel->attr.type !=PERF_TYPE_TRACEPOINT ) { + printed +=comma_fprintf (fp, &first," (not a tracepoint)" ); + goto out; + } + + field = evsel->tp_format->format.fields; +if (field ==NULL ) { + printed +=comma_fprintf (fp, &first," (no trace field)" ); + goto out; + } + + printed +=comma_fprintf (fp, &first," trace_fields=%s" , field->name); + + field = field->next; +while (field) { + printed +=comma_fprintf (fp, &first,"%s" , field->name); + field = field->next; + } + } out:fputc ('\n' , fp);return ++printed;
tools/perf/util/evsel.h +1 -0
@@ -369,6 +369,7 @@ struct perf_attr_details {bool verbose;bool event_group;bool force; +bool trace_fields; }; int perf_evsel__fprintf(struct perf_evsel *evsel,
Signature · 1 line
2.6.4
Namhyung Kim
maintainerPATCH v3 3/5 perf tools: Fix dynamic sort keys to sort properly
In reply to Namhyung KimCurrently, the dynamic sort keys compares trace data using memcmp(). But for output sorting, it should check data size and compare by word. Also it sorted strings in reverse order, fix it.
Before)
$ perf report -F overhead -s prev_pid,next_pid
...
# Overhead prev_pid next_pid
# ........ .......... ..........
#
0.39% 490 0
9.12% 225 0
0.04% 224 0
0.51% 731 189
0.08% 731 3
0.12% 731 0
4.82% 729 0
0.08% 1229 0
0.20% 715 0
4.78% 189 225
...After)
$ perf report -F overhead -s prev_pid,next_pid
...
# Overhead prev_pid next_pid
# ........ .......... ..........
#
0.43% 0 7
0.04% 0 11
0.04% 0 12
0.08% 0 14
0.04% 0 17
0.08% 0 19
0.04% 0 22
0.04% 0 27
0.04% 0 37
0.04% 0 42
...--- tools/perf/util/sort.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-)
tools/perf/util/sort.c +46 -1
@@ -1798,6 +1798,51 @@ static int64_t __sort__hde_cmp(struct perf_hpp_fmt *fmt,return memcmp (a->raw_data + offset, b->raw_data + offset, size); } +static int64_t __sort__hde_sort (struct perf_hpp_fmt *fmt, +struct hist_entry *a,struct hist_entry *b) +{ +struct hpp_dynamic_entry *hde; +struct format_field *field; +unsigned offset, size; +int64_t *a64, *b64; +int32_t *a32, *b32; +int16_t *a16, *b16; + + hde = container_of(fmt, struct hpp_dynamic_entry, hpp); + + field = hde->field; +if (field->flags &FIELD_IS_DYNAMIC ) { +unsigned long long dyn; + +pevent_read_number_field (field, a->raw_data, &dyn); + offset = dyn &0xffff ; + size = (dyn >>16 ) &0xffff ; + }else { + offset = field->offset; + size = field->size; + } + +if (field->flags &FIELD_IS_STRING ) +return strcmp (b->raw_data + offset, a->raw_data + offset); + +switch (size) { +case 8 : + a64 = a->raw_data + offset; + b64 = b->raw_data + offset; +return *b64 - *a64; +case 4 : + a32 = a->raw_data + offset; + b32 = b->raw_data + offset; +return *b32 - *a32; +case 2 : + a16 = a->raw_data + offset; + b16 = b->raw_data + offset; +return *b16 - *a16; +default : +return memcmp (b->raw_data + offset, a->raw_data + offset, size); + } +} +bool perf_hpp__is_dynamic_entry (struct perf_hpp_fmt *fmt) {return fmt->cmp == __sort__hde_cmp;
@@ -1826,7 +1871,7 @@ __alloc_dynamic_entry(struct perf_evsel *evsel, struct format_field *field) hde->hpp.cmp = __sort__hde_cmp; hde->hpp.collapse = __sort__hde_cmp; - hde->hpp.sort = __sort__hde_cmp; + hde->hpp.sort = __sort__hde_sort;INIT_LIST_HEAD (&hde->hpp.list);INIT_LIST_HEAD (&hde->hpp.sort_list);
Signature · 1 line
2.6.4
Namhyung Kim
maintainerPATCH v3 4/5 perf tools: Support dynamic sort keys for -F/--fields
In reply to Namhyung KimNow dynamic sort keys are supported for tracepoint events, add it to output fields too.
--- tools/perf/util/sort.c | 51 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 18 deletions(-)
tools/perf/util/sort.c +33 -18
@@ -1964,7 +1964,7 @@ static struct perf_evsel *find_evsel(struct perf_evlist *evlist, char *event_namstatic int __dynamic_dimension__add (struct perf_evsel *evsel,struct format_field *field, -bool raw_trace) +bool raw_trace,bool is_sort_key) {struct hpp_dynamic_entry *hde;
@@ -1974,18 +1974,24 @@ static int __dynamic_dimension__add(struct perf_evsel *evsel, hde->raw_trace = raw_trace; -perf_hpp__register_sort_field (&hde->hpp); +if (is_sort_key) +perf_hpp__register_sort_field (&hde->hpp); +else +perf_hpp__column_register (&hde->hpp); +return 0 ; } -static int add_evsel_fields (struct perf_evsel *evsel,bool raw_trace) +static int add_evsel_fields (struct perf_evsel *evsel,bool raw_trace, +bool is_sort_key) {int ret;struct format_field *field; field = evsel->tp_format->format.fields;while (field) { - ret =__dynamic_dimension__add (evsel, field, raw_trace); + ret =__dynamic_dimension__add (evsel, field, raw_trace, + is_sort_key);if (ret <0 )return ret;
@@ -1994,7 +2000,8 @@ static int add_evsel_fields(struct perf_evsel *evsel, bool raw_trace)return 0 ; } -static int add_all_dynamic_fields (struct perf_evlist *evlist,bool raw_trace) +static int add_all_dynamic_fields (struct perf_evlist *evlist,bool raw_trace, +bool is_sort_key) {int ret;struct perf_evsel *evsel;
@@ -2003,7 +2010,7 @@ static int add_all_dynamic_fields(struct perf_evlist *evlist, bool raw_trace)if (evsel->attr.type !=PERF_TYPE_TRACEPOINT )continue ; - ret =add_evsel_fields (evsel, raw_trace); + ret =add_evsel_fields (evsel, raw_trace, is_sort_key);if (ret <0 )return ret; }
@@ -2011,7 +2018,8 @@ static int add_all_dynamic_fields(struct perf_evlist *evlist, bool raw_trace) }static int add_all_matching_fields (struct perf_evlist *evlist, -char *field_name,bool raw_trace) +char *field_name,bool raw_trace, +bool is_sort_key) {int ret = -ESRCH ;struct perf_evsel *evsel;
@@ -2025,14 +2033,16 @@ static int add_all_matching_fields(struct perf_evlist *evlist,if (field ==NULL )continue ; - ret =__dynamic_dimension__add (evsel, field, raw_trace); + ret =__dynamic_dimension__add (evsel, field, raw_trace, + is_sort_key);if (ret <0 )break ; }return ret; } -static int add_dynamic_entry (struct perf_evlist *evlist,const char *tok) +static int add_dynamic_entry (struct perf_evlist *evlist,const char *tok, +bool is_sort_key) {char *str, *event_name, *field_name, *opt_name;struct perf_evsel *evsel;
@@ -2062,12 +2072,13 @@ static int add_dynamic_entry(struct perf_evlist *evlist, const char *tok) }if (!strcmp (field_name,"trace_fields" )) { - ret =add_all_dynamic_fields (evlist, raw_trace); + ret =add_all_dynamic_fields (evlist, raw_trace, is_sort_key); goto out; }if (event_name ==NULL ) { - ret =add_all_matching_fields (evlist, field_name, raw_trace); + ret =add_all_matching_fields (evlist, field_name, raw_trace, + is_sort_key); goto out; }
@@ -2085,7 +2096,7 @@ static int add_dynamic_entry(struct perf_evlist *evlist, const char *tok) }if (!strcmp (field_name,"*" )) { - ret =add_evsel_fields (evsel, raw_trace); + ret =add_evsel_fields (evsel, raw_trace, is_sort_key); }else { field =pevent_find_any_field (evsel->tp_format, field_name);if (field ==NULL ) {
@@ -2094,7 +2105,8 @@ static int add_dynamic_entry(struct perf_evlist *evlist, const char *tok)return -ENOENT ; } - ret =__dynamic_dimension__add (evsel, field, raw_trace); + ret =__dynamic_dimension__add (evsel, field, raw_trace, + is_sort_key); } out:
@@ -2238,7 +2250,7 @@ static int sort_dimension__add(const char *tok,return 0 ; } -if (!add_dynamic_entry (evlist, tok)) +if (!add_dynamic_entry (evlist, tok, true))return 0 ;return -ESRCH ;
@@ -2443,7 +2455,7 @@ void sort__setup_elide(FILE *output) } } -static int output_field_add (char *tok) +static int output_field_add (struct perf_evlist *evlist,char *tok) {unsigned int i;
@@ -2483,6 +2495,9 @@ static int output_field_add(char *tok)return __sort_dimension__add_output (sd); } +if (!add_dynamic_entry (evlist, tok, false)) +return 0 ; +return -ESRCH ; }
@@ -2508,7 +2523,7 @@ bool is_strict_order(const char *order)return order && (*order !='+' ); } -static int __setup_output_field (void ) +static int __setup_output_field (struct perf_evlist *evlist) {char *tmp, *tok, *str, *strp;int ret = -EINVAL ;
@@ -2532,7 +2547,7 @@ static int __setup_output_field(void)for (tok =strtok_r (strp,", " , &tmp); tok; tok =strtok_r (NULL ,", " , &tmp)) { - ret =output_field_add (tok); + ret =output_field_add (evlist, tok);if (ret == -EINVAL ) {error ("Invalid --fields key: `%s'" , tok);break ;
@@ -2569,7 +2584,7 @@ int setup_sorting(struct perf_evlist *evlist)if (sort__mode !=SORT_MODE__DIFF )perf_hpp__init (); - err =__setup_output_field (); + err =__setup_output_field (evlist);if (err <0 )return err;
Signature · 1 line
2.6.4
Quoted 9 lines · Namhyung Kim
When a perf.data file has multiple events, it's likely to be similar (tracepoint) events. In that case, they might have same field name so add all of them to sort keys instead of bailing out.
In addition, it contains a trivial whitespace fix at callsite of
add_all_dynamic_fields().Acked-by Jiri Olsa <[email protected]>Signed-off-by Namhyung Kim <[email protected]>
hum, I haven't tried with this last version but I get all hist tests failing on acme's perf/core and it seems to be related to sorting changes:
[jolsa@krava perf]$ ./perf test hist
15: Test matching and linking multiple hists : FAILED! 25: Test filtering hist entries : FAILED! 28: Test output sorting of hist entries : FAILED! 29: Test cumulation of child hist entries : FAILED!
[jolsa@krava perf]$ ./perf test 15 -v
15: Test matching and linking multiple hists :
--- start ---
test child forked, pid 10676
perf: Segmentation fault
Obtained 16 stack frames. ./perf(dump_stack+0x2d) [0x50f1d7] ./perf(sighandler_dump_stack+0x2d) [0x50f2b7] /lib64/libc.so.6(+0x34a4f) [0x7fb0b1178a4f] ./perf() [0x508c40]
./perf() [0x508e23]
./perf(setup_sorting+0x26) [0x5097b0] ./perf(test__hists_link+0xb6) [0x487f43] ./perf() [0x4725c0]
./perf() [0x4726ff]
./perf() [0x472986]
./perf(cmd_test+0x1fe) [0x472ddc]
./perf() [0x49b2ab]
./perf() [0x49b513]
./perf() [0x49b661]
./perf(main+0x258) [0x49b9e2] /lib64/libc.so.6(__libc_start_main+0xef) [0x7fb0b11646ff] test child interrupted
---- end ----
Test matching and linking multiple hists: FAILED!
thanks,
jirka
Arnaldo Carvalho de Melo
maintainerEm Wed, Jan 06, 2016 at 12:19:39PM +0100, Jiri Olsa escreveu:
Quoted 8 lines · Namhyung Kim
Quoted 7 lines
When a perf.data file has multiple events, it's likely to be similar (tracepoint) events. In that case, they might have same field name so add all of them to sort keys instead of bailing out.
In addition, it contains a trivial whitespace fix at callsite of
add_all_dynamic_fields().
Quoted 6 lines
Quoted 2 lines
Acked-by Jiri Olsa <[email protected]>Signed-off-by Namhyung Kim <[email protected]>hum, I haven't tried with this last version but I get all hist tests failing on acme's perf/core and it seems to be related to sorting changes:
Bisected it down to
0337e6473845 ("perf tools: Make 'trace' or 'trace_fields' sort key default for tracepoint events")
Fixed with the following patch, which I'm folding into the above commit, thanks for the report!
- Arnaldo
tools/perf/util/sort.c +4 -1
@@ -2187,6 +2187,9 @@ static const char *get_default_sort_order(struct perf_evlist *evlist)BUG_ON (sort__mode >=ARRAY_SIZE (default_sort_orders)); +if (evlist ==NULL ) + goto out_no_evlist; +evlist__for_each (evlist, evsel) {if (evsel->attr.type !=PERF_TYPE_TRACEPOINT ) { use_trace = false;
@@ -2199,7 +2202,7 @@ static const char *get_default_sort_order(struct perf_evlist *evlist)if (symbol_conf.raw_trace)return "trace_fields" ; } - +out_no_evlist:return default_sort_orders[sort__mode]; }
Quoted 36 lines
[jolsa@krava perf]$ ./perf test hist
15: Test matching and linking multiple hists : FAILED! 25: Test filtering hist entries : FAILED! 28: Test output sorting of hist entries : FAILED! 29: Test cumulation of child hist entries : FAILED![jolsa@krava perf]$ ./perf test 15 -v
15: Test matching and linking multiple hists :
--- start ---
test child forked, pid 10676
perf: Segmentation fault
Obtained 16 stack frames. ./perf(dump_stack+0x2d) [0x50f1d7] ./perf(sighandler_dump_stack+0x2d) [0x50f2b7] /lib64/libc.so.6(+0x34a4f) [0x7fb0b1178a4f] ./perf() [0x508c40]
./perf() [0x508e23]
./perf(setup_sorting+0x26) [0x5097b0] ./perf(test__hists_link+0xb6) [0x487f43] ./perf() [0x4725c0]
./perf() [0x4726ff]
./perf() [0x472986]
./perf(cmd_test+0x1fe) [0x472ddc]
./perf() [0x49b2ab]
./perf() [0x49b513]
./perf() [0x49b661]
./perf(main+0x258) [0x49b9e2] /lib64/libc.so.6(__libc_start_main+0xef) [0x7fb0b11646ff] test child interrupted
---- end ----
Test matching and linking multiple hists: FAILED!thanks,
jirka
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v3 3/5] perf tools: Fix dynamic sort keys to sort properly
In reply to Namhyung KimEm Wed, Jan 06, 2016 at 09:54:59AM +0900, Namhyung Kim escreveu:
Quoted 3 lines
Currently, the dynamic sort keys compares trace data using
memcmp(). But for output sorting, it should check data size and compare by word. Also it sorted strings in reverse order, fix it.
Can this be broken down in two patches? This is complex code, lets try to make it as bisectable as possible.
- Arnaldo
Quoted 112 lines
Before)
$ perf report -F overhead -s prev_pid,next_pid ... # Overhead prev_pid next_pid # ........ .......... .......... # 0.39% 490 0 9.12% 225 0 0.04% 224 0 0.51% 731 189 0.08% 731 3 0.12% 731 0 4.82% 729 0 0.08% 1229 0 0.20% 715 0 4.78% 189 225 ...After)
$ perf report -F overhead -s prev_pid,next_pid ... # Overhead prev_pid next_pid # ........ .......... .......... # 0.43% 0 7 0.04% 0 11 0.04% 0 12 0.08% 0 14 0.04% 0 17 0.08% 0 19 0.04% 0 22 0.04% 0 27 0.04% 0 37 0.04% 0 42 ...Reported-by Arnaldo Carvalho de Melo <[email protected]>Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/util/sort.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-)tools/perf/util/sort.c +46
-1@@ -1798,6 +1798,51 @@ static int64_t __sort__hde_cmp(struct perf_hpp_fmt *fmt,return memcmp (a->raw_data + offset, b->raw_data + offset, size); } +static int64_t __sort__hde_sort (struct perf_hpp_fmt *fmt, +struct hist_entry *a,struct hist_entry *b) +{ +struct hpp_dynamic_entry *hde; +struct format_field *field; +unsigned offset, size; +int64_t *a64, *b64; +int32_t *a32, *b32; +int16_t *a16, *b16; + + hde = container_of(fmt, struct hpp_dynamic_entry, hpp); + + field = hde->field; +if (field->flags &FIELD_IS_DYNAMIC ) { +unsigned long long dyn; + +pevent_read_number_field (field, a->raw_data, &dyn); + offset = dyn &0xffff ; + size = (dyn >>16 ) &0xffff ; + }else { + offset = field->offset; + size = field->size; + } + +if (field->flags &FIELD_IS_STRING ) +return strcmp (b->raw_data + offset, a->raw_data + offset); + +switch (size) { +case 8 : + a64 = a->raw_data + offset; + b64 = b->raw_data + offset; +return *b64 - *a64; +case 4 : + a32 = a->raw_data + offset; + b32 = b->raw_data + offset; +return *b32 - *a32; +case 2 : + a16 = a->raw_data + offset; + b16 = b->raw_data + offset; +return *b16 - *a16; +default : +return memcmp (b->raw_data + offset, a->raw_data + offset, size); + } +} +bool perf_hpp__is_dynamic_entry (struct perf_hpp_fmt *fmt) {return fmt->cmp == __sort__hde_cmp;@@ -1826,7 +1871,7 @@ __alloc_dynamic_entry(struct perf_evsel *evsel, struct format_field *field) hde->hpp.cmp = __sort__hde_cmp; hde->hpp.collapse = __sort__hde_cmp; - hde->hpp.sort = __sort__hde_cmp; + hde->hpp.sort = __sort__hde_sort;INIT_LIST_HEAD (&hde->hpp.list);INIT_LIST_HEAD (&hde->hpp.sort_list);Signature · 1 line
2.6.4
Namhyung Kim
maintainerHi Arnaldo and Jiri,
Quoted 16 lines · Arnaldo Carvalho de Melo
Em Wed, Jan 06, 2016 at 12:19:39PM +0100, Jiri Olsa escreveu:
Quoted 8 lines · Namhyung Kim
Quoted 7 lines
When a perf.data file has multiple events, it's likely to be similar (tracepoint) events. In that case, they might have same field name so add all of them to sort keys instead of bailing out.
In addition, it contains a trivial whitespace fix at callsite of
add_all_dynamic_fields().Quoted 6 lines
Quoted 2 lines
Acked-by Jiri Olsa <[email protected]>Signed-off-by Namhyung Kim <[email protected]>hum, I haven't tried with this last version but I get all hist tests failing on acme's perf/core and it seems to be related to sorting changes:
Quoted 6 lines
Bisected it down to
0337e6473845("perf tools: Make 'trace' or 'trace_fields' sort key default for tracepoint events")Fixed with the following patch, which I'm folding into the above commit, thanks for the report!
Ouch, thank you for the fix! :)
Thanks,
Namhyung
Quoted 61 lines
tools/perf/util/sort.c +4
-1@@ -2187,6 +2187,9 @@ static const char *get_default_sort_order(struct perf_evlist *evlist)BUG_ON (sort__mode >=ARRAY_SIZE (default_sort_orders)); +if (evlist ==NULL ) + goto out_no_evlist; +evlist__for_each (evlist, evsel) {if (evsel->attr.type !=PERF_TYPE_TRACEPOINT ) { use_trace = false;@@ -2199,7 +2202,7 @@ static const char *get_default_sort_order(struct perf_evlist *evlist)if (symbol_conf.raw_trace)return "trace_fields" ; } - +out_no_evlist:return default_sort_orders[sort__mode]; }Quoted 37 lines
[jolsa@krava perf]$ ./perf test hist
15: Test matching and linking multiple hists : FAILED! 25: Test filtering hist entries : FAILED! 28: Test output sorting of hist entries : FAILED! 29: Test cumulation of child hist entries : FAILED![jolsa@krava perf]$ ./perf test 15 -v
15: Test matching and linking multiple hists :
--- start ---
test child forked, pid 10676
perf: Segmentation fault
Obtained 16 stack frames. ./perf(dump_stack+0x2d) [0x50f1d7] ./perf(sighandler_dump_stack+0x2d) [0x50f2b7] /lib64/libc.so.6(+0x34a4f) [0x7fb0b1178a4f] ./perf() [0x508c40]
./perf() [0x508e23]
./perf(setup_sorting+0x26) [0x5097b0] ./perf(test__hists_link+0xb6) [0x487f43] ./perf() [0x4725c0]
./perf() [0x4726ff]
./perf() [0x472986]
./perf(cmd_test+0x1fe) [0x472ddc]
./perf() [0x49b2ab]
./perf() [0x49b513]
./perf() [0x49b661]
./perf(main+0x258) [0x49b9e2] /lib64/libc.so.6(__libc_start_main+0xef) [0x7fb0b11646ff] test child interrupted
---- end ----
Test matching and linking multiple hists: FAILED!thanks,
jirka
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v3 5/5] perf evlist: Add --trace-fields option to show trace fields
In reply to Namhyung KimEm Wed, Jan 06, 2016 at 09:55:01AM +0900, Namhyung Kim escreveu:
Quoted 14 lines
To use dynamic sort keys, it might be good to add an option to see the list of field names.
$ perf evlist -i perf.data.sched sched:sched_switch sched:sched_stat_wait sched:sched_stat_sleep sched:sched_stat_iowait sched:sched_stat_runtime sched:sched_process_fork sched:sched_wakeup sched:sched_wakeup_new sched:sched_migrate_task # Tip: use 'perf evlist --trace-fields' to show fields for tracepoint events
Ok, almost there, question is: if I ask explicitely for "--trace-fields", why should we have the "trace_fields=" in all lines, instead of just:
$ perf evlist -i perf.data.sched --trace-fields sched:sched_switch: prev_comm,prev_pid,prev_prio,prev_state,next_comm,next_pid,next_prio sched:sched_stat_wait: comm,pid,delay
?
I like the lack of spaces after commans, this way we can double click and select the whole list, then edit it, etc.
- Arnaldo
Quoted 117 lines
$ perf evlist -i perf.data.sched --trace-fields sched:sched_switch: trace_fields=prev_comm,prev_pid,prev_prio,prev_state,next_comm,next_pid,next_prio sched:sched_stat_wait: trace_fields=comm,pid,delay sched:sched_stat_sleep: trace_fields=comm,pid,delay sched:sched_stat_iowait: trace_fields=comm,pid,delay sched:sched_stat_runtime: trace_fields=comm,pid,runtime,vruntime sched:sched_process_fork: trace_fields=parent_comm,parent_pid,child_comm,child_pid sched:sched_wakeup: trace_fields=comm,pid,prio,success,target_cpu sched:sched_wakeup_new: trace_fields=comm,pid,prio,success,target_cpu sched:sched_migrate_task: trace_fields=comm,pid,prio,orig_cpu,dest_cpuSigned-off-by Namhyung Kim <[email protected]>--- tools/perf/Documentation/perf-evlist.txt | 3 +++ tools/perf/builtin-evlist.c | 11 ++++++++++- tools/perf/util/evsel.c | 23 +++++++++++++++++++++++ tools/perf/util/evsel.h | 1 + 4 files changed, 37 insertions(+), 1 deletion(-)tools/perf/Documentation/perf-evlist.txt +3
-0@@ -32,6 +32,9 @@ OPTIONS --group:: Show event group information. +--trace-fields:: + Show tracepoint field names. + SEE ALSO -------- linkperf:perf-record[1], linkperf:perf-list[1],tools/perf/builtin-evlist.c +10
-1@@ -26,14 +26,22 @@ static int __cmd_evlist(const char *file_name, struct perf_attr_details *details .mode = PERF_DATA_MODE_READ, .force = details->force, }; +bool has_tracepoint = false; session =perf_session__new (&file,0 ,NULL );if (session ==NULL )return -1 ; -evlist__for_each (session->evlist, pos) +evlist__for_each (session->evlist, pos) {perf_evsel__fprintf (pos, details, stdout); +if (pos->attr.type ==PERF_TYPE_TRACEPOINT ) + has_tracepoint = true; + } + +if (has_tracepoint && !details->trace_fields) +printf ("# Tip: use 'perf evlist --trace-fields' to show fields for tracepoint events\n" ); +perf_session__delete (session);return 0 ; }@@ -49,6 +57,7 @@ int cmd_evlist(int argc, const char **argv, const char *prefix __maybe_unused)OPT_BOOLEAN ('g' ,"group" , &details.event_group,"Show event group information" ),OPT_BOOLEAN ('f' ,"force" , &details.force,"don't complain, do it" ), +OPT_BOOLEAN (0 ,"trace-fields" , &details.trace_fields,"Show tracepoint fields" ),OPT_END () }; const char * const evlist_usage[] = {tools/perf/util/evsel.c +23
-0@@ -2298,6 +2298,29 @@ int perf_evsel__fprintf(struct perf_evsel *evsel, printed +=comma_fprintf (fp, &first," %s=%" PRIu64, term, (u64 )evsel->attr.sample_freq); } + +if (details->trace_fields) { +struct format_field *field; + +if (evsel->attr.type !=PERF_TYPE_TRACEPOINT ) { + printed +=comma_fprintf (fp, &first," (not a tracepoint)" ); + goto out; + } + + field = evsel->tp_format->format.fields; +if (field ==NULL ) { + printed +=comma_fprintf (fp, &first," (no trace field)" ); + goto out; + } + + printed +=comma_fprintf (fp, &first," trace_fields=%s" , field->name); + + field = field->next; +while (field) { + printed +=comma_fprintf (fp, &first,"%s" , field->name); + field = field->next; + } + } out:fputc ('\n' , fp);return ++printed;tools/perf/util/evsel.h +1
-0@@ -369,6 +369,7 @@ struct perf_attr_details {bool verbose;bool event_group;bool force; +bool trace_fields; }; int perf_evsel__fprintf(struct perf_evsel *evsel,Signature · 1 line
2.6.4
Namhyung Kim
maintainerRe: [PATCH v3 5/5] perf evlist: Add --trace-fields option to show trace fields
Quoted 21 lines · Arnaldo Carvalho de Melo
Em Wed, Jan 06, 2016 at 09:55:01AM +0900, Namhyung Kim escreveu:
Quoted 14 lines
To use dynamic sort keys, it might be good to add an option to see the list of field names.
$ perf evlist -i perf.data.sched sched:sched_switch sched:sched_stat_wait sched:sched_stat_sleep sched:sched_stat_iowait sched:sched_stat_runtime sched:sched_process_fork sched:sched_wakeup sched:sched_wakeup_new sched:sched_migrate_task # Tip: use 'perf evlist --trace-fields' to show fields for tracepoint eventsOk, almost there, question is: if I ask explicitely for "--trace-fields", why should we have the "trace_fields=" in all lines, instead of just:
Quoted 5 lines
$ perf evlist -i perf.data.sched --trace-fields sched:sched_switch: prev_comm,prev_pid,prev_prio,prev_state,next_comm,next_pid,next_prio sched:sched_stat_wait: comm,pid,delay?
I made it to work with other options too, like 'perf evlist --freq --trace-fields'. In that case you may want to see it. :)
Thanks,
Namhyung
Quoted 123 lines
I like the lack of spaces after commans, this way we can double click and select the whole list, then edit it, etc.
- Arnaldo
Quoted 117 lines
$ perf evlist -i perf.data.sched --trace-fields sched:sched_switch: trace_fields=prev_comm,prev_pid,prev_prio,prev_state,next_comm,next_pid,next_prio sched:sched_stat_wait: trace_fields=comm,pid,delay sched:sched_stat_sleep: trace_fields=comm,pid,delay sched:sched_stat_iowait: trace_fields=comm,pid,delay sched:sched_stat_runtime: trace_fields=comm,pid,runtime,vruntime sched:sched_process_fork: trace_fields=parent_comm,parent_pid,child_comm,child_pid sched:sched_wakeup: trace_fields=comm,pid,prio,success,target_cpu sched:sched_wakeup_new: trace_fields=comm,pid,prio,success,target_cpu sched:sched_migrate_task: trace_fields=comm,pid,prio,orig_cpu,dest_cpuSigned-off-by Namhyung Kim <[email protected]>--- tools/perf/Documentation/perf-evlist.txt | 3 +++ tools/perf/builtin-evlist.c | 11 ++++++++++- tools/perf/util/evsel.c | 23 +++++++++++++++++++++++ tools/perf/util/evsel.h | 1 + 4 files changed, 37 insertions(+), 1 deletion(-)tools/perf/Documentation/perf-evlist.txt +3
-0@@ -32,6 +32,9 @@ OPTIONS --group:: Show event group information. +--trace-fields:: + Show tracepoint field names. + SEE ALSO -------- linkperf:perf-record[1], linkperf:perf-list[1],tools/perf/builtin-evlist.c +10
-1@@ -26,14 +26,22 @@ static int __cmd_evlist(const char *file_name, struct perf_attr_details *details .mode = PERF_DATA_MODE_READ, .force = details->force, }; +bool has_tracepoint = false; session =perf_session__new (&file,0 ,NULL );if (session ==NULL )return -1 ; -evlist__for_each (session->evlist, pos) +evlist__for_each (session->evlist, pos) {perf_evsel__fprintf (pos, details, stdout); +if (pos->attr.type ==PERF_TYPE_TRACEPOINT ) + has_tracepoint = true; + } + +if (has_tracepoint && !details->trace_fields) +printf ("# Tip: use 'perf evlist --trace-fields' to show fields for tracepoint events\n" ); +perf_session__delete (session);return 0 ; }@@ -49,6 +57,7 @@ int cmd_evlist(int argc, const char **argv, const char *prefix __maybe_unused)OPT_BOOLEAN ('g' ,"group" , &details.event_group,"Show event group information" ),OPT_BOOLEAN ('f' ,"force" , &details.force,"don't complain, do it" ), +OPT_BOOLEAN (0 ,"trace-fields" , &details.trace_fields,"Show tracepoint fields" ),OPT_END () }; const char * const evlist_usage[] = {tools/perf/util/evsel.c +23
-0@@ -2298,6 +2298,29 @@ int perf_evsel__fprintf(struct perf_evsel *evsel, printed +=comma_fprintf (fp, &first," %s=%" PRIu64, term, (u64 )evsel->attr.sample_freq); } + +if (details->trace_fields) { +struct format_field *field; + +if (evsel->attr.type !=PERF_TYPE_TRACEPOINT ) { + printed +=comma_fprintf (fp, &first," (not a tracepoint)" ); + goto out; + } + + field = evsel->tp_format->format.fields; +if (field ==NULL ) { + printed +=comma_fprintf (fp, &first," (no trace field)" ); + goto out; + } + + printed +=comma_fprintf (fp, &first," trace_fields=%s" , field->name); + + field = field->next; +while (field) { + printed +=comma_fprintf (fp, &first,"%s" , field->name); + field = field->next; + } + } out:fputc ('\n' , fp);return ++printed;tools/perf/util/evsel.h +1
-0@@ -369,6 +369,7 @@ struct perf_attr_details {bool verbose;bool event_group;bool force; +bool trace_fields; }; int perf_evsel__fprintf(struct perf_evsel *evsel,Signature · 1 line
2.6.4
Namhyung Kim
maintainerRe: [PATCH v3 3/5] perf tools: Fix dynamic sort keys to sort properly
In reply to Arnaldo Carvalho de MeloQuoted 7 lines · Arnaldo Carvalho de Melo
Em Wed, Jan 06, 2016 at 09:54:59AM +0900, Namhyung Kim escreveu:
Quoted 3 lines
Currently, the dynamic sort keys compares trace data using
memcmp(). But for output sorting, it should check data size and compare by word. Also it sorted strings in reverse order, fix it.Can this be broken down in two patches? This is complex code, lets try to make it as bisectable as possible.
OK, I'll break out the string part then. But I think it doesn't help much to reduce the complexity.
Thanks,
Namhyung
Quoted 115 lines
- Arnaldo
Quoted 112 lines
Before)
$ perf report -F overhead -s prev_pid,next_pid ... # Overhead prev_pid next_pid # ........ .......... .......... # 0.39% 490 0 9.12% 225 0 0.04% 224 0 0.51% 731 189 0.08% 731 3 0.12% 731 0 4.82% 729 0 0.08% 1229 0 0.20% 715 0 4.78% 189 225 ...After)
$ perf report -F overhead -s prev_pid,next_pid ... # Overhead prev_pid next_pid # ........ .......... .......... # 0.43% 0 7 0.04% 0 11 0.04% 0 12 0.08% 0 14 0.04% 0 17 0.08% 0 19 0.04% 0 22 0.04% 0 27 0.04% 0 37 0.04% 0 42 ...Reported-by Arnaldo Carvalho de Melo <[email protected]>Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/util/sort.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-)tools/perf/util/sort.c +46
-1@@ -1798,6 +1798,51 @@ static int64_t __sort__hde_cmp(struct perf_hpp_fmt *fmt,return memcmp (a->raw_data + offset, b->raw_data + offset, size); } +static int64_t __sort__hde_sort (struct perf_hpp_fmt *fmt, +struct hist_entry *a,struct hist_entry *b) +{ +struct hpp_dynamic_entry *hde; +struct format_field *field; +unsigned offset, size; +int64_t *a64, *b64; +int32_t *a32, *b32; +int16_t *a16, *b16; + + hde = container_of(fmt, struct hpp_dynamic_entry, hpp); + + field = hde->field; +if (field->flags &FIELD_IS_DYNAMIC ) { +unsigned long long dyn; + +pevent_read_number_field (field, a->raw_data, &dyn); + offset = dyn &0xffff ; + size = (dyn >>16 ) &0xffff ; + }else { + offset = field->offset; + size = field->size; + } + +if (field->flags &FIELD_IS_STRING ) +return strcmp (b->raw_data + offset, a->raw_data + offset); + +switch (size) { +case 8 : + a64 = a->raw_data + offset; + b64 = b->raw_data + offset; +return *b64 - *a64; +case 4 : + a32 = a->raw_data + offset; + b32 = b->raw_data + offset; +return *b32 - *a32; +case 2 : + a16 = a->raw_data + offset; + b16 = b->raw_data + offset; +return *b16 - *a16; +default : +return memcmp (b->raw_data + offset, a->raw_data + offset, size); + } +} +bool perf_hpp__is_dynamic_entry (struct perf_hpp_fmt *fmt) {return fmt->cmp == __sort__hde_cmp;@@ -1826,7 +1871,7 @@ __alloc_dynamic_entry(struct perf_evsel *evsel, struct format_field *field) hde->hpp.cmp = __sort__hde_cmp; hde->hpp.collapse = __sort__hde_cmp; - hde->hpp.sort = __sort__hde_cmp; + hde->hpp.sort = __sort__hde_sort;INIT_LIST_HEAD (&hde->hpp.list);INIT_LIST_HEAD (&hde->hpp.sort_list);Signature · 1 line
2.6.4
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v3 5/5] perf evlist: Add --trace-fields option to show trace fields
In reply to Namhyung KimEm Thu, Jan 07, 2016 at 08:21:44AM +0900, Namhyung Kim escreveu:
Quoted 22 lines · Arnaldo Carvalho de Melo
Quoted 21 lines
Em Wed, Jan 06, 2016 at 09:55:01AM +0900, Namhyung Kim escreveu:
Quoted 14 lines
To use dynamic sort keys, it might be good to add an option to see the list of field names.
$ perf evlist -i perf.data.sched sched:sched_switch sched:sched_stat_wait sched:sched_stat_sleep sched:sched_stat_iowait sched:sched_stat_runtime sched:sched_process_fork sched:sched_wakeup sched:sched_wakeup_new sched:sched_migrate_task # Tip: use 'perf evlist --trace-fields' to show fields for tracepoint eventsOk, almost there, question is: if I ask explicitely for "--trace-fields", why should we have the "trace_fields=" in all lines, instead of just:
Quoted 8 lines
Quoted 5 lines
$ perf evlist -i perf.data.sched --trace-fields sched:sched_switch: prev_comm,prev_pid,prev_prio,prev_state,next_comm,next_pid,next_prio sched:sched_stat_wait: comm,pid,delay?
I made it to work with other options too, like 'perf evlist --freq --trace-fields'. In that case you may want to see it. :)
I see... And then you want to show those at the same time... Would you have an use case for that? Or would it be better to make them mutually exclusive? /me unsure...
- Arnaldo
Quoted 127 lines
Thanks,
NamhyungQuoted 123 lines
I like the lack of spaces after commans, this way we can double click and select the whole list, then edit it, etc.
- Arnaldo
Quoted 117 lines
$ perf evlist -i perf.data.sched --trace-fields sched:sched_switch: trace_fields=prev_comm,prev_pid,prev_prio,prev_state,next_comm,next_pid,next_prio sched:sched_stat_wait: trace_fields=comm,pid,delay sched:sched_stat_sleep: trace_fields=comm,pid,delay sched:sched_stat_iowait: trace_fields=comm,pid,delay sched:sched_stat_runtime: trace_fields=comm,pid,runtime,vruntime sched:sched_process_fork: trace_fields=parent_comm,parent_pid,child_comm,child_pid sched:sched_wakeup: trace_fields=comm,pid,prio,success,target_cpu sched:sched_wakeup_new: trace_fields=comm,pid,prio,success,target_cpu sched:sched_migrate_task: trace_fields=comm,pid,prio,orig_cpu,dest_cpuSigned-off-by Namhyung Kim <[email protected]>--- tools/perf/Documentation/perf-evlist.txt | 3 +++ tools/perf/builtin-evlist.c | 11 ++++++++++- tools/perf/util/evsel.c | 23 +++++++++++++++++++++++ tools/perf/util/evsel.h | 1 + 4 files changed, 37 insertions(+), 1 deletion(-)tools/perf/Documentation/perf-evlist.txt +3
-0@@ -32,6 +32,9 @@ OPTIONS --group:: Show event group information. +--trace-fields:: + Show tracepoint field names. + SEE ALSO -------- linkperf:perf-record[1], linkperf:perf-list[1],tools/perf/builtin-evlist.c +10
-1@@ -26,14 +26,22 @@ static int __cmd_evlist(const char *file_name, struct perf_attr_details *details .mode = PERF_DATA_MODE_READ, .force = details->force, }; +bool has_tracepoint = false; session =perf_session__new (&file,0 ,NULL );if (session ==NULL )return -1 ; -evlist__for_each (session->evlist, pos) +evlist__for_each (session->evlist, pos) {perf_evsel__fprintf (pos, details, stdout); +if (pos->attr.type ==PERF_TYPE_TRACEPOINT ) + has_tracepoint = true; + } + +if (has_tracepoint && !details->trace_fields) +printf ("# Tip: use 'perf evlist --trace-fields' to show fields for tracepoint events\n" ); +perf_session__delete (session);return 0 ; }@@ -49,6 +57,7 @@ int cmd_evlist(int argc, const char **argv, const char *prefix __maybe_unused)OPT_BOOLEAN ('g' ,"group" , &details.event_group,"Show event group information" ),OPT_BOOLEAN ('f' ,"force" , &details.force,"don't complain, do it" ), +OPT_BOOLEAN (0 ,"trace-fields" , &details.trace_fields,"Show tracepoint fields" ),OPT_END () }; const char * const evlist_usage[] = {tools/perf/util/evsel.c +23
-0@@ -2298,6 +2298,29 @@ int perf_evsel__fprintf(struct perf_evsel *evsel, printed +=comma_fprintf (fp, &first," %s=%" PRIu64, term, (u64 )evsel->attr.sample_freq); } + +if (details->trace_fields) { +struct format_field *field; + +if (evsel->attr.type !=PERF_TYPE_TRACEPOINT ) { + printed +=comma_fprintf (fp, &first," (not a tracepoint)" ); + goto out; + } + + field = evsel->tp_format->format.fields; +if (field ==NULL ) { + printed +=comma_fprintf (fp, &first," (no trace field)" ); + goto out; + } + + printed +=comma_fprintf (fp, &first," trace_fields=%s" , field->name); + + field = field->next; +while (field) { + printed +=comma_fprintf (fp, &first,"%s" , field->name); + field = field->next; + } + } out:fputc ('\n' , fp);return ++printed;tools/perf/util/evsel.h +1
-0@@ -369,6 +369,7 @@ struct perf_attr_details {bool verbose;bool event_group;bool force; +bool trace_fields; }; int perf_evsel__fprintf(struct perf_evsel *evsel,Signature · 1 line
2.6.4
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v3 3/5] perf tools: Fix dynamic sort keys to sort properly
In reply to Namhyung KimEm Thu, Jan 07, 2016 at 08:26:45AM +0900, Namhyung Kim escreveu:
Quoted 11 lines · Arnaldo Carvalho de Melo
Quoted 7 lines
Em Wed, Jan 06, 2016 at 09:54:59AM +0900, Namhyung Kim escreveu:
Quoted 3 lines
Currently, the dynamic sort keys compares trace data using
memcmp(). But for output sorting, it should check data size and compare by word. Also it sorted strings in reverse order, fix it.Can this be broken down in two patches? This is complex code, lets try to make it as bisectable as possible.
OK, I'll break out the string part then. But I think it doesn't help much to reduce the complexity.
Well, number of patches is not a problem, everytime I see a "Also lets do this other thing" I cringe, it is automatic, sorry :-\
For reviewing its soooo much better to see things nicely separated, and sometimes I like one part but not the other, so I pick one and continue discussion on the other, etc.
- Arnaldo
Quoted 119 lines
Thanks,
NamhyungQuoted 115 lines
- Arnaldo
Quoted 112 lines
Before)
$ perf report -F overhead -s prev_pid,next_pid ... # Overhead prev_pid next_pid # ........ .......... .......... # 0.39% 490 0 9.12% 225 0 0.04% 224 0 0.51% 731 189 0.08% 731 3 0.12% 731 0 4.82% 729 0 0.08% 1229 0 0.20% 715 0 4.78% 189 225 ...After)
$ perf report -F overhead -s prev_pid,next_pid ... # Overhead prev_pid next_pid # ........ .......... .......... # 0.43% 0 7 0.04% 0 11 0.04% 0 12 0.08% 0 14 0.04% 0 17 0.08% 0 19 0.04% 0 22 0.04% 0 27 0.04% 0 37 0.04% 0 42 ...Reported-by Arnaldo Carvalho de Melo <[email protected]>Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/util/sort.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-)tools/perf/util/sort.c +46
-1@@ -1798,6 +1798,51 @@ static int64_t __sort__hde_cmp(struct perf_hpp_fmt *fmt,return memcmp (a->raw_data + offset, b->raw_data + offset, size); } +static int64_t __sort__hde_sort (struct perf_hpp_fmt *fmt, +struct hist_entry *a,struct hist_entry *b) +{ +struct hpp_dynamic_entry *hde; +struct format_field *field; +unsigned offset, size; +int64_t *a64, *b64; +int32_t *a32, *b32; +int16_t *a16, *b16; + + hde = container_of(fmt, struct hpp_dynamic_entry, hpp); + + field = hde->field; +if (field->flags &FIELD_IS_DYNAMIC ) { +unsigned long long dyn; + +pevent_read_number_field (field, a->raw_data, &dyn); + offset = dyn &0xffff ; + size = (dyn >>16 ) &0xffff ; + }else { + offset = field->offset; + size = field->size; + } + +if (field->flags &FIELD_IS_STRING ) +return strcmp (b->raw_data + offset, a->raw_data + offset); + +switch (size) { +case 8 : + a64 = a->raw_data + offset; + b64 = b->raw_data + offset; +return *b64 - *a64; +case 4 : + a32 = a->raw_data + offset; + b32 = b->raw_data + offset; +return *b32 - *a32; +case 2 : + a16 = a->raw_data + offset; + b16 = b->raw_data + offset; +return *b16 - *a16; +default : +return memcmp (b->raw_data + offset, a->raw_data + offset, size); + } +} +bool perf_hpp__is_dynamic_entry (struct perf_hpp_fmt *fmt) {return fmt->cmp == __sort__hde_cmp;@@ -1826,7 +1871,7 @@ __alloc_dynamic_entry(struct perf_evsel *evsel, struct format_field *field) hde->hpp.cmp = __sort__hde_cmp; hde->hpp.collapse = __sort__hde_cmp; - hde->hpp.sort = __sort__hde_cmp; + hde->hpp.sort = __sort__hde_sort;INIT_LIST_HEAD (&hde->hpp.list);INIT_LIST_HEAD (&hde->hpp.sort_list);Signature · 1 line
2.6.4
Namhyung Kim
maintainerRe: [PATCH v3 5/5] perf evlist: Add --trace-fields option to show trace fields
In reply to Arnaldo Carvalho de MeloQuoted 27 lines · Arnaldo Carvalho de Melo
Em Thu, Jan 07, 2016 at 08:21:44AM +0900, Namhyung Kim escreveu:
Quoted 26 lines · Arnaldo Carvalho de Melo
Quoted 25 lines
Em Wed, Jan 06, 2016 at 09:55:01AM +0900, Namhyung Kim escreveu:
Quoted 14 lines
To use dynamic sort keys, it might be good to add an option to see the list of field names.
$ perf evlist -i perf.data.sched sched:sched_switch sched:sched_stat_wait sched:sched_stat_sleep sched:sched_stat_iowait sched:sched_stat_runtime sched:sched_process_fork sched:sched_wakeup sched:sched_wakeup_new sched:sched_migrate_task # Tip: use 'perf evlist --trace-fields' to show fields for tracepoint eventsOk, almost there, question is: if I ask explicitely for "--trace-fields", why should we have the "trace_fields=" in all lines, instead of just:
$ perf evlist -i perf.data.sched --trace-fields sched:sched_switch: prev_comm,prev_pid,prev_prio,prev_state,next_comm,next_pid,next_prio sched:sched_stat_wait: comm,pid,delay
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
?
I made it to work with other options too, like 'perf evlist --freq --trace-fields'. In that case you may want to see it. :)
I see... And then you want to show those at the same time... Would you have an use case for that? Or would it be better to make them mutually exclusive? /me unsure...
I don't have one. But I think I sometimes want to see it with -v/--verbose option. Hmm.. do you think --verbose should imply --trace-fields?
Thanks,
Namhyung
Quoted 123 lines
Quoted 123 lines
Quoted 123 lines
I like the lack of spaces after commans, this way we can double click and select the whole list, then edit it, etc.
- Arnaldo
Quoted 117 lines
$ perf evlist -i perf.data.sched --trace-fields sched:sched_switch: trace_fields=prev_comm,prev_pid,prev_prio,prev_state,next_comm,next_pid,next_prio sched:sched_stat_wait: trace_fields=comm,pid,delay sched:sched_stat_sleep: trace_fields=comm,pid,delay sched:sched_stat_iowait: trace_fields=comm,pid,delay sched:sched_stat_runtime: trace_fields=comm,pid,runtime,vruntime sched:sched_process_fork: trace_fields=parent_comm,parent_pid,child_comm,child_pid sched:sched_wakeup: trace_fields=comm,pid,prio,success,target_cpu sched:sched_wakeup_new: trace_fields=comm,pid,prio,success,target_cpu sched:sched_migrate_task: trace_fields=comm,pid,prio,orig_cpu,dest_cpuSigned-off-by Namhyung Kim <[email protected]>--- tools/perf/Documentation/perf-evlist.txt | 3 +++ tools/perf/builtin-evlist.c | 11 ++++++++++- tools/perf/util/evsel.c | 23 +++++++++++++++++++++++ tools/perf/util/evsel.h | 1 + 4 files changed, 37 insertions(+), 1 deletion(-)tools/perf/Documentation/perf-evlist.txt +3
-0@@ -32,6 +32,9 @@ OPTIONS --group:: Show event group information. +--trace-fields:: + Show tracepoint field names. + SEE ALSO -------- linkperf:perf-record[1], linkperf:perf-list[1],tools/perf/builtin-evlist.c +10
-1@@ -26,14 +26,22 @@ static int __cmd_evlist(const char *file_name, struct perf_attr_details *details .mode = PERF_DATA_MODE_READ, .force = details->force, }; +bool has_tracepoint = false; session =perf_session__new (&file,0 ,NULL );if (session ==NULL )return -1 ; -evlist__for_each (session->evlist, pos) +evlist__for_each (session->evlist, pos) {perf_evsel__fprintf (pos, details, stdout); +if (pos->attr.type ==PERF_TYPE_TRACEPOINT ) + has_tracepoint = true; + } + +if (has_tracepoint && !details->trace_fields) +printf ("# Tip: use 'perf evlist --trace-fields' to show fields for tracepoint events\n" ); +perf_session__delete (session);return 0 ; }@@ -49,6 +57,7 @@ int cmd_evlist(int argc, const char **argv, const char *prefix __maybe_unused)OPT_BOOLEAN ('g' ,"group" , &details.event_group,"Show event group information" ),OPT_BOOLEAN ('f' ,"force" , &details.force,"don't complain, do it" ), +OPT_BOOLEAN (0 ,"trace-fields" , &details.trace_fields,"Show tracepoint fields" ),OPT_END () }; const char * const evlist_usage[] = {tools/perf/util/evsel.c +23
-0@@ -2298,6 +2298,29 @@ int perf_evsel__fprintf(struct perf_evsel *evsel, printed +=comma_fprintf (fp, &first," %s=%" PRIu64, term, (u64 )evsel->attr.sample_freq); } + +if (details->trace_fields) { +struct format_field *field; + +if (evsel->attr.type !=PERF_TYPE_TRACEPOINT ) { + printed +=comma_fprintf (fp, &first," (not a tracepoint)" ); + goto out; + } + + field = evsel->tp_format->format.fields; +if (field ==NULL ) { + printed +=comma_fprintf (fp, &first," (no trace field)" ); + goto out; + } + + printed +=comma_fprintf (fp, &first," trace_fields=%s" , field->name); + + field = field->next; +while (field) { + printed +=comma_fprintf (fp, &first,"%s" , field->name); + field = field->next; + } + } out:fputc ('\n' , fp);return ++printed;tools/perf/util/evsel.h +1
-0@@ -369,6 +369,7 @@ struct perf_attr_details {bool verbose;bool event_group;bool force; +bool trace_fields; }; int perf_evsel__fprintf(struct perf_evsel *evsel,Signature · 1 line
2.6.4
Namhyung Kim
maintainerRe: [PATCH v3 3/5] perf tools: Fix dynamic sort keys to sort properly
In reply to Arnaldo Carvalho de MeloQuoted 13 lines · Arnaldo Carvalho de Melo
Em Thu, Jan 07, 2016 at 08:26:45AM +0900, Namhyung Kim escreveu:
Quoted 11 lines · Arnaldo Carvalho de Melo
Quoted 7 lines
Em Wed, Jan 06, 2016 at 09:54:59AM +0900, Namhyung Kim escreveu:
Quoted 3 lines
Currently, the dynamic sort keys compares trace data using
memcmp(). But for output sorting, it should check data size and compare by word. Also it sorted strings in reverse order, fix it.Can this be broken down in two patches? This is complex code, lets try to make it as bisectable as possible.
OK, I'll break out the string part then. But I think it doesn't help much to reduce the complexity.
Quoted 6 lines
Well, number of patches is not a problem, everytime I see a "Also lets do this other thing" I cringe, it is automatic, sorry :-\
For reviewing its soooo much better to see things nicely separated, and sometimes I like one part but not the other, so I pick one and continue discussion on the other, etc.
OK, I understand your concern. I'll try to make it more easier to review.
Thanks,
Namhyung
Quoted 113 lines
Quoted 113 lines
Quoted 113 lines
Quoted 113 lines
Before)
$ perf report -F overhead -s prev_pid,next_pid ... # Overhead prev_pid next_pid # ........ .......... .......... # 0.39% 490 0 9.12% 225 0 0.04% 224 0 0.51% 731 189 0.08% 731 3 0.12% 731 0 4.82% 729 0 0.08% 1229 0 0.20% 715 0 4.78% 189 225 ...After)
$ perf report -F overhead -s prev_pid,next_pid ... # Overhead prev_pid next_pid # ........ .......... .......... # 0.43% 0 7 0.04% 0 11 0.04% 0 12 0.08% 0 14 0.04% 0 17 0.08% 0 19 0.04% 0 22 0.04% 0 27 0.04% 0 37 0.04% 0 42 ...Reported-by Arnaldo Carvalho de Melo <[email protected]>Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/util/sort.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-)tools/perf/util/sort.c +46
-1@@ -1798,6 +1798,51 @@ static int64_t __sort__hde_cmp(struct perf_hpp_fmt *fmt,return memcmp (a->raw_data + offset, b->raw_data + offset, size); } +static int64_t __sort__hde_sort (struct perf_hpp_fmt *fmt, +struct hist_entry *a,struct hist_entry *b) +{ +struct hpp_dynamic_entry *hde; +struct format_field *field; +unsigned offset, size; +int64_t *a64, *b64; +int32_t *a32, *b32; +int16_t *a16, *b16; + + hde = container_of(fmt, struct hpp_dynamic_entry, hpp); + + field = hde->field; +if (field->flags &FIELD_IS_DYNAMIC ) { +unsigned long long dyn; + +pevent_read_number_field (field, a->raw_data, &dyn); + offset = dyn &0xffff ; + size = (dyn >>16 ) &0xffff ; + }else { + offset = field->offset; + size = field->size; + } + +if (field->flags &FIELD_IS_STRING ) +return strcmp (b->raw_data + offset, a->raw_data + offset); + +switch (size) { +case 8 : + a64 = a->raw_data + offset; + b64 = b->raw_data + offset; +return *b64 - *a64; +case 4 : + a32 = a->raw_data + offset; + b32 = b->raw_data + offset; +return *b32 - *a32; +case 2 : + a16 = a->raw_data + offset; + b16 = b->raw_data + offset; +return *b16 - *a16; +default : +return memcmp (b->raw_data + offset, a->raw_data + offset, size); + } +} +bool perf_hpp__is_dynamic_entry (struct perf_hpp_fmt *fmt) {return fmt->cmp == __sort__hde_cmp;@@ -1826,7 +1871,7 @@ __alloc_dynamic_entry(struct perf_evsel *evsel, struct format_field *field) hde->hpp.cmp = __sort__hde_cmp; hde->hpp.collapse = __sort__hde_cmp; - hde->hpp.sort = __sort__hde_cmp; + hde->hpp.sort = __sort__hde_sort;INIT_LIST_HEAD (&hde->hpp.list);INIT_LIST_HEAD (&hde->hpp.sort_list);Signature · 1 line
2.6.4
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v3 3/5] perf tools: Fix dynamic sort keys to sort properly
In reply to Arnaldo Carvalho de MeloEm Wed, Jan 06, 2016 at 08:31:49PM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 13 lines
Em Thu, Jan 07, 2016 at 08:26:45AM +0900, Namhyung Kim escreveu:
Quoted 11 lines · Arnaldo Carvalho de Melo
Quoted 7 lines
Em Wed, Jan 06, 2016 at 09:54:59AM +0900, Namhyung Kim escreveu:
Quoted 3 lines
Currently, the dynamic sort keys compares trace data using
memcmp(). But for output sorting, it should check data size and compare by word. Also it sorted strings in reverse order, fix it.Can this be broken down in two patches? This is complex code, lets try to make it as bisectable as possible.
OK, I'll break out the string part then. But I think it doesn't help much to reduce the complexity.
Quoted 6 lines
Well, number of patches is not a problem, everytime I see a "Also lets do this other thing" I cringe, it is automatic, sorry :-\
For reviewing its soooo much better to see things nicely separated, and sometimes I like one part but not the other, so I pick one and continue discussion on the other, etc.
Ah, please rebase from my latest perf/core, I'm still holding on it since some 'perf test' entries are failing and I want to check first if its due to bugs introduced in this branch...
- Arnaldo
Namhyung Kim
maintainerRe: [PATCH v3 3/5] perf tools: Fix dynamic sort keys to sort properly
Quoted 17 lines · Arnaldo Carvalho de Melo
Em Wed, Jan 06, 2016 at 08:31:49PM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 16 lines
Em Thu, Jan 07, 2016 at 08:26:45AM +0900, Namhyung Kim escreveu:
Quoted 11 lines · Arnaldo Carvalho de Melo
Quoted 7 lines
Em Wed, Jan 06, 2016 at 09:54:59AM +0900, Namhyung Kim escreveu:
Quoted 3 lines
Currently, the dynamic sort keys compares trace data using
memcmp(). But for output sorting, it should check data size and compare by word. Also it sorted strings in reverse order, fix it.Can this be broken down in two patches? This is complex code, lets try to make it as bisectable as possible.
OK, I'll break out the string part then. But I think it doesn't help much to reduce the complexity.
Well, number of patches is not a problem, everytime I see a "Also lets do this other thing" I cringe, it is automatic, sorry :-\
Quoted 7 lines
Quoted 3 lines
For reviewing its soooo much better to see things nicely separated, and sometimes I like one part but not the other, so I pick one and continue discussion on the other, etc.
Ah, please rebase from my latest perf/core, I'm still holding on it since some 'perf test' entries are failing and I want to check first if its due to bugs introduced in this branch...
Will do!
Thanks,
Namhyung