perf diff: Add new filter options
v3 cover perf diff: Add new filter options
This patch series creates following new filter options for perf diff.
--time:
It supports time percent with multipe time ranges. Time string is 'a%/n,b%/m,...' or 'a%-b%,c%-%d,...'.
For example:
Select the second 10% time slice to diff:
perf diff --time 10%/2
Select from 0% to 10% time slice to diff:
perf diff --time 0%-10%
Select the first and the second 10% time slices to diff:
perf diff --time 10%/1,10%/2
Select from 0% to 10% and 30% to 40% slices to diff:
perf diff --time 0%-10%,30%-40%
It also supports to analyze samples within given time window as:
<start>,<stop>. Times have the format seconds.microseconds. If start is not given (i.e., time string is ',x.y') then analysis starts at the beginning of the file. If stop time is not given (i.e, time string is 'x.y,') then analysis goes to end of file. Time string is 'a1.b1,c1.d1:a2.b2,c2.d2'. Use ':' to separate timestamps for different perf.data files.
For example, we get the timestamp information from perf script.
perf script -i perf.data.old
mgen 13940 [000] 3946.361400: ...
perf script -i perf.data
mgen 13940 [000] 3971.150589 ...
perf diff --time 3946.361400,:3971.150589,
It analyzes the perf.data.old from the timestamp 3946.361400 to the end of perf.data.old and analyzes the perf.data from the timestamp 3971.150589 to the end of perf.data.
--cpu:
Only diff samples for the list of CPUs provided. Multiple CPUs can be provided as a comma-separated list with no space: 0,1. Ranges of CPUs are specified with -: 0-2. Default is to report samples on all CPUs.
For example:
perf diff --cpu 0,1
It only diff the samples for CPU0 and CPU1.
--pid:
Only diff samples for given process ID (comma separated list).
--tid:
Only diff samples for given thread ID (comma separated list).
For example,
perf diff --tid 13965
It only diff the samples for thread 13965.
v3:
---
Update patch "perf diff: Support --time filter option" according to Jiri's comments. Others are no logical changes.
Jin Yao (3):
perf diff: Support --time filter option
perf diff: Support --cpu filter option
perf diff: Support --pid/--tid filter options
tools/perf/Documentation/perf-diff.txt | 52 +++++++++++ tools/perf/builtin-diff.c | 156 ++++++++++++++++++++++++++++++--- 2 files changed, 195 insertions(+), 13 deletions(-)
Signature · 1 line
2.7.4
PATCH v3 1/3 perf diff: Support --time filter option
For better support for perf diff, it would be useful to add --time filter option to diff the samples within given time window.
It supports time percent with multipe time ranges. Time string is 'a%/n,b%/m,...' or 'a%-b%,c%-%d,...'.
For example:
Select the second 10% time slice to diff:
perf diff --time 10%/2
Select from 0% to 10% time slice to diff:
perf diff --time 0%-10%
Select the first and the second 10% time slices to diff:
perf diff --time 10%/1,10%/2
Select from 0% to 10% and 30% to 40% slices to diff:
perf diff --time 0%-10%,30%-40%
It also supports to analyze samples within given time window as:
<start>,<stop>. Times have the format seconds.microseconds. If start is not given (i.e., time string is ',x.y') then analysis starts at the beginning of the file. If stop time is not given (i.e, time string is 'x.y,') then analysis goes to end of file. Time string is 'a1.b1,c1.d1:a2.b2,c2.d2'. Use ':' to separate timestamps for different perf.data files.
For example, we get the timestamp information from perf script.
perf script -i perf.data.old
mgen 13940 [000] 3946.361400: ...
perf script -i perf.data
mgen 13940 [000] 3971.150589 ...
perf diff --time 3946.361400,:3971.150589,
It analyzes the perf.data.old from the timestamp 3946.361400 to the end of perf.data.old and analyzes the perf.data from the timestamp 3971.150589 to the end of perf.data.
v3:
---
Don't parse the time string if --time option is not set. Refactor the code to make it simpler.
--- tools/perf/Documentation/perf-diff.txt | 41 ++++++++++ tools/perf/builtin-diff.c | 136 +++++++++++++++++++++++++++++---- 2 files changed, 164 insertions(+), 13 deletions(-)
tools/perf/Documentation/perf-diff.txt +41 -0
@@ -118,6 +118,47 @@ OPTIONS sum of shown entries will be always 100%. "absolute" means it retains the original value before and after the filter is applied. +--time:: + Analyze samples within given time window. It supports time + percent with multipe time ranges. Time string is 'a%/n,b%/m,...' + or 'a%-b%,c%-%d,...'. + + For example: + + Select the second 10% time slice to diff: + perf diff --time 10%/2 + + Select from 0% to 10% time slice to diff: + perf diff --time 0%-10% + + Select the first and the second 10% time slices to diff: + perf diff --time 10%/1,10%/2 + + Select from 0% to 10% and 30% to 40% slices to diff: + perf diff --time 0%-10%,30%-40% + + It also supports to analyze samples within given time window: + <start>,<stop>. Times have the format seconds.microseconds. If start + is not given (i.e., time string is ',x.y') then analysis starts at + the beginning of the file. If stop time is not given (i.e, time + string is 'x.y,') then analysis goes to end of file. Time string is + 'a1.b1,c1.d1:a2.b2,c2.d2'. Use ':' to separate timestamps for different + perf.data files. + + For example, we get the timestamp information from perf script. + + perf script -i perf.data.old + mgen 13940 [000] 3946.361400: ... + + perf script -i perf.data + mgen 13940 [000] 3971.150589 ... + + perf diff --time 3946.361400,:3971.150589, + + It analyzes the perf.data.old from the timestamp 3946.361400 to + the end of perf.data.old and analyzes the perf.data from the + timestamp 3971.150589 to the end of perf.data. + COMPARISON ---------- The comparison is governed by the baseline file. The baseline perf.data
tools/perf/builtin-diff.c +123 -13
205 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH v3 1/3] perf diff: Support --time filter option
Quoted 38 lines · Jin Yao
For better support for perf diff, it would be useful to add --time filter option to diff the samples within given time window.
It supports time percent with multipe time ranges. Time string is 'a%/n,b%/m,...' or 'a%-b%,c%-%d,...'.
For example:
Select the second 10% time slice to diff:
perf diff --time 10%/2Select from 0% to 10% time slice to diff:
perf diff --time 0%-10%Select the first and the second 10% time slices to diff:
perf diff --time 10%/1,10%/2Select from 0% to 10% and 30% to 40% slices to diff:
perf diff --time 0%-10%,30%-40%It also supports to analyze samples within given time window as:
<start>,<stop>. Times have the format seconds.microseconds. If start is not given (i.e., time string is ',x.y') then analysis starts at the beginning of the file. If stop time is not given (i.e, time string is 'x.y,') then analysis goes to end of file. Time string is 'a1.b1,c1.d1:a2.b2,c2.d2'. Use ':' to separate timestamps for different perf.data files.For example, we get the timestamp information from perf script.
perf script -i perf.data.old
mgen 13940 [000] 3946.361400: ...perf script -i perf.data
mgen 13940 [000] 3971.150589 ...perf diff --time 3946.361400,:3971.150589,
Quoted 8 lines
It analyzes the perf.data.old from the timestamp 3946.361400 to the end of perf.data.old and analyzes the perf.data from the timestamp 3971.150589 to the end of perf.data.
v3:
---
Don't parse the time string if --time option is not set. Refactor the code to make it simpler.
it's much clearer now, thanks for doing this, some nits below
SNIP
tools/perf/builtin-diff.c static void data__free(struct data__file *d) · line 869
Quoted 9 lines
tools/perf/builtin-diff.c +5
-0+static int __cmd_diff (void ) {struct data__file *d;int ret = -EINVAL , i; +char *abstime_ostr, *abstime_tmp; + + abstime_ostr =abstime_str_dup (); + abstime_tmp = abstime_ostr;
could be just one line:
abstime_ostr = abstime_tmp = abstime_str_dup();
also please fail if the allocation fails
Quoted 30 lines
tools/perf/builtin-diff.c +10
-1data__for_each_file (i, d) { - d->session =perf_session__new (&d->data, false, &tool); + d->session =perf_session__new (&d->data, false, &pdiff.tool);if (!d->session) {pr_err ("Failed to open %s\n" , d->data.path); ret =-1 ; goto out_delete; } +if (pdiff.time_str) { + ret =parse_time_str (d, abstime_ostr, &abstime_tmp); +if (ret <0 ) + goto out_delete; + } + ret =perf_session__process_events (d->session);if (ret) {pr_err ("Failed to process %s\n" , d->data.path);@@ -791,6 +889,9 @@ static int __cmd_diff(void) }perf_evlist__collapse_resort (d->session->evlist); + +if (pdiff.ptime_range) +zfree (&pdiff.ptime_range); }data_process ();
tools/perf/builtin-diff.c static int __cmd_diff(void) · line 908
Quoted 6 lines
tools/perf/builtin-diff.c +3
-0@@ -802,6 +903,13 @@ static int __cmd_diff(void) }free (data__files); + +if (pdiff.ptime_range) +zfree (&pdiff.ptime_range);
is this zfree needed? you free it in a loop for every data above
jirka
SNIP
Re: [PATCH v3 1/3] perf diff: Support --time filter option
Quoted 43 lines · Jiri Olsa
Quoted 42 lines · Jin Yao
For better support for perf diff, it would be useful to add --time filter option to diff the samples within given time window.
It supports time percent with multipe time ranges. Time string is 'a%/n,b%/m,...' or 'a%-b%,c%-%d,...'.
For example:
Select the second 10% time slice to diff:
perf diff --time 10%/2Select from 0% to 10% time slice to diff:
perf diff --time 0%-10%Select the first and the second 10% time slices to diff:
perf diff --time 10%/1,10%/2Select from 0% to 10% and 30% to 40% slices to diff:
perf diff --time 0%-10%,30%-40%It also supports to analyze samples within given time window as:
<start>,<stop>. Times have the format seconds.microseconds. If start is not given (i.e., time string is ',x.y') then analysis starts at the beginning of the file. If stop time is not given (i.e, time string is 'x.y,') then analysis goes to end of file. Time string is 'a1.b1,c1.d1:a2.b2,c2.d2'. Use ':' to separate timestamps for different perf.data files.For example, we get the timestamp information from perf script.
perf script -i perf.data.old
mgen 13940 [000] 3946.361400: ...perf script -i perf.data
mgen 13940 [000] 3971.150589 ...perf diff --time 3946.361400,:3971.150589,
It analyzes the perf.data.old from the timestamp 3946.361400 to the end of perf.data.old and analyzes the perf.data from the timestamp 3971.150589 to the end of perf.data.
Quoted 7 lines
Quoted 4 lines
v3:
---
Don't parse the time string if --time option is not set. Refactor the code to make it simpler.it's much clearer now, thanks for doing this, some nits below
Thanks!
Quoted 14 lines
SNIP
tools/perf/builtin-diff.c static void data__free(struct data__file *d) · line 869
Quoted 9 lines
tools/perf/builtin-diff.c +5
-0+static int __cmd_diff (void ) {struct data__file *d;int ret = -EINVAL , i; +char *abstime_ostr, *abstime_tmp; + + abstime_ostr =abstime_str_dup (); + abstime_tmp = abstime_ostr;could be just one line:
Quoted 4 lines
abstime_ostr = abstime_tmp = abstime_str_dup();also please fail if the allocation fails
OK, I will fix that.
Quoted 32 lines
Quoted 32 lines
data__for_each_file(i, d) {tools/perf/builtin-diff.c +10
-1- d->session =perf_session__new (&d->data, false, &tool); + d->session =perf_session__new (&d->data, false, &pdiff.tool);if (!d->session) {pr_err ("Failed to open %s\n" , d->data.path); ret =-1 ; goto out_delete; } +if (pdiff.time_str) { + ret =parse_time_str (d, abstime_ostr, &abstime_tmp); +if (ret <0 ) + goto out_delete; + } + ret =perf_session__process_events (d->session);if (ret) {pr_err ("Failed to process %s\n" , d->data.path);@@ -791,6 +889,9 @@ static int __cmd_diff(void) }perf_evlist__collapse_resort (d->session->evlist); + +if (pdiff.ptime_range) +zfree (&pdiff.ptime_range); }data_process ();@@ -802,6 +903,13 @@ static int __cmd_diff(void) }
Quoted 7 lines
tools/perf/builtin-diff.c static int __cmd_diff(void) · line 908
Quoted 4 lines
tools/perf/builtin-diff.c +3
-0free (data__files); + +if (pdiff.ptime_range) +zfree (&pdiff.ptime_range);is this zfree needed? you free it in a loop for every data above
Yes, we need this zfree. Because if we read the __cmd_diff() in uiltin-diff.c directly (not only read from this patch), we may see other "goto out_delete" cases, the zfree in loop may be not called. So we need an additional zfree checking in error handling.
Thanks
Jin Yao
Quoted 5 lines
jirka
SNIP
PATCH v3 2/3 perf diff: Support --cpu filter option
In reply to Jin YaoFor better support for perf diff, it would be useful to add --cpu filter option.
Multiple CPUs can be provided as a comma-separated list with no space: 0,1. Ranges of CPUs are specified with -: 0-2. Default is to report samples on all CPUs.
For example,
perf diff --cpu 0,1
It only diff the samples for CPU0 and CPU1.
v3:
---
No logical changes
--- tools/perf/Documentation/perf-diff.txt | 5 +++++ tools/perf/builtin-diff.c | 16 ++++++++++++++++ 2 files changed, 21 insertions(+)
tools/perf/Documentation/perf-diff.txt +5 -0
@@ -159,6 +159,11 @@ OPTIONS the end of perf.data.old and analyzes the perf.data from the timestamp 3971.150589 to the end of perf.data. +--cpu:: Only diff samples for the list of CPUs provided. Multiple CPUs can + be provided as a comma-separated list with no space: 0,1. Ranges of + CPUs are specified with -: 0-2. Default is to report samples on all + CPUs. + COMPARISON ---------- The comparison is governed by the baseline file. The baseline perf.data
tools/perf/builtin-diff.c +16 -0
@@ -83,6 +83,9 @@ static unsigned int sort_compute = 1;static s64 compute_wdiff_w1;static s64 compute_wdiff_w2; +static const char *cpu_list; +static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS); +enum {COMPUTE_DELTA ,COMPUTE_RATIO ,
@@ -354,6 +357,11 @@ static int diff__process_sample_event(struct perf_tool *tool,return -1 ; } +if (cpu_list && !test_bit (sample->cpu, cpu_bitmap)) { + ret =0 ; + goto out_put; + } +if (!hists__add_entry (hists, &al,NULL ,NULL ,NULL , sample, true)) {pr_warning ("problem incrementing symbol period, skipping event\n" ); goto out_put;
@@ -882,6 +890,13 @@ static int __cmd_diff(void) goto out_delete; } +if (cpu_list) { + ret =perf_session__cpu_bitmap (d->session, cpu_list, + cpu_bitmap); +if (ret <0 ) + goto out_delete; + } + ret =perf_session__process_events (d->session);if (ret) {pr_err ("Failed to process %s\n" , d->data.path);
@@ -959,6 +974,7 @@ static const struct option options[] = { "How to display percentage of filtered entries", parse_filter_percentage),OPT_STRING (0 ,"time" , &pdiff.time_str,"str" ,"Time span (time percent or absolute timestamp)" ), +OPT_STRING (0 ,"cpu" , &cpu_list,"cpu" ,"list of cpus to profile" ), OPT_END() };
Signature · 1 line
2.7.4
PATCH v3 3/3 perf diff: Support --pid/--tid filter options
In reply to Jin YaoFor better filtering support for perf diff, it would be useful to add --pid and --tid filter options.
For example,
perf diff --tid 13965
It only diff the samples for thread 13965.
v3:
---
No logical changes.
--- tools/perf/Documentation/perf-diff.txt | 6 ++++++ tools/perf/builtin-diff.c | 4 ++++ 2 files changed, 10 insertions(+)
tools/perf/Documentation/perf-diff.txt +6 -0
@@ -164,6 +164,12 @@ OPTIONS CPUs are specified with -: 0-2. Default is to report samples on all CPUs. +--pid=:: + Only diff samples for given process ID (comma separated list). + +--tid=:: + Only diff samples for given thread ID (comma separated list). + COMPARISON ---------- The comparison is governed by the baseline file. The baseline perf.data
tools/perf/builtin-diff.c +4 -0
@@ -975,6 +975,10 @@ static const struct option options[] = {OPT_STRING (0 ,"time" , &pdiff.time_str,"str" ,"Time span (time percent or absolute timestamp)" ),OPT_STRING (0 ,"cpu" , &cpu_list,"cpu" ,"list of cpus to profile" ), +OPT_STRING (0 ,"pid" , &symbol_conf.pid_list_str,"pid[,pid...]" , +"only consider symbols in these pids" ), +OPT_STRING (0 ,"tid" , &symbol_conf.tid_list_str,"tid[,tid...]" , +"only consider symbols in these tids" ), OPT_END() };
Signature · 1 line
2.7.4