perf stat: Support --all-kernel/--all-user
PATCH 1/1 perf stat: Support --all-kernel/--all-user
perf record has supported --all-kernel / --all-user to configure all used events to run in kernel space or run in user space. But perf stat doesn't support these options.
It would be useful to support these options in perf-stat too to keep the same semantics.
--- tools/perf/Documentation/perf-stat.txt | 6 ++++++ tools/perf/builtin-stat.c | 6 ++++++ tools/perf/util/stat.c | 10 ++++++++++ tools/perf/util/stat.h | 2 ++ 4 files changed, 24 insertions(+)
tools/perf/Documentation/perf-stat.txt +6 -0
@@ -323,6 +323,12 @@ The output is SMI cycles%, equals to (aperf - unhalted core cycles) / aperf Users who wants to get the actual value can apply --no-metric-only. +--all-kernel:: +Configure all used events to run in kernel space. + +--all-user:: +Configure all used events to run in user space. + EXAMPLES --------
tools/perf/builtin-stat.c +6 -0
@@ -803,6 +803,12 @@ static struct option stat_options[] = {OPT_CALLBACK ('M' ,"metrics" , &evsel_list,"metric/metric group list" ,"monitor specified metrics or metric groups (separated by ,)" , parse_metric_groups), +OPT_BOOLEAN_FLAG (0 ,"all-kernel" , &stat_config.all_kernel, +"Configure all used events to run in kernel space." , +PARSE_OPT_EXCLUSIVE ), +OPT_BOOLEAN_FLAG (0 ,"all-user" , &stat_config.all_user, +"Configure all used events to run in user space." , +PARSE_OPT_EXCLUSIVE ), OPT_END() };
tools/perf/util/stat.c +10 -0
@@ -490,6 +490,16 @@ int create_perf_stat_counter(struct evsel *evsel,if (config->identifier) attr->sample_type =PERF_SAMPLE_IDENTIFIER ; +if (config->all_user) { + attr->exclude_kernel =1 ; + attr->exclude_user =0 ; + } + +if (config->all_kernel) { + attr->exclude_kernel =0 ; + attr->exclude_user =1 ; + } +/* * Disabling all counters initially, they will be enabled * either manually by us or by kernel via enable_on_exec
tools/perf/util/stat.h +2 -0
@@ -106,6 +106,8 @@ struct perf_stat_config {bool big_num;bool no_merge;bool walltime_run_table; +bool all_kernel; +bool all_user;FILE *output;unsigned int interval;unsigned int timeout;
Signature · 1 line
2.17.1
Quoted 8 lines · Jin Yao
perf record has supported --all-kernel / --all-user to configure all used events to run in kernel space or run in user space. But perf stat doesn't support these options.
It would be useful to support these options in perf-stat too to keep the same semantics.
Signed-off-by Jin Yao <[email protected]>
thanks,
jirka
Quoted 78 lines
--- tools/perf/Documentation/perf-stat.txt | 6 ++++++ tools/perf/builtin-stat.c | 6 ++++++ tools/perf/util/stat.c | 10 ++++++++++ tools/perf/util/stat.h | 2 ++ 4 files changed, 24 insertions(+)tools/perf/Documentation/perf-stat.txt +6
-0@@ -323,6 +323,12 @@ The output is SMI cycles%, equals to (aperf - unhalted core cycles) / aperf Users who wants to get the actual value can apply --no-metric-only. +--all-kernel:: +Configure all used events to run in kernel space. + +--all-user:: +Configure all used events to run in user space. + EXAMPLES --------tools/perf/builtin-stat.c +6
-0@@ -803,6 +803,12 @@ static struct option stat_options[] = {OPT_CALLBACK ('M' ,"metrics" , &evsel_list,"metric/metric group list" ,"monitor specified metrics or metric groups (separated by ,)" , parse_metric_groups), +OPT_BOOLEAN_FLAG (0 ,"all-kernel" , &stat_config.all_kernel, +"Configure all used events to run in kernel space." , +PARSE_OPT_EXCLUSIVE ), +OPT_BOOLEAN_FLAG (0 ,"all-user" , &stat_config.all_user, +"Configure all used events to run in user space." , +PARSE_OPT_EXCLUSIVE ), OPT_END() };tools/perf/util/stat.c +10
-0@@ -490,6 +490,16 @@ int create_perf_stat_counter(struct evsel *evsel,if (config->identifier) attr->sample_type =PERF_SAMPLE_IDENTIFIER ; +if (config->all_user) { + attr->exclude_kernel =1 ; + attr->exclude_user =0 ; + } + +if (config->all_kernel) { + attr->exclude_kernel =0 ; + attr->exclude_user =1 ; + } +/* * Disabling all counters initially, they will be enabled * either manually by us or by kernel via enable_on_exec tools/perf/util/stat.h +2
-0@@ -106,6 +106,8 @@ struct perf_stat_config {bool big_num;bool no_merge;bool walltime_run_table; +bool all_kernel; +bool all_user;FILE *output;unsigned int interval;unsigned int timeout;Signature · 1 line
2.17.1
Em Mon, Oct 14, 2019 at 04:42:08PM +0200, Jiri Olsa escreveu:
Quoted 11 lines · Jin Yao
Quoted 8 lines
perf record has supported --all-kernel / --all-user to configure all used events to run in kernel space or run in user space. But perf stat doesn't support these options.
It would be useful to support these options in perf-stat too to keep the same semantics.
Signed-off-by Jin Yao <[email protected]>Acked-by Jiri Olsa <[email protected]>
What happens if one asks for both? From the patch only the --all-kernel will stick, right? Is that the behaviour for 'perf record'? Lemme see, as I recall having this discussion at that time...
Yeah, same thing, and looking at that I wonder why we dong use perf_evsel__config() in 'perf stat'...
Ok, I'm going to apply it.
Quoted 81 lines
thanks,
jirkaQuoted 78 lines
--- tools/perf/Documentation/perf-stat.txt | 6 ++++++ tools/perf/builtin-stat.c | 6 ++++++ tools/perf/util/stat.c | 10 ++++++++++ tools/perf/util/stat.h | 2 ++ 4 files changed, 24 insertions(+)tools/perf/Documentation/perf-stat.txt +6
-0@@ -323,6 +323,12 @@ The output is SMI cycles%, equals to (aperf - unhalted core cycles) / aperf Users who wants to get the actual value can apply --no-metric-only. +--all-kernel:: +Configure all used events to run in kernel space. + +--all-user:: +Configure all used events to run in user space. + EXAMPLES --------tools/perf/builtin-stat.c +6
-0@@ -803,6 +803,12 @@ static struct option stat_options[] = {OPT_CALLBACK ('M' ,"metrics" , &evsel_list,"metric/metric group list" ,"monitor specified metrics or metric groups (separated by ,)" , parse_metric_groups), +OPT_BOOLEAN_FLAG (0 ,"all-kernel" , &stat_config.all_kernel, +"Configure all used events to run in kernel space." , +PARSE_OPT_EXCLUSIVE ), +OPT_BOOLEAN_FLAG (0 ,"all-user" , &stat_config.all_user, +"Configure all used events to run in user space." , +PARSE_OPT_EXCLUSIVE ), OPT_END() };tools/perf/util/stat.c +10
-0@@ -490,6 +490,16 @@ int create_perf_stat_counter(struct evsel *evsel,if (config->identifier) attr->sample_type =PERF_SAMPLE_IDENTIFIER ; +if (config->all_user) { + attr->exclude_kernel =1 ; + attr->exclude_user =0 ; + } + +if (config->all_kernel) { + attr->exclude_kernel =0 ; + attr->exclude_user =1 ; + } +/* * Disabling all counters initially, they will be enabled * either manually by us or by kernel via enable_on_exec tools/perf/util/stat.h +2
-0@@ -106,6 +106,8 @@ struct perf_stat_config {bool big_num;bool no_merge;bool walltime_run_table; +bool all_kernel; +bool all_user;FILE *output;unsigned int interval;unsigned int timeout;Signature · 1 line
2.17.1
Signature · 1 line
- Arnaldo
Quoted 13 lines · Arnaldo Carvalho de Melo
Em Mon, Oct 14, 2019 at 04:42:08PM +0200, Jiri Olsa escreveu:
Quoted 11 lines · Jin Yao
Quoted 8 lines
perf record has supported --all-kernel / --all-user to configure all used events to run in kernel space or run in user space. But perf stat doesn't support these options.
It would be useful to support these options in perf-stat too to keep the same semantics.
Signed-off-by Jin Yao <[email protected]>Acked-by Jiri Olsa <[email protected]>
Quoted 9 lines
What happens if one asks for both? From the patch only the --all-kernel will stick, right? Is that the behaviour for 'perf record'? Lemme see, as I recall having this discussion at that time...
Yeah, same thing, and looking at that I wonder why we dong use
perf_evsel__config()in 'perf stat'...Ok, I'm going to apply it.
Hi Arnaldo,
If we specify both, we will see the error.
root@kbl:~# perf stat --all-kernel --all-user -a -- sleep 1 Error: option `all-user' cannot be used with all-kernel
root@kbl:~# perf record --all-kernel --all-user -a -- sleep 1 Error: option `all-user' cannot be used with all-kernel
For why I don't set them in perf_evsel__config, because perf_evsel__config is called in record but not called in stat.
Thanks for reviewing and applying this patch.
Thanks
Jin Yao
Quoted 82 lines
Quoted 81 lines
thanks,
jirkaQuoted 78 lines
--- tools/perf/Documentation/perf-stat.txt | 6 ++++++ tools/perf/builtin-stat.c | 6 ++++++ tools/perf/util/stat.c | 10 ++++++++++ tools/perf/util/stat.h | 2 ++ 4 files changed, 24 insertions(+)tools/perf/Documentation/perf-stat.txt +6
-0@@ -323,6 +323,12 @@ The output is SMI cycles%, equals to (aperf - unhalted core cycles) / aperf Users who wants to get the actual value can apply --no-metric-only. +--all-kernel:: +Configure all used events to run in kernel space. + +--all-user:: +Configure all used events to run in user space. + EXAMPLES --------tools/perf/builtin-stat.c +6
-0@@ -803,6 +803,12 @@ static struct option stat_options[] = {OPT_CALLBACK ('M' ,"metrics" , &evsel_list,"metric/metric group list" ,"monitor specified metrics or metric groups (separated by ,)" , parse_metric_groups), +OPT_BOOLEAN_FLAG (0 ,"all-kernel" , &stat_config.all_kernel, +"Configure all used events to run in kernel space." , +PARSE_OPT_EXCLUSIVE ), +OPT_BOOLEAN_FLAG (0 ,"all-user" , &stat_config.all_user, +"Configure all used events to run in user space." , +PARSE_OPT_EXCLUSIVE ), OPT_END() };tools/perf/util/stat.c +10
-0@@ -490,6 +490,16 @@ int create_perf_stat_counter(struct evsel *evsel,if (config->identifier) attr->sample_type =PERF_SAMPLE_IDENTIFIER ; +if (config->all_user) { + attr->exclude_kernel =1 ; + attr->exclude_user =0 ; + } + +if (config->all_kernel) { + attr->exclude_kernel =0 ; + attr->exclude_user =1 ; + } +/* * Disabling all counters initially, they will be enabled * either manually by us or by kernel via enable_on_exec tools/perf/util/stat.h +2
-0@@ -106,6 +106,8 @@ struct perf_stat_config {bool big_num;bool no_merge;bool walltime_run_table; +bool all_kernel; +bool all_user;FILE *output;unsigned int interval;unsigned int timeout;Signature · 1 line
2.17.1
Em Tue, Oct 15, 2019 at 09:57:33AM +0800, Jin, Yao escreveu:
Quoted 23 lines · Arnaldo Carvalho de Melo
Quoted 20 lines
Em Mon, Oct 14, 2019 at 04:42:08PM +0200, Jiri Olsa escreveu:
Quoted 11 lines · Jin Yao
Quoted 8 lines
perf record has supported --all-kernel / --all-user to configure all used events to run in kernel space or run in user space. But perf stat doesn't support these options.
It would be useful to support these options in perf-stat too to keep the same semantics.
Signed-off-by Jin Yao <[email protected]>Acked-by Jiri Olsa <[email protected]>What happens if one asks for both? From the patch only the --all-kernel will stick, right? Is that the behaviour for 'perf record'? Lemme see, as I recall having this discussion at that time...
Yeah, same thing, and looking at that I wonder why we dong use
perf_evsel__config()in 'perf stat'...
Quoted 6 lines
Quoted 2 lines
Ok, I'm going to apply it.
Hi Arnaldo,
If we specify both, we will see the error.
Cool, I looked for this code and couldn't quickly spot it nor tried running with both to see what happened, my bad, thanks for replying and making sure that that is the behaviour.
Quoted 8 lines
root@kbl:~# perf stat --all-kernel --all-user -a -- sleep 1 Error: option `all-user' cannot be used with all-kernelroot@kbl:~# perf record --all-kernel --all-user -a -- sleep 1 Error: option `all-user' cannot be used with all-kernelFor why I don't set them in
perf_evsel__config, becauseperf_evsel__configis called in record but not called in stat.
Ok, at some point we should try and check if we could make 'perf stat' use perf_evsel__config(), even if we have to separate what is shared into some __perf_evsel__config() that then gets called by 'perf stat' while the preexisting perf_evsel__config() calls it and does things that don't make sense for 'perf stat'.
Quoted 1 line
Thanks for reviewing and applying this patch.
You're welcome!
- Arnaldo
Quoted 80 lines
Thanks
Jin YaoQuoted 77 lines
Quoted 76 lines
thanks,
jirkaQuoted 73 lines
--- tools/perf/Documentation/perf-stat.txt | 6 ++++++ tools/perf/builtin-stat.c | 6 ++++++ tools/perf/util/stat.c | 10 ++++++++++ tools/perf/util/stat.h | 2 ++ 4 files changed, 24 insertions(+)tools/perf/Documentation/perf-stat.txt +6
-0@@ -323,6 +323,12 @@ The output is SMI cycles%, equals to (aperf - unhalted core cycles) / aperf Users who wants to get the actual value can apply --no-metric-only. +--all-kernel:: +Configure all used events to run in kernel space. + +--all-user:: +Configure all used events to run in user space. + EXAMPLES --------tools/perf/builtin-stat.c +6
-0@@ -803,6 +803,12 @@ static struct option stat_options[] = {OPT_CALLBACK ('M' ,"metrics" , &evsel_list,"metric/metric group list" ,"monitor specified metrics or metric groups (separated by ,)" , parse_metric_groups), +OPT_BOOLEAN_FLAG (0 ,"all-kernel" , &stat_config.all_kernel, +"Configure all used events to run in kernel space." , +PARSE_OPT_EXCLUSIVE ), +OPT_BOOLEAN_FLAG (0 ,"all-user" , &stat_config.all_user, +"Configure all used events to run in user space." , +PARSE_OPT_EXCLUSIVE ), OPT_END() };tools/perf/util/stat.c +10
-0@@ -490,6 +490,16 @@ int create_perf_stat_counter(struct evsel *evsel,if (config->identifier) attr->sample_type =PERF_SAMPLE_IDENTIFIER ; +if (config->all_user) { + attr->exclude_kernel =1 ; + attr->exclude_user =0 ; + } + +if (config->all_kernel) { + attr->exclude_kernel =0 ; + attr->exclude_user =1 ; + } +/* * Disabling all counters initially, they will be enabled * either manually by us or by kernel via enable_on_exec tools/perf/util/stat.h +2
-0@@ -106,6 +106,8 @@ struct perf_stat_config {bool big_num;bool no_merge;bool walltime_run_table; +bool all_kernel; +bool all_user;FILE *output;unsigned int interval;unsigned int timeout;Signature · 1 line
2.17.1
Signature · 1 line
- Arnaldo
Quoted 41 lines · Arnaldo Carvalho de Melo
Em Tue, Oct 15, 2019 at 09:57:33AM +0800, Jin, Yao escreveu:
Quoted 23 lines · Arnaldo Carvalho de Melo
Quoted 20 lines
Em Mon, Oct 14, 2019 at 04:42:08PM +0200, Jiri Olsa escreveu:
Quoted 11 lines · Jin Yao
Quoted 8 lines
perf record has supported --all-kernel / --all-user to configure all used events to run in kernel space or run in user space. But perf stat doesn't support these options.
It would be useful to support these options in perf-stat too to keep the same semantics.
Signed-off-by Jin Yao <[email protected]>Acked-by Jiri Olsa <[email protected]>What happens if one asks for both? From the patch only the --all-kernel will stick, right? Is that the behaviour for 'perf record'? Lemme see, as I recall having this discussion at that time...
Yeah, same thing, and looking at that I wonder why we dong use
perf_evsel__config()in 'perf stat'...Quoted 6 lines
Quoted 2 lines
Ok, I'm going to apply it.
Hi Arnaldo,
If we specify both, we will see the error.
Cool, I looked for this code and couldn't quickly spot it nor tried running with both to see what happened, my bad, thanks for replying and making sure that that is the behaviour.
Quoted 6 lines
root@kbl:~# perf stat --all-kernel --all-user -a -- sleep 1 Error: option `all-user' cannot be used with all-kernelroot@kbl:~# perf record --all-kernel --all-user -a -- sleep 1 Error: option `all-user' cannot be used with all-kernel
Quoted 9 lines
Quoted 2 lines
For why I don't set them in
perf_evsel__config, becauseperf_evsel__configis called in record but not called in stat.Ok, at some point we should try and check if we could make 'perf stat' use
perf_evsel__config(), even if we have to separate what is shared into some__perf_evsel__config()that then gets called by 'perf stat' while the preexistingperf_evsel__config()calls it and does things that don't make sense for 'perf stat'.
Yes, fully agree, that should be better. If we reconstruct the perf_evsel__config() and make it be shared by perf stat, perf record and others, that would be nice. :)
Thanks
Jin Yao
Quoted 87 lines
Quoted 1 line
Thanks for reviewing and applying this patch.
You're welcome!
- Arnaldo
Quoted 80 lines
Thanks
Jin YaoQuoted 77 lines
Quoted 76 lines
thanks,
jirkaQuoted 73 lines
--- tools/perf/Documentation/perf-stat.txt | 6 ++++++ tools/perf/builtin-stat.c | 6 ++++++ tools/perf/util/stat.c | 10 ++++++++++ tools/perf/util/stat.h | 2 ++ 4 files changed, 24 insertions(+)tools/perf/Documentation/perf-stat.txt +6
-0@@ -323,6 +323,12 @@ The output is SMI cycles%, equals to (aperf - unhalted core cycles) / aperf Users who wants to get the actual value can apply --no-metric-only. +--all-kernel:: +Configure all used events to run in kernel space. + +--all-user:: +Configure all used events to run in user space. + EXAMPLES --------tools/perf/builtin-stat.c +6
-0@@ -803,6 +803,12 @@ static struct option stat_options[] = {OPT_CALLBACK ('M' ,"metrics" , &evsel_list,"metric/metric group list" ,"monitor specified metrics or metric groups (separated by ,)" , parse_metric_groups), +OPT_BOOLEAN_FLAG (0 ,"all-kernel" , &stat_config.all_kernel, +"Configure all used events to run in kernel space." , +PARSE_OPT_EXCLUSIVE ), +OPT_BOOLEAN_FLAG (0 ,"all-user" , &stat_config.all_user, +"Configure all used events to run in user space." , +PARSE_OPT_EXCLUSIVE ), OPT_END() };tools/perf/util/stat.c +10
-0@@ -490,6 +490,16 @@ int create_perf_stat_counter(struct evsel *evsel,if (config->identifier) attr->sample_type =PERF_SAMPLE_IDENTIFIER ; +if (config->all_user) { + attr->exclude_kernel =1 ; + attr->exclude_user =0 ; + } + +if (config->all_kernel) { + attr->exclude_kernel =0 ; + attr->exclude_user =1 ; + } +/* * Disabling all counters initially, they will be enabled * either manually by us or by kernel via enable_on_exec tools/perf/util/stat.h +2
-0@@ -106,6 +106,8 @@ struct perf_stat_config {bool big_num;bool no_merge;bool walltime_run_table; +bool all_kernel; +bool all_user;FILE *output;unsigned int interval;unsigned int timeout;Signature · 1 line
2.17.1
The following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: dd071024bf52156eed31deaf511c6e7a82a6f57b Gitweb: https://git.kernel.org/tip/dd071024bf52156eed31deaf511c6e7a82a6f57b Author: Jin Yao <[email protected]> AuthorDate: Fri, 11 Oct 2019 13:05:45 +08:00 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Tue, 15 Oct 2019 08:39:42 -03:00
perf stat: Support --all-kernel/--all-user
'perf record' has supported --all-kernel / --all-user to configure all used events to run in kernel space or run in user space. But 'perf stat' doesn't support these options.
It would be useful to support these options in 'perf stat' too to keep the same semantics available in both tools.
--- tools/perf/Documentation/perf-stat.txt | 6 ++++++ tools/perf/builtin-stat.c | 6 ++++++ tools/perf/util/stat.c | 10 ++++++++++ tools/perf/util/stat.h | 2 ++ 4 files changed, 24 insertions(+)
tools/perf/Documentation/perf-stat.txt +6 -0
@@ -323,6 +323,12 @@ The output is SMI cycles%, equals to (aperf - unhalted core cycles) / aperf Users who wants to get the actual value can apply --no-metric-only. +--all-kernel:: +Configure all used events to run in kernel space. + +--all-user:: +Configure all used events to run in user space. + EXAMPLES --------
tools/perf/builtin-stat.c +6 -0
@@ -803,6 +803,12 @@ static struct option stat_options[] = {OPT_CALLBACK ('M' ,"metrics" , &evsel_list,"metric/metric group list" ,"monitor specified metrics or metric groups (separated by ,)" , parse_metric_groups), +OPT_BOOLEAN_FLAG (0 ,"all-kernel" , &stat_config.all_kernel, +"Configure all used events to run in kernel space." , +PARSE_OPT_EXCLUSIVE ), +OPT_BOOLEAN_FLAG (0 ,"all-user" , &stat_config.all_user, +"Configure all used events to run in user space." , +PARSE_OPT_EXCLUSIVE ), OPT_END() };
tools/perf/util/stat.c +10 -0
@@ -490,6 +490,16 @@ int create_perf_stat_counter(struct evsel *evsel,if (config->identifier) attr->sample_type =PERF_SAMPLE_IDENTIFIER ; +if (config->all_user) { + attr->exclude_kernel =1 ; + attr->exclude_user =0 ; + } + +if (config->all_kernel) { + attr->exclude_kernel =0 ; + attr->exclude_user =1 ; + } +/* * Disabling all counters initially, they will be enabled * either manually by us or by kernel via enable_on_exec
tools/perf/util/stat.h +2 -0
@@ -106,6 +106,8 @@ struct perf_stat_config {bool big_num;bool no_merge;bool walltime_run_table; +bool all_kernel; +bool all_user;FILE *output;unsigned int interval;unsigned int timeout;