perf diff: Add new filter options
v2 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.
v2:
---
Update patch "perf diff: Support --time filter option" according to Jiri's comments. Others are no functional 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 | 187 ++++++++++++++++++++++++++++++--- 2 files changed, 226 insertions(+), 13 deletions(-)
Signature · 1 line
2.7.4
PATCH v2 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.
v2:
---
Update according to Jiri's comments. For example, put the time string processing code to separate functions and align the memebers in perf_diff.
--- tools/perf/Documentation/perf-diff.txt | 41 ++++++++ tools/perf/builtin-diff.c | 167 ++++++++++++++++++++++++++++++--- 2 files changed, 195 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 +154 -13
230 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH v2 1/3] perf diff: Support --time filter option
On Tue, Feb 26, 2019 at 08:11:07PM +0800, Jin Yao wrote:
SNIP
Quoted 11 lines
tools/perf/builtin-diff.c +2
-1+ abstime_tmp = abstime_ostr;data__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; }
tools/perf/builtin-diff.c static void data__free(struct data__file *d) · line 918
Quoted 10 lines
tools/perf/builtin-diff.c +10
-0+if (abstime_ostr) { + ret =parse_absolute_time (d, &abstime_tmp); +if (ret <0 ) + goto out_delete; + }else if (pdiff.time_str) { + ret =parse_percent_time (d); +if (ret <0 ) + goto out_delete; + }else { + pdiff.range_num =1 ;
hum, why are we setting range_num to 1 again?
it's really hard to parse this code, maybe
it'd be better in separate loop/function
that would setup just timestamps..
thanks,
jirka
Re: [PATCH v2 1/3] perf diff: Support --time filter option
Quoted 15 lines · Jiri Olsa
On Tue, Feb 26, 2019 at 08:11:07PM +0800, Jin Yao wrote:
SNIP
Quoted 11 lines
tools/perf/builtin-diff.c +2
-1+ abstime_tmp = abstime_ostr;data__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; }
Quoted 12 lines
tools/perf/builtin-diff.c static void data__free(struct data__file *d) · line 918
Quoted 10 lines
tools/perf/builtin-diff.c +10
-0+if (abstime_ostr) { + ret =parse_absolute_time (d, &abstime_tmp); +if (ret <0 ) + goto out_delete; + }else if (pdiff.time_str) { + ret =parse_percent_time (d); +if (ret <0 ) + goto out_delete; + }else { + pdiff.range_num =1 ;hum, why are we setting
range_numto 1 again?
Yes, that may be not necessary. I will remove this line and test again.
Quoted 5 lines
it's really hard to parse this code, maybe
it'd be better in separate loop/function
that would setup just timestamps..
Do you mean the above parsing code should be put in a separate function (e.g. parse_time_string in following example)?
data__for_each_file(i, d) {
....
d->session = perf_session__new(&d->data, false, &pdiff.tool);
....
parse_time_string(...);
ret = perf_session__process_events(d->session);
....
}Thanks
Jin Yao
Quoted 4 lines
thanks,
jirka
Re: [PATCH v2 1/3] perf diff: Support --time filter option
Quoted 40 lines · Yao
Quoted 17 lines · Jiri Olsa
On Tue, Feb 26, 2019 at 08:11:07PM +0800, Jin Yao wrote:
SNIP
Quoted 13 lines
tools/perf/builtin-diff.c +6
-1+ abstime_tmp = abstime_ostr;data__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 (abstime_ostr) { + ret =parse_absolute_time (d, &abstime_tmp); +if (ret <0 ) + goto out_delete;Quoted 8 lines
tools/perf/builtin-diff.c static void data__free(struct data__file *d) · line 918
Quoted 6 lines
tools/perf/builtin-diff.c +6
-0+ }else if (pdiff.time_str) { + ret =parse_percent_time (d); +if (ret <0 ) + goto out_delete; + }else { + pdiff.range_num =1 ;hum, why are we setting
range_numto 1 again?Yes, that may be not necessary. I will remove this line and test again.
Quoted 5 lines
it's really hard to parse this code, maybe
it'd be better in separate loop/function
that would setup just timestamps..Do you mean the above parsing code should be put in a separate function (e.g.
parse_time_stringin following example)?
Quoted 8 lines
data__for_each_file(i, d) {
....
d->session = perf_session__new(&d->data, false, &pdiff.tool);
....
parse_time_string(...);
ret = perf_session__process_events(d->session);
....
}anything that would make this more clear/readable ;-)
thanks,
jirka
Re: [PATCH v2 1/3] perf diff: Support --time filter option
In reply to Jin YaoOn Tue, Feb 26, 2019 at 08:11:07PM +0800, Jin Yao wrote:
SNIP
Quoted 25 lines
tools/perf/builtin-diff.c +18
-0+ .ordered_events = true, + .ordering_requires_timestamps = true, + }, }; static struct perf_evsel *evsel_match(struct perf_evsel *evsel,@@ -771,19 +788,136 @@ static void data__free(struct data__file *d) } } +static int parse_time_range (struct data__file *d, +struct perf_time_interval *ptime_range, +const char *time_str) +{ +if (perf_time__parse_str (ptime_range, + time_str) !=0 ) { +if (d->session->evlist->first_sample_time ==0 && + d->session->evlist->last_sample_time ==0 ) { +pr_err ("HINT: no first/last sample time found in perf data.\n" +"Please use latest perf binary to execute 'perf record'\n" +"(if '--buildid-all' is enabled, please set '--timestamp-boundary').\n" ); +return -EINVAL ; + } + + pdiff.range_num = perf_time__percent_parse_str(
tools/perf/builtin-diff.c static void data__free(struct data__file *d) · line 815
Quoted 10 lines
tools/perf/builtin-diff.c +10
-0+ ptime_range, pdiff.range_size, time_str, + d->session->evlist->first_sample_time, + d->session->evlist->last_sample_time); + +if (pdiff.range_num <0 ) { +pr_err ("Invalid time string\n" ); +return -EINVAL ; + } + }else { + pdiff.range_num =1 ;
I dont understand why we set range_num to 1 if there's not time option set.. it should be 0 and we should take no action in diff__process_sample_event, right?
then I checked the report code and we do the same, could we fix that? I'm assuming we don't need any time check if the time option is not set.. please correct me if I miss something
jirka
Re: [PATCH v2 1/3] perf diff: Support --time filter option
Quoted 44 lines · Jiri Olsa
On Tue, Feb 26, 2019 at 08:11:07PM +0800, Jin Yao wrote:
SNIP
Quoted 25 lines
tools/perf/builtin-diff.c +18
-0+ .ordered_events = true, + .ordering_requires_timestamps = true, + }, }; static struct perf_evsel *evsel_match(struct perf_evsel *evsel,@@ -771,19 +788,136 @@ static void data__free(struct data__file *d) } } +static int parse_time_range (struct data__file *d, +struct perf_time_interval *ptime_range, +const char *time_str) +{ +if (perf_time__parse_str (ptime_range, + time_str) !=0 ) { +if (d->session->evlist->first_sample_time ==0 && + d->session->evlist->last_sample_time ==0 ) { +pr_err ("HINT: no first/last sample time found in perf data.\n" +"Please use latest perf binary to execute 'perf record'\n" +"(if '--buildid-all' is enabled, please set '--timestamp-boundary').\n" ); +return -EINVAL ; + } + + pdiff.range_num = perf_time__percent_parse_str(tools/perf/builtin-diff.c static void data__free(struct data__file *d) · line 815
Quoted 10 lines
tools/perf/builtin-diff.c +10
-0+ ptime_range, pdiff.range_size, time_str, + d->session->evlist->first_sample_time, + d->session->evlist->last_sample_time); + +if (pdiff.range_num <0 ) { +pr_err ("Invalid time string\n" ); +return -EINVAL ; + } + }else { + pdiff.range_num =1 ;I dont understand why we set
range_numto 1 if there's not time option set.. it should be 0 and we should take no action indiff__process_sample_event, right?
Quoted 7 lines
then I checked the report code and we do the same, could we fix that? I'm assuming we don't need any time check if the time option is not set.. please correct me if I miss something
jirka
We support multiple complicated time strings. :(
In parse_time_range(), perf_time__parse_str() returns 0 if the time string is a simple start/stop format. So next, we set the range_num to 1. If the time string contains multiple time percent ranges (e.g. "10%/1,10%/2,..."), perf_time__parse_str() will return with error (<0), then we will continue checking with perf_time__percent_parse_str().
So when range_num is set to 1, it just means it's the simple time string.
Thanks
Jin Yao
Re: [PATCH v2 1/3] perf diff: Support --time filter option
Quoted 55 lines · Yao
Quoted 42 lines · Jiri Olsa
On Tue, Feb 26, 2019 at 08:11:07PM +0800, Jin Yao wrote:
SNIP
Quoted 23 lines
tools/perf/builtin-diff.c +18
-0+ .ordered_events = true, + .ordering_requires_timestamps = true, + }, }; static struct perf_evsel *evsel_match(struct perf_evsel *evsel,@@ -771,19 +788,136 @@ static void data__free(struct data__file *d) } } +static int parse_time_range (struct data__file *d, +struct perf_time_interval *ptime_range, +const char *time_str) +{ +if (perf_time__parse_str (ptime_range, + time_str) !=0 ) { +if (d->session->evlist->first_sample_time ==0 && + d->session->evlist->last_sample_time ==0 ) { +pr_err ("HINT: no first/last sample time found in perf data.\n" +"Please use latest perf binary to execute 'perf record'\n" +"(if '--buildid-all' is enabled, please set '--timestamp-boundary').\n" ); +return -EINVAL ; + } + + pdiff.range_num = perf_time__percent_parse_str(tools/perf/builtin-diff.c static void data__free(struct data__file *d) · line 814
Quoted 10 lines
tools/perf/builtin-diff.c +10
-0+ ptime_range, pdiff.range_size, time_str, + d->session->evlist->first_sample_time, + d->session->evlist->last_sample_time); + +if (pdiff.range_num <0 ) { +pr_err ("Invalid time string\n" ); +return -EINVAL ; + } + }else { + pdiff.range_num =1 ;I dont understand why we set
range_numto 1 if there's not time option set.. it should be 0 and we should take no action indiff__process_sample_event, right?Quoted 7 lines
then I checked the report code and we do the same, could we fix that? I'm assuming we don't need any time check if the time option is not set.. please correct me if I miss something
jirka
We support multiple complicated time strings. :(
Quoted 7 lines
In
parse_time_range(),perf_time__parse_str()returns 0 if the time string is a simple start/stop format. So next, we set therange_numto 1. If the time string contains multiple time percent ranges (e.g. "10%/1,10%/2,..."),perf_time__parse_str()will return with error (<0), then we will continue checking withperf_time__percent_parse_str().So when
range_numis set to 1, it just means it's the simple time string.
why do we need to have time range set if there's no --time option set by user?
jirka
Re: [PATCH v2 1/3] perf diff: Support --time filter option
Quoted 62 lines · Jiri Olsa
Quoted 61 lines · Yao
Quoted 42 lines · Jiri Olsa
On Tue, Feb 26, 2019 at 08:11:07PM +0800, Jin Yao wrote:
SNIP
Quoted 23 lines
tools/perf/builtin-diff.c +18
-0+ .ordered_events = true, + .ordering_requires_timestamps = true, + }, }; static struct perf_evsel *evsel_match(struct perf_evsel *evsel,@@ -771,19 +788,136 @@ static void data__free(struct data__file *d) } } +static int parse_time_range (struct data__file *d, +struct perf_time_interval *ptime_range, +const char *time_str) +{ +if (perf_time__parse_str (ptime_range, + time_str) !=0 ) { +if (d->session->evlist->first_sample_time ==0 && + d->session->evlist->last_sample_time ==0 ) { +pr_err ("HINT: no first/last sample time found in perf data.\n" +"Please use latest perf binary to execute 'perf record'\n" +"(if '--buildid-all' is enabled, please set '--timestamp-boundary').\n" ); +return -EINVAL ; + } + + pdiff.range_num = perf_time__percent_parse_str(tools/perf/builtin-diff.c static void data__free(struct data__file *d) · line 814
Quoted 10 lines
tools/perf/builtin-diff.c +10
-0+ ptime_range, pdiff.range_size, time_str, + d->session->evlist->first_sample_time, + d->session->evlist->last_sample_time); + +if (pdiff.range_num <0 ) { +pr_err ("Invalid time string\n" ); +return -EINVAL ; + } + }else { + pdiff.range_num =1 ;I dont understand why we set
range_numto 1 if there's not time option set.. it should be 0 and we should take no action indiff__process_sample_event, right?Quoted 7 lines
then I checked the report code and we do the same, could we fix that? I'm assuming we don't need any time check if the time option is not set.. please correct me if I miss something
jirka
We support multiple complicated time strings. :(
In
parse_time_range(),perf_time__parse_str()returns 0 if the time string is a simple start/stop format. So next, we set therange_numto 1. If the time string contains multiple time percent ranges (e.g. "10%/1,10%/2,..."),perf_time__parse_str()will return with error (<0), then we will continue checking withperf_time__percent_parse_str().
Quoted 7 lines
Quoted 1 line
So when
range_numis set to 1, it just means it's the simple time string.why do we need to have time range set if there's no --time option set by user?
jirka
Yes, that could be refined if no --time option set by user. I think I can add a new patch to fix these for perf report/script.
Thanks
Jin Yao
PATCH v2 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.
v2:
---
No functional change.
--- 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;
@@ -918,6 +926,13 @@ static int __cmd_diff(void) pdiff.range_num =1 ; } +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);
@@ -990,6 +1005,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 v2 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.
v2:
---
No functional change.
--- 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
@@ -1006,6 +1006,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