Skip to contentSkip to conversation

perf diff: Add new filter options

PATCH Applied Jin Yao 4 participants 9 messages Mar 5, 2019 – Mar 9, 2019 perf events

lore
Share & tools
lore

Jin Yao

author
#0 lore raw

v4 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.

v4:
---
Update abstime_str_dup(), let it return error if strdup is failed, and update __cmd_diff() accordingly.

Only the patch "perf diff: Support --time filter option" is impacted 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              | 168 ++++++++++++++++++++++++++++++---
 2 files changed, 206 insertions(+), 14 deletions(-)
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH v4 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.

v4:
---
Update abstime_str_dup(), let it return error if strdup is failed, and update __cmd_diff() accordingly.

---
 tools/perf/Documentation/perf-diff.txt |  41 +++++++++
 tools/perf/builtin-diff.c              | 148 +++++++++++++++++++++++++++++----
 2 files changed, 175 insertions(+), 14 deletions(-)
tools/perf/Documentation/perf-diff.txt +41 -0
index a79c84a..5bfe876 100644
@@ -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 +134 -14

216 lines not on this page · raw message

Signature · 1 line
2.7.4
#2 lore raw

[tip:perf/urgent] perf diff: Support --time filter option

perf diff: Support --time filter option
Commit-ID:  4802138d78caed36cee2a859f77fb2035f230018
Gitweb:     https://git.kernel.org/tip/4802138d78caed36cee2a859f77fb2035f230018
Author:     Jin Yao <[email protected]>
AuthorDate: Tue, 5 Mar 2019 21:05:41 +0800
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 6 Mar 2019 18:03:23 -0300

perf diff: Support --time filter option

To improve 'perf diff', implement a --time filter option to diff the samples within given time window.

It supports time percent with multiple time ranges. The time string format 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 analysing samples within a 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 the 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.

v4:
---
Update abstime_str_dup(), let it return error if strdup is failed, and update __cmd_diff() accordingly.

---
 tools/perf/Documentation/perf-diff.txt |  45 ++++++++++
 tools/perf/builtin-diff.c              | 148 +++++++++++++++++++++++++++++----
 2 files changed, 179 insertions(+), 14 deletions(-)
tools/perf/Documentation/perf-diff.txt +45 -0
index a79c84ae61aa..036d65bded51 100644
@@ -118,6 +118,51 @@ 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 multiple 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 analyzing samples within a 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 the end of the 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 +134 -14

216 lines not on this page · raw message

author
#3 lore raw

PATCH v4 2/3 perf diff: Support --cpu filter option

In reply to Jin Yao

For 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.

v4:
---
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
index 5bfe876..ed13b3f 100644
@@ -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
index 17cd898..dfe6c76 100644
@@ -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;
@@ -892,6 +900,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);
@@ -969,6 +984,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
#4 lore raw

[tip:perf/urgent] perf diff: Support --cpu filter option

perf diff: Support --cpu filter option
Commit-ID:  daca23b2007595b6a48255ca08c763f56050d1c5
Gitweb:     https://git.kernel.org/tip/daca23b2007595b6a48255ca08c763f56050d1c5
Author:     Jin Yao <[email protected]>
AuthorDate: Tue, 5 Mar 2019 21:05:42 +0800
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 6 Mar 2019 18:05:21 -0300

perf diff: Support --cpu filter option

To improve 'perf diff', implement a --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.

---
 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
index 036d65bded51..8c2c229faf50 100644
@@ -163,6 +163,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
index 17cd898074c8..dfe6c7606f5a 100644
@@ -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;
@@ -892,6 +900,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);
@@ -969,6 +984,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()
 };
 
author
#5 lore raw

PATCH v4 3/3 perf diff: Support --pid/--tid filter options

In reply to Jin Yao

For 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.

v4:
---
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
index ed13b3f..83c9496 100644
@@ -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
index dfe6c76..6e79207 100644
@@ -985,6 +985,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
#6 lore raw

[tip:perf/urgent] perf diff: Support --pid/--tid filter options

perf diff: Support --pid/--tid filter options
Commit-ID:  c1d3e633e16db3eb64f519c7099171bfcef94b20
Gitweb:     https://git.kernel.org/tip/c1d3e633e16db3eb64f519c7099171bfcef94b20
Author:     Jin Yao <[email protected]>
AuthorDate: Tue, 5 Mar 2019 21:05:43 +0800
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 6 Mar 2019 18:06:16 -0300

perf diff: Support --pid/--tid filter options

Using the existing symbol_conf.pid_list_str and symbol_conf.tid_list_str logic.

For example:

  perf diff --tid 13965

It'll only diff the samples for thread 13965.

---
 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
index 8c2c229faf50..da7809b15cc9 100644
@@ -168,6 +168,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
index dfe6c7606f5a..6e7920793729 100644
@@ -985,6 +985,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()
 };
 
Acked-by on the v4 series
#7 lore raw
In reply to Jin Yao
Quoted 69 lines · Jin Yao

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.

v4:
---
Update abstime_str_dup(), let it return error if strdup is failed, and update __cmd_diff() accordingly.

Quoted 7 lines

Only the patch "perf diff: Support --time filter option" is impacted 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

thanks,
jirka

#8 lore raw

Em Tue, Mar 05, 2019 at 01:34:23PM +0100, Jiri Olsa escreveu:

Quoted 7 lines · Jin Yao
Quoted 4 lines

Jin Yao (3):
perf diff: Support --time filter option
perf diff: Support --cpu filter option
perf diff: Support --pid/--tid filter options

Thanks, applied.

- Arnaldo