perf tools: Assorted fixes
Jiri Olsa
reviewercover perf tools: Assorted fixes
hi,
sending assorted general fixes that queued
up in my other branches.
Also available in here:
https://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
perf/fixes
thanks,
jirka
---
Jiri Olsa (6):
perf tools: Don't report zero period samples for slave events perf tools: Force sample_type for slave events
perf script: Allow +- operator for type specific fields option perf tools: Add missing new line into pr_debug call perf tools: Increase debug leve for cpu_map__snprint verbose output perf tools: Make rm_rf to remove single file
tools/perf/Documentation/perf-script.txt | 6 ++++++ tools/perf/builtin-script.c | 8 ++++++++ tools/perf/util/bpf-event.c | 2 +- tools/perf/util/cpumap.c | 2 +- tools/perf/util/evsel.c | 8 ++++++++ tools/perf/util/session.c | 7 +++++++ tools/perf/util/util.c | 16 +++++++++++++--- 7 files changed, 44 insertions(+), 5 deletions(-)
Jiri Olsa
reviewerPATCH 1/6 perf tools: Don't report zero period samples for slave events
There's no reason to deliver sample for zero period. It means there was no value for slave event since its last group leader sample.
--- tools/perf/util/session.c | 7 +++++++ 1 file changed, 7 insertions(+)
tools/perf/util/session.c +7 -0
@@ -1202,6 +1202,13 @@ static int deliver_sample_value(struct perf_evlist *evlist,return 0 ; } +/* +* There's no reason to deliver sample +* for zero period, bail out. +*/ +if (!sample->period) +return 0 ; +return tool->sample (tool, event, sample, sid->evsel, machine); }
Signature · 1 line
2.17.2
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf session: Don't report zero period samples for slave events
perf session: Don't report zero period samples for slave events
Commit-ID: 529c1a9e18c3b470d2eff7879923eda40b1431db Gitweb: https://git.kernel.org/tip/529c1a9e18c3b470d2eff7879923eda40b1431db Author: Jiri Olsa <[email protected]> AuthorDate: Wed, 20 Feb 2019 13:27:55 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 20 Feb 2019 16:07:51 -0300
perf session: Don't report zero period samples for slave events
There's no reason to deliver a sample with zero period. It means there was no value for slave event since its last group leader sample.
--- tools/perf/util/session.c | 7 +++++++ 1 file changed, 7 insertions(+)
tools/perf/util/session.c +7 -0
@@ -1202,6 +1202,13 @@ static int deliver_sample_value(struct perf_evlist *evlist,return 0 ; } +/* +* There's no reason to deliver sample +* for zero period, bail out. +*/ +if (!sample->period) +return 0 ; +return tool->sample (tool, event, sample, sid->evsel, machine); }
Jiri Olsa
reviewerPATCH 2/6 perf tools: Force sample_type for slave events
In reply to Jiri OlsaForcing sample_type setup for slave events in group leader sessions.
We don't get sample for slave events, we make them when delivering group leader sample. Set the slave event to follow the master sample_type to ease up report.
--- tools/perf/util/evsel.c | 8 ++++++++ 1 file changed, 8 insertions(+)
tools/perf/util/evsel.c +8 -0
@@ -956,6 +956,14 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts, attr->sample_freq =0 ; attr->sample_period =0 ; attr->write_backward =0 ; + +/* +* We don't get sample for slave events, we make them +* when delivering group leader sample. Set the slave +* event to follow the master sample_type to ease up +* report. +*/ + attr->sample_type = leader->attr.sample_type; }if (opts->no_samples)
Signature · 1 line
2.17.2
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf evsel: Force sample_type for slave events
perf evsel: Force sample_type for slave events
Commit-ID: 6e7e8b9fec45f7bef11a5d9d2dd9febe439d4047 Gitweb: https://git.kernel.org/tip/6e7e8b9fec45f7bef11a5d9d2dd9febe439d4047 Author: Jiri Olsa <[email protected]> AuthorDate: Wed, 20 Feb 2019 13:27:56 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 20 Feb 2019 16:08:59 -0300
perf evsel: Force sample_type for slave events
Force sample_type setup for slave events in group leader sessions.
We don't get sample for slave events, we make them when delivering group leader sample. Set the slave event to follow the master sample_type to ease up report.
--- tools/perf/util/evsel.c | 8 ++++++++ 1 file changed, 8 insertions(+)
tools/perf/util/evsel.c +8 -0
@@ -956,6 +956,14 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts, attr->sample_freq =0 ; attr->sample_period =0 ; attr->write_backward =0 ; + +/* +* We don't get sample for slave events, we make them +* when delivering group leader sample. Set the slave +* event to follow the master sample_type to ease up +* report. +*/ + attr->sample_type = leader->attr.sample_type; }if (opts->no_samples)
Jiri Olsa
reviewerPATCH 3/6 perf script: Allow +- operator for type specific fields option
In reply to Jiri OlsaAdding support to add/remove fields for specific event types in -F option. It's now possible to use '+-' after event type, like:
# cat > test.c #include <stdio.h>
int main(void)
{
printf("Hello world\n");
while(1) {}
}
^D
# gcc -g -o test test.c
# perf probe -x test 'test.c:5'
# perf record -e '{cpu/cpu-cycles,period=10000/,probe_test:main}:S' ./test
... # perf script -Ftrace:+period,-cpu
test 3859 396291.117343: 10275 cpu/cpu-cycles,period=10000/: 7f..
test 3859 396291.118234: 11041 cpu/cpu-cycles,period=10000/: ffffff..
test 3859 396291.118234: 1 probe_test:main:
test 3859 396291.118248: 8668 cpu/cpu-cycles,period=10000/: ffffff..
test 3859 396291.118263: 10139 cpu/cpu-cycles,period=10000/: ffffff..--- tools/perf/Documentation/perf-script.txt | 6 ++++++ tools/perf/builtin-script.c | 8 ++++++++ 2 files changed, 14 insertions(+)
tools/perf/Documentation/perf-script.txt +6 -0
@@ -159,6 +159,12 @@ OPTIONS the override, and the result of the above is that only S/W and H/W events are displayed with the given fields. + It's possible tp add/remove fields only for specific event type: + + -Fsw:-cpu,-period + + removes cpu and period from software events. + For the 'wildcard' option if a user selected field is invalid for an event type, a message is displayed to the user that the option is ignored for that type. For example:
tools/perf/builtin-script.c +8 -0
@@ -2560,6 +2560,10 @@ static int parse_output_fields(const struct option *opt __maybe_unused,pr_warning ("Overriding previous field request for %s events.\n" ,event_type (type)); +/* Don't override defaults for +- */ +if (strchr (tok,'+' ) ||strchr (tok,'-' )) + goto parse; + output[type].fields =0 ; output[type].user_set = true; output[type].wildcard_set = false;
@@ -2644,6 +2648,10 @@ static int parse_output_fields(const struct option *opt __maybe_unused, rc = -EINVAL ; goto out; } +if (change ==REMOVE ) + output[type].fields &= ~all_output_options[i].field; +else + output[type].fields |= all_output_options[i].field; output[type].user_set = true; output[type].wildcard_set = true; }
Signature · 1 line
2.17.2
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf script: Allow +- operator for type specific fields option
perf script: Allow +- operator for type specific fields option
Commit-ID: 6ef362fd3cf3af5d8143a07b4ea20499bf2a9eec Gitweb: https://git.kernel.org/tip/6ef362fd3cf3af5d8143a07b4ea20499bf2a9eec Author: Jiri Olsa <[email protected]> AuthorDate: Wed, 20 Feb 2019 13:27:57 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 20 Feb 2019 16:15:35 -0300
perf script: Allow +- operator for type specific fields option
Add support to add/remove fields for specific event types in -F option. It's now possible to use '+-' after event type, like:
# cat > test.c #include <stdio.h>
int main(void)
{
printf("Hello world\n");
while(1) {}
}
^D
# gcc -g -o test test.c
# perf probe -x test 'test.c:5'
# perf record -e '{cpu/cpu-cycles,period=10000/,probe_test:main}:S' ./test
... # perf script -Ftrace:+period,-cpu
test 3859 396291.117343: 10275 cpu/cpu-cycles,period=10000/: 7f..
test 3859 396291.118234: 11041 cpu/cpu-cycles,period=10000/: ffffff..
test 3859 396291.118234: 1 probe_test:main:
test 3859 396291.118248: 8668 cpu/cpu-cycles,period=10000/: ffffff..
test 3859 396291.118263: 10139 cpu/cpu-cycles,period=10000/: ffffff..Committer testing:
Couldn't make the test above work, but tested it with:
# perf probe -x hello main
Added new event:
probe_hello:main (on main in /home/acme/c/hello)You can now use it in all perf tools, such as:
perf record -e probe_hello:main -aR sleep 1
# perf record -e probe_hello:main ./hello
hello, world
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.025 MB perf.data (1 samples) ]
# perf script
hello 21454 [002] 254116.874005: probe_hello:main: (401126)
#
# perf script -Ftrace:+period,-cpu
hello 21454 254116.874005: 1 probe_hello:main: (401126)--- tools/perf/Documentation/perf-script.txt | 6 ++++++ tools/perf/builtin-script.c | 8 ++++++++ 2 files changed, 14 insertions(+)
tools/perf/Documentation/perf-script.txt +6 -0
@@ -159,6 +159,12 @@ OPTIONS the override, and the result of the above is that only S/W and H/W events are displayed with the given fields. + It's possible tp add/remove fields only for specific event type: + + -Fsw:-cpu,-period + + removes cpu and period from software events. + For the 'wildcard' option if a user selected field is invalid for an event type, a message is displayed to the user that the option is ignored for that type. For example:
tools/perf/builtin-script.c +8 -0
@@ -2560,6 +2560,10 @@ static int parse_output_fields(const struct option *opt __maybe_unused,pr_warning ("Overriding previous field request for %s events.\n" ,event_type (type)); +/* Don't override defaults for +- */ +if (strchr (tok,'+' ) ||strchr (tok,'-' )) + goto parse; + output[type].fields =0 ; output[type].user_set = true; output[type].wildcard_set = false;
@@ -2644,6 +2648,10 @@ parse: rc = -EINVAL ; goto out; } +if (change ==REMOVE ) + output[type].fields &= ~all_output_options[i].field; +else + output[type].fields |= all_output_options[i].field; output[type].user_set = true; output[type].wildcard_set = true; }
Jiri Olsa
reviewerPATCH 4/6 perf tools: Add missing new line into pr_debug call
In reply to Jiri OlsaAdding missing new line into pr_debug call inperf_event__synthesize_bpf_events function,
so the error message does not screw the verbose
output.
--- tools/perf/util/bpf-event.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/bpf-event.c +1 -1
@@ -233,7 +233,7 @@ int perf_event__synthesize_bpf_events(struct perf_tool *tool, err =0 ;break ; } -pr_debug ("%s: can't get next program: %s%s" , +pr_debug ("%s: can't get next program: %s%s\n" , __func__,strerror (errno), errno ==EINVAL ?" -- kernel too old?" :"" );/* don't report error on old kernel or EPERM */
Signature · 1 line
2.17.2
Arnaldo Carvalho de Melo
maintainerRe: [PATCH 4/6] perf tools: Add missing new line into pr_debug call
Em Wed, Feb 20, 2019 at 01:27:58PM +0100, Jiri Olsa escreveu:
Quoted 4 lines
Adding missing new line into
pr_debugcall inperf_event__synthesize_bpf_eventsfunction,
so the error message does not screw the verbose
output.
Adding Song Liu to the CC list,
- Arnaldo
Quoted 21 lines
Signed-off-by Jiri Olsa <[email protected]>--- tools/perf/util/bpf-event.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/perf/util/bpf-event.c +1
-1@@ -233,7 +233,7 @@ int perf_event__synthesize_bpf_events(struct perf_tool *tool, err =0 ;break ; } -pr_debug ("%s: can't get next program: %s%s" , +pr_debug ("%s: can't get next program: %s%s\n" , __func__,strerror (errno), errno ==EINVAL ?" -- kernel too old?" :"" );/* don't report error on old kernel or EPERM */ Signature · 1 line
2.17.2
Signature · 1 line
- Arnaldo
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf bpf-event: Add missing new line into pr_debug call
In reply to Jiri Olsaperf bpf-event: Add missing new line into pr_debug call
Commit-ID: b20fe10642f90d17c07b5e621bf4c00093c5654b Gitweb: https://git.kernel.org/tip/b20fe10642f90d17c07b5e621bf4c00093c5654b Author: Jiri Olsa <[email protected]> AuthorDate: Wed, 20 Feb 2019 13:27:58 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 20 Feb 2019 16:23:07 -0300
perf bpf-event: Add missing new line into pr_debug call
Add a missing new line into pr_debug call in perf_event__synthesize_bpf_events(), so that the error message does not screw the verbose output.
--- tools/perf/util/bpf-event.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/bpf-event.c +1 -1
@@ -233,7 +233,7 @@ int perf_event__synthesize_bpf_events(struct perf_tool *tool, err =0 ;break ; } -pr_debug ("%s: can't get next program: %s%s" , +pr_debug ("%s: can't get next program: %s%s\n" , __func__,strerror (errno), errno ==EINVAL ?" -- kernel too old?" :"" );/* don't report error on old kernel or EPERM */
Jiri Olsa
reviewerPATCH 5/6 perf tools: Increase debug leve for cpu_map__snprint verbose output
In reply to Jiri OlsaSo it does not screw up single -v verbose output.
--- tools/perf/util/cpumap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/cpumap.c +1 -1
@@ -681,7 +681,7 @@ size_t cpu_map__snprint(struct cpu_map *map, char *buf, size_t size)#undef COMMA -pr_debug ("cpumask list: %s\n" , buf); +pr_debug2 ("cpumask list: %s\n" , buf);return ret; }
Signature · 1 line
2.17.2
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf cpumap: Increase debug level for cpu_map__snprint verbose output
perf cpumap: Increase debug level for cpu_map__snprint verbose output
Commit-ID: deb83da16c1f3412fcb33c8944b3d854c4b265d6 Gitweb: https://git.kernel.org/tip/deb83da16c1f3412fcb33c8944b3d854c4b265d6 Author: Jiri Olsa <[email protected]> AuthorDate: Wed, 20 Feb 2019 13:27:59 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 20 Feb 2019 17:08:39 -0300
perf cpumap: Increase debug level for cpu_map__snprint verbose output
So it does not screw up single -v verbose output.
--- tools/perf/util/cpumap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/cpumap.c +1 -1
@@ -681,7 +681,7 @@ size_t cpu_map__snprint(struct cpu_map *map, char *buf, size_t size)#undef COMMA -pr_debug ("cpumask list: %s\n" , buf); +pr_debug2 ("cpumask list: %s\n" , buf);return ret; }
Jiri Olsa
reviewerPATCH 6/6 perf tools: Make rm_rf to remove single file
In reply to Jiri OlsaLet rm_rf remove file if it's provided by path.
--- tools/perf/util/util.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
tools/perf/util/util.c +13 -3
@@ -120,16 +120,26 @@ int mkdir_p(char *path, mode_t mode)int rm_rf (const char *path) {DIR *dir; -int ret =0 ; +int ret;struct dirent *d;char namebuf[PATH_MAX ]; +struct stat statbuf; +/* Do not fail if there's no file. */ + ret =lstat (path, &statbuf); +if (ret) +return 0 ; + +/* Try to remove any file we get. */ +if (!(statbuf.st_mode &S_IFDIR )) +return unlink (path); + +/* We have directory in path. */ dir =opendir (path);if (dir ==NULL ) -return 0 ; +return -1 ;while ((d =readdir (dir)) !=NULL && !ret) { -struct stat statbuf;if (!strcmp (d->d_name,"." ) || !strcmp (d->d_name,".." ))continue ;
Signature · 1 line
2.17.2
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf tools: Make rm_rf() remove single file
perf tools: Make rm_rf() remove single file
Commit-ID: b4409ae112caa6315f6ee678e953b9fc93e6919c Gitweb: https://git.kernel.org/tip/b4409ae112caa6315f6ee678e953b9fc93e6919c Author: Jiri Olsa <[email protected]> AuthorDate: Wed, 20 Feb 2019 13:28:00 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 20 Feb 2019 17:09:28 -0300
perf tools: Make rm_rf() remove single file
Let rm_rf() remove a file if it's provided by path, not just directories.
--- tools/perf/util/util.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
tools/perf/util/util.c +13 -3
@@ -120,16 +120,26 @@ int mkdir_p(char *path, mode_t mode)int rm_rf (const char *path) {DIR *dir; -int ret =0 ; +int ret;struct dirent *d;char namebuf[PATH_MAX ]; +struct stat statbuf; +/* Do not fail if there's no file. */ + ret =lstat (path, &statbuf); +if (ret) +return 0 ; + +/* Try to remove any file we get. */ +if (!(statbuf.st_mode &S_IFDIR )) +return unlink (path); + +/* We have directory in path. */ dir =opendir (path);if (dir ==NULL ) -return 0 ; +return -1 ;while ((d =readdir (dir)) !=NULL && !ret) { -struct stat statbuf;if (!strcmp (d->d_name,"." ) || !strcmp (d->d_name,".." ))continue ;