perf tools: Assorted fixes
Jiri Olsa
reviewercover perf tools: Assorted fixes
hi,
sending assorted general fixes that queued
up in my other branches.
Arnaldo,
I added wait4 call in the last patch and am wondering if it will pass your all-distros-docker test ;-) If not I'll need to put some build detection code.
Also available in here:
https://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
perf/fixes
thanks,
jirka
---
Jiri Olsa (9):
perf check-headers.sh: Simplify arguments passing
perf check-headers.sh: Add support to check 2 independent files perf stat: Keep the / modifier separator in fallback perf tools: Fix pmu events parsing rule
perf tools: Disable write_backward for leader sampling group events perf stat: Display time in precision based on std deviation perf stat: Add --table option to display time of each run perf stat: Display length strings of each run for --table option perf stat: Display user and system time
tools/perf/builtin-stat.c | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------- tools/perf/check-headers.sh | 30 +++++++++++++++------------- tools/perf/tests/attr/test-record-group-sampling | 3 +++ tools/perf/util/evsel.c | 15 +++++++++++--- tools/perf/util/parse-events.y | 8 ++++---- tools/perf/util/stat.h | 3 +-- 6 files changed, 146 insertions(+), 33 deletions(-)
Jiri Olsa
reviewerPATCH 1/9 perf check-headers.sh: Simplify arguments passing
Passing whole string instead of parsing them after. It simplifies things for the next patches, that adds another function call, which makes it hard to pass arguments in the correct shape.
--- tools/perf/check-headers.sh | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
tools/perf/check-headers.sh +5 -10
@@ -59,13 +59,8 @@ check () { file=$1 shift - opts= - while [ -n "$*" ]; do - opts="$opts \"$1\"" - shift - done - cmd="diff $opts ../$file ../../$file > /dev/null" + cmd="diff $* ../$file ../../$file > /dev/null" test -f ../../$file && eval $cmd || echo "Warning: Kernel ABI header at 'tools/$file' differs from latest version at '$file'" >&2
@@ -83,7 +78,7 @@ for i in $HEADERS; do done # diff with extra ignore lines -check arch/x86/lib/memcpy_64.S -I "^EXPORT_SYMBOL" -I "^#include <asm/export.h>" -check arch/x86/lib/memset_64.S -I "^EXPORT_SYMBOL" -I "^#include <asm/export.h>" -check include/uapi/asm-generic/mman.h -I "^#include <\(uapi/\)*asm-generic/mman-common.h>" -check include/uapi/linux/mman.h -I "^#include <\(uapi/\)*asm/mman.h>" +check arch/x86/lib/memcpy_64.S '-I "^EXPORT_SYMBOL" -I "^#include <asm/export.h>"' +check arch/x86/lib/memset_64.S '-I "^EXPORT_SYMBOL" -I "^#include <asm/export.h>"' +check include/uapi/asm-generic/mman.h '-I "^#include <\(uapi/\)*asm-generic/mman-common.h>"' +check include/uapi/linux/mman.h '-I "^#include <\(uapi/\)*asm/mman.h>"'
Signature · 1 line
2.13.6
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf check-headers.sh: Simplify arguments passing
perf check-headers.sh: Simplify arguments passing
Commit-ID: 15019e9815a06b84870bfaf9ee1e8b75bf7ef6a6 Gitweb: https://git.kernel.org/tip/15019e9815a06b84870bfaf9ee1e8b75bf7ef6a6 Author: Jiri Olsa <[email protected]> AuthorDate: Mon, 23 Apr 2018 11:08:15 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 26 Apr 2018 09:30:26 -0300
perf check-headers.sh: Simplify arguments passing
Passing whole string instead of parsing them after. It simplifies things for the next patches, that adds another function call, which makes it hard to pass arguments in the correct shape.
--- tools/perf/check-headers.sh | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
tools/perf/check-headers.sh +5 -10
@@ -59,13 +59,8 @@ check () { file=$1 shift - opts= - while [ -n "$*" ]; do - opts="$opts \"$1\"" - shift - done - cmd="diff $opts ../$file ../../$file > /dev/null" + cmd="diff $* ../$file ../../$file > /dev/null" test -f ../../$file && eval $cmd || echo "Warning: Kernel ABI header at 'tools/$file' differs from latest version at '$file'" >&2
@@ -83,7 +78,7 @@ for i in $HEADERS; do done # diff with extra ignore lines -check arch/x86/lib/memcpy_64.S -I "^EXPORT_SYMBOL" -I "^#include <asm/export.h>" -check arch/x86/lib/memset_64.S -I "^EXPORT_SYMBOL" -I "^#include <asm/export.h>" -check include/uapi/asm-generic/mman.h -I "^#include <\(uapi/\)*asm-generic/mman-common.h>" -check include/uapi/linux/mman.h -I "^#include <\(uapi/\)*asm/mman.h>" +check arch/x86/lib/memcpy_64.S '-I "^EXPORT_SYMBOL" -I "^#include <asm/export.h>"' +check arch/x86/lib/memset_64.S '-I "^EXPORT_SYMBOL" -I "^#include <asm/export.h>"' +check include/uapi/asm-generic/mman.h '-I "^#include <\(uapi/\)*asm-generic/mman-common.h>"' +check include/uapi/linux/mman.h '-I "^#include <\(uapi/\)*asm/mman.h>"'
Jiri Olsa
reviewerPATCH 2/9 perf check-headers.sh: Add support to check 2 independent files
In reply to Jiri OlsaAdding check_2 function to check 2 different files, the check function stays to check files that differs only in the prefix path.
In upcoming changes we need to check on header files in locations which don't follow the prefix logic.
--- tools/perf/check-headers.sh | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
tools/perf/check-headers.sh +13 -4
@@ -55,17 +55,26 @@ include/uapi/asm-generic/ioctls.h include/uapi/asm-generic/mman-common.h ' -check () { - file=$1 +check_2 () { + file1=$1 + file2=$2 shift + shift - cmd="diff $* ../$file ../../$file > /dev/null" + cmd="diff $* $file1 $file2 > /dev/null" - test -f ../../$file && + test -f $file2 && eval $cmd || echo "Warning: Kernel ABI header at 'tools/$file' differs from latest version at '$file'" >&2 } +check () { + file=$1 + + shift + + check_2 ../$file ../../$file $* +} # Check if we have the kernel headers (tools/perf/../../include), else # we're probably on a detached tarball, so no point in trying to check
Signature · 1 line
2.13.6
Arnaldo Carvalho de Melo
maintainerRe: [PATCH 2/9] perf check-headers.sh: Add support to check 2 independent files
Em Mon, Apr 23, 2018 at 11:08:16AM +0200, Jiri Olsa escreveu:
Quoted 3 lines
Adding
check_2function to check 2 different files, the check function stays to check files that differs only in the prefix path.
Applied 1/9 and 2/9 to perf/core.
- Arnaldo
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf check-headers.sh: Add support to check 2 independent files
In reply to Jiri Olsaperf check-headers.sh: Add support to check 2 independent files
Commit-ID: 58247297359326603d601451223e0da6a97bee3c Gitweb: https://git.kernel.org/tip/58247297359326603d601451223e0da6a97bee3c Author: Jiri Olsa <[email protected]> AuthorDate: Mon, 23 Apr 2018 11:08:16 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 26 Apr 2018 09:30:26 -0300
perf check-headers.sh: Add support to check 2 independent files
Add 'check_2' function to check 2 different files, the 'check' function stays to check files that differs only in the prefix path.
In upcoming changes we need to check header files in locations which don't follow the prefix logic.
--- tools/perf/check-headers.sh | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
tools/perf/check-headers.sh +13 -4
@@ -55,17 +55,26 @@ include/uapi/asm-generic/ioctls.h include/uapi/asm-generic/mman-common.h ' -check () { - file=$1 +check_2 () { + file1=$1 + file2=$2 + shift shift - cmd="diff $* ../$file ../../$file > /dev/null" + cmd="diff $* $file1 $file2 > /dev/null" - test -f ../../$file && + test -f $file2 && eval $cmd || echo "Warning: Kernel ABI header at 'tools/$file' differs from latest version at '$file'" >&2 } +check () { + file=$1 + + shift + + check_2 ../$file ../../$file $* +} # Check if we have the kernel headers (tools/perf/../../include), else # we're probably on a detached tarball, so no point in trying to check
Jiri Olsa
reviewerPATCH 3/9 perf stat: Keep the / modifier separator in fallback
In reply to Jiri OlsaThe perf stat fallback for EACCES error sets exclude_kernel for event and repeats the open. In addition, it also changes the name of the event to reflect that change by adding the 'u' modifier.
But it does not take into account the '/' separator, so the event name can end up mangled, like:
(note the '/:' characters)
$ perf stat -e cpu/cpu-cycles/ kill
...
386,832 cpu/cpu-cycles/:uAdding the code to check on the '/' separatos and set following event name:
$ perf stat -e cpu/cpu-cycles/ kill
...
388,548 cpu/cpu-cycles/u--- tools/perf/util/evsel.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
tools/perf/util/evsel.c +7 -1
@@ -2754,8 +2754,14 @@ bool perf_evsel__fallback(struct perf_evsel *evsel, int err, (paranoid = perf_event_paranoid()) > 1) {const char *name =perf_evsel__name (evsel);char *new_name; +const char *sep =":" ; -if (asprintf (&new_name,"%s%su" , name,strchr (name,':' ) ?"" :":" ) <0 ) +/* Is there already the separator in the name. */ +if (strchr (name,'/' ) || +strchr (name,':' )) + sep ="" ; + +if (asprintf (&new_name,"%s%su" , name, sep) <0 )return false;if (evsel->name)
Signature · 1 line
2.13.6
Arnaldo Carvalho de Melo
maintainerRe: [PATCH 3/9] perf stat: Keep the / modifier separator in fallback
Em Mon, Apr 23, 2018 at 11:08:17AM +0200, Jiri Olsa escreveu:
Quoted 13 lines
The perf stat fallback for EACCES error sets
exclude_kernelfor event and repeats the open. In addition, it also changes the name of the event to reflect that change by adding the 'u' modifier.But it does not take into account the '/' separator, so the event name can end up mangled, like:
(note the '/:' characters)$ perf stat -e cpu/cpu-cycles/ kill ... 386,832 cpu/cpu-cycles/:u
Quoted 6 lines
Adding the code to check on the '/' separatos and set following event name:
$ perf stat -e cpu/cpu-cycles/ kill ... 388,548 cpu/cpu-cycles/u
Thanks, tested, reproduced and applied to perf/urgent
- Arnaldo
tip-bot for Jiri Olsa
merge bot[tip:perf/urgent] perf stat: Keep the / modifier separator in fallback
In reply to Jiri Olsaperf stat: Keep the / modifier separator in fallback
Commit-ID: 129193bb0c43d42f1c397c175346e3e0dba5a578 Gitweb: https://git.kernel.org/tip/129193bb0c43d42f1c397c175346e3e0dba5a578 Author: Jiri Olsa <[email protected]> AuthorDate: Mon, 23 Apr 2018 11:08:17 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 23 Apr 2018 11:14:10 -0300
perf stat: Keep the / modifier separator in fallback
The 'perf stat' fallback for EACCES error sets the exclude_kernel perf_event_attr and tries perf_event_open() again with it. In addition, it also changes the name of the event to reflect that change by adding the 'u' modifier.
But it does not take into account the '/' separator, so the event name can end up mangled, like: (note the '/:' characters)
$ perf stat -e cpu/cpu-cycles/ kill
...
386,832 cpu/cpu-cycles/:uAdding the code to check on the '/' separator and set the following correct event name:
$ perf stat -e cpu/cpu-cycles/ kill
...
388,548 cpu/cpu-cycles/u--- tools/perf/util/evsel.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
tools/perf/util/evsel.c +7 -1
@@ -2754,8 +2754,14 @@ bool perf_evsel__fallback(struct perf_evsel *evsel, int err, (paranoid = perf_event_paranoid()) > 1) {const char *name =perf_evsel__name (evsel);char *new_name; +const char *sep =":" ; -if (asprintf (&new_name,"%s%su" , name,strchr (name,':' ) ?"" :":" ) <0 ) +/* Is there already the separator in the name. */ +if (strchr (name,'/' ) || +strchr (name,':' )) + sep ="" ; + +if (asprintf (&new_name,"%s%su" , name, sep) <0 )return false;if (evsel->name)
Jiri Olsa
reviewerPATCH 4/9 perf tools: Fix pmu events parsing rule
In reply to Jiri OlsaCurrently all the event parsing fails end up in the event_pmu rule, and display misleading help like:
$ perf stat -e inst kill
event syntax error: 'inst'
\___ Cannot find PMU `inst'. Missing kernel support?
...The reason is that the event_pmu is too strong and match also single string. Changing it to force the '/' separators to be part of the rule, and getting the proper error now:
$ perf stat -e inst kill
event syntax error: 'inst'
\___ parser error
Run 'perf list' for a list of valid events
...--- tools/perf/util/parse-events.y | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
tools/perf/util/parse-events.y +4 -4
@@ -224,15 +224,15 @@ event_def: event_pmu | event_bpf_file event_pmu: -PE_NAME opt_event_config +PE_NAME '/' event_config '/' { struct list_head *list, *orig_terms, *terms; - if (parse_events_copy_term_list($2, &orig_terms)) + if (parse_events_copy_term_list($3, &orig_terms)) YYABORT; ALLOC_LIST(list); - if (parse_events_add_pmu(_parse_state, list, $1, $2, false)) { + if (parse_events_add_pmu(_parse_state, list, $1, $3, false)) { struct perf_pmu *pmu = NULL; int ok = 0; char *pattern;
@@ -262,7 +262,7 @@ PE_NAME opt_event_config if (!ok) YYABORT; } - parse_events_terms__delete($2); + parse_events_terms__delete($3); parse_events_terms__delete(orig_terms); $$ = list; }
Signature · 1 line
2.13.6
Arnaldo Carvalho de Melo
maintainerRe: [PATCH 4/9] perf tools: Fix pmu events parsing rule
Em Mon, Apr 23, 2018 at 11:08:18AM +0200, Jiri Olsa escreveu:
Quoted 14 lines
Currently all the event parsing fails end up in the
event_pmurule, and display misleading help like:$ perf stat -e inst kill event syntax error: 'inst' \___ Cannot find PMU `inst'. Missing kernel support? ...The reason is that the
event_pmuis too strong and match also single string. Changing it to force the '/' separators to be part of the rule, and getting the proper error now:
Quoted 4 lines
$ perf stat -e inst kill
event syntax error: 'inst'
\___ parser error
Run 'perf list' for a list of valid eventsI added a Reported-by: Ingo after checking that that was the case in tha private conversation we had, but I think this has to be further
improved: do we have enough context at this point to change that into:
$ perf stat -e inst kill
event syntax error: 'inst'
\___ unknown event
Run 'perf list' for a list of valid eventsInstead of the generic "parser error"? That "list of valid events" helps tho, but if we're going to say something at that \___ MSG part...
- Arnaldo
Quoted 42 lines
...
Signed-off-by Jiri Olsa <[email protected]>--- tools/perf/util/parse-events.y | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)tools/perf/util/parse-events.y +4
-4@@ -224,15 +224,15 @@ event_def: event_pmu | event_bpf_file event_pmu: -PE_NAME opt_event_config +PE_NAME '/' event_config '/' { struct list_head *list, *orig_terms, *terms; - if (parse_events_copy_term_list($2, &orig_terms)) + if (parse_events_copy_term_list($3, &orig_terms)) YYABORT; ALLOC_LIST(list); - if (parse_events_add_pmu(_parse_state, list, $1, $2, false)) { + if (parse_events_add_pmu(_parse_state, list, $1, $3, false)) { struct perf_pmu *pmu = NULL; int ok = 0; char *pattern;@@ -262,7 +262,7 @@ PE_NAME opt_event_config if (!ok) YYABORT; } - parse_events_terms__delete($2); + parse_events_terms__delete($3); parse_events_terms__delete(orig_terms); $$ = list; }Signature · 1 line
2.13.6
Re: [PATCH 4/9] perf tools: Fix pmu events parsing rule
Quoted 24 lines · Arnaldo Carvalho de Melo
Em Mon, Apr 23, 2018 at 11:08:18AM +0200, Jiri Olsa escreveu:
Quoted 14 lines
Currently all the event parsing fails end up in the
event_pmurule, and display misleading help like:$ perf stat -e inst kill event syntax error: 'inst' \___ Cannot find PMU `inst'. Missing kernel support? ...The reason is that the
event_pmuis too strong and match also single string. Changing it to force the '/' separators to be part of the rule, and getting the proper error now:Quoted 4 lines
$ perf stat -e inst kill event syntax error: 'inst' \___ parser error Run 'perf list' for a list of valid eventsI added a Reported-by: Ingo after checking that that was the case in tha private conversation we had, but I think this has to be further
improved: do we have enough context at this point to change that into:
Quoted 7 lines
$ perf stat -e inst kill event syntax error: 'inst' \___ unknown event Run 'perf list' for a list of valid eventsInstead of the generic "parser error"? That "list of valid events" helps tho, but if we're going to say something at that \___ MSG part...
yep, the plan is to display whatever match the user input out of the all known event names.. in this case 'inst' would match 'instructions' and some other arch related events
but it's some more work and this fix stands by itself ;-)
jirka
tip-bot for Jiri Olsa
merge bot[tip:perf/urgent] perf pmu: Fix pmu events parsing rule
In reply to Jiri Olsaperf pmu: Fix pmu events parsing rule
Commit-ID: 9a4a931ce847f4aaa12edf11b2e050e18bf45910 Gitweb: https://git.kernel.org/tip/9a4a931ce847f4aaa12edf11b2e050e18bf45910 Author: Jiri Olsa <[email protected]> AuthorDate: Mon, 23 Apr 2018 11:08:18 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 23 Apr 2018 11:17:27 -0300
perf pmu: Fix pmu events parsing rule
Currently all the event parsing fails end up in the event_pmu rule, and display misleading help like:
$ perf stat -e inst kill
event syntax error: 'inst'
\___ Cannot find PMU `inst'. Missing kernel support?
...The reason is that the event_pmu is too strong and match also single string. Changing it to force the '/' separators to be part of the rule, and getting the proper error now:
$ perf stat -e inst kill
event syntax error: 'inst'
\___ parser error
Run 'perf list' for a list of valid events
...--- tools/perf/util/parse-events.y | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
tools/perf/util/parse-events.y +4 -4
@@ -224,15 +224,15 @@ event_def: event_pmu | event_bpf_file event_pmu: -PE_NAME opt_event_config +PE_NAME '/' event_config '/' { struct list_head *list, *orig_terms, *terms; - if (parse_events_copy_term_list($2, &orig_terms)) + if (parse_events_copy_term_list($3, &orig_terms)) YYABORT; ALLOC_LIST(list); - if (parse_events_add_pmu(_parse_state, list, $1, $2, false)) { + if (parse_events_add_pmu(_parse_state, list, $1, $3, false)) { struct perf_pmu *pmu = NULL; int ok = 0; char *pattern;
@@ -262,7 +262,7 @@ PE_NAME opt_event_config if (!ok) YYABORT; } - parse_events_terms__delete($2); + parse_events_terms__delete($3); parse_events_terms__delete(orig_terms); $$ = list; }
Jiri Olsa
reviewerPATCH 5/9 perf tools: Disable write_backward for leader sampling group events
In reply to Jiri Olsa.. and other related fields that do not need to be enabled for events that have sampling leader.
It fixes the perf top usage Ingo reported broken:
# perf top -e '{cycles,msr/aperf/}:S'The msr/aperf/ is configured for write_back sampling, which is not allowed by msr pmu, so it fails to create the event.
Adjusting related attr test.
--- tools/perf/tests/attr/test-record-group-sampling | 3 +++ tools/perf/util/evsel.c | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-)
tools/perf/tests/attr/test-record-group-sampling +3 -0
@@ -35,3 +35,6 @@ inherit=0 # sampling disabled sample_freq=0 sample_period=0 +freq=0 +write_backward=0 +sample_id_all=0
tools/perf/util/evsel.c +5 -2
@@ -930,8 +930,11 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts,* than leader in case leader 'leads' the sampling. */ if ((leader != evsel) && leader->sample_read) { - attr->sample_freq =0 ; - attr->sample_period =0 ; + attr->freq =0 ; + attr->sample_freq =0 ; + attr->sample_period =0 ; + attr->write_backward =0 ; + attr->sample_id_all =0 ; }if (opts->no_samples)
Signature · 1 line
2.13.6
Re: [PATCH 5/9] perf tools: Disable write_backward for leader sampling group events
Em Mon, Apr 23, 2018 at 11:08:19AM +0200, Jiri Olsa escreveu:
Quoted 11 lines
.. and other related fields that do not need to be enabled for events that have sampling leader.
It fixes the perf top usage Ingo reported broken:
# perf top -e '{cycles,msr/aperf/}:S'The msr/aperf/ is configured for
write_backsampling, which is not allowed by msr pmu, so it fails to create the event.Adjusting related attr test.
Applied to perf/urgent.
- Arnaldo
tip-bot for Jiri Olsa
merge bot[tip:perf/urgent] perf evsel: Disable write_backward for leader sampling group events
In reply to Jiri Olsaperf evsel: Disable write_backward for leader sampling group events
Commit-ID: e9add8bac6c69edb4bf391e537faa659b2ed70d2 Gitweb: https://git.kernel.org/tip/e9add8bac6c69edb4bf391e537faa659b2ed70d2 Author: Jiri Olsa <[email protected]> AuthorDate: Mon, 23 Apr 2018 11:08:19 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 23 Apr 2018 11:21:56 -0300
perf evsel: Disable write_backward for leader sampling group events
.. and other related fields that do not need to be enabled for events that have sampling leader.
It fixes the perf top usage Ingo reported broken:
# perf top -e '{cycles,msr/aperf/}:S'The 'msr/aperf/' event is configured for write_back sampling, which is not allowed by the MSR PMU, so it fails to create the event.
Adjusting related attr test.
--- tools/perf/tests/attr/test-record-group-sampling | 3 +++ tools/perf/util/evsel.c | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-)
tools/perf/tests/attr/test-record-group-sampling +3 -0
@@ -35,3 +35,6 @@ inherit=0 # sampling disabled sample_freq=0 sample_period=0 +freq=0 +write_backward=0 +sample_id_all=0
tools/perf/util/evsel.c +5 -2
@@ -930,8 +930,11 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts,* than leader in case leader 'leads' the sampling. */ if ((leader != evsel) && leader->sample_read) { - attr->sample_freq =0 ; - attr->sample_period =0 ; + attr->freq =0 ; + attr->sample_freq =0 ; + attr->sample_period =0 ; + attr->write_backward =0 ; + attr->sample_id_all =0 ; }if (opts->no_samples)
Jiri Olsa
reviewerPATCH 6/9 perf stat: Display time in precision based on std deviation
In reply to Jiri OlsaIngo suggested to display elapsed time for multirun workload (perf stat -e) with precision based on the precision of the standard deviation.
In his own words:
Quoted 8 lines
It would be better if perf stat would display elapsed time with a precision adjusted to stddev, it should display at most 2 more significant digits than the stddev inaccuracy.
I.e. in the above case 0.39% is 0.109, so we only have accuracy for 1 digit, and so we should only display 3:
27.988 seconds time elapsed ( +- 0.39% )
Plus suggestion about the output, which is small enough and connected with above change that I merged both changes together.
Quoted 4 lines
Small output style nit - I think it would be nice if with --repeat the stddev was also displayed in absolute values, besides percentage:
27.988 +- 0.109 seconds time elapsed ( +- 0.39% )
The output is now:
Performance counter stats for './perf bench sched pipe' (5 runs):
SNIP
13.3667 +- 0.0256 seconds time elapsed ( +- 0.19% )
--- tools/perf/builtin-stat.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-)
tools/perf/builtin-stat.c +24 -6
@@ -1733,19 +1733,37 @@ static void print_header(int argc, const char **argv) } } +static int get_precision (double num) +{ +if (num >1 ) +return 0 ; + +return lround (ceil (-log10 (num))); +} +static void print_footer (void ) { +double avg =avg_stats (&walltime_nsecs_stats) /NSEC_PER_SEC ;FILE *output = stat_config.output;int n;if (!null_run)fprintf (output,"\n" ); -fprintf (output," %17.9f seconds time elapsed" , -avg_stats (&walltime_nsecs_stats) /NSEC_PER_SEC ); -if (run_count >1 ) { -fprintf (output," " ); -print_noise_pct (stddev_stats (&walltime_nsecs_stats), -avg_stats (&walltime_nsecs_stats)); + +if (run_count ==1 ) { +fprintf (output," %17.9f seconds time elapsed" , avg); + }else { +double sd =stddev_stats (&walltime_nsecs_stats) /NSEC_PER_SEC ; +/* +* Display at most 2 more significant +* digits than the stddev inaccuracy. +*/ +int precision =get_precision (sd) +2 ; + +fprintf (output," %17.*f +- %.*f seconds time elapsed" , + precision, avg, precision, sd); + +print_noise_pct (sd, avg); }fprintf (output,"\n\n" );
Signature · 1 line
2.13.6
Arnaldo Carvalho de Melo
maintainerRe: [PATCH 6/9] perf stat: Display time in precision based on std deviation
Em Mon, Apr 23, 2018 at 11:08:20AM +0200, Jiri Olsa escreveu:
Quoted 5 lines
Ingo suggested to display elapsed time for multirun workload (perf stat -e) with precision based on the precision of the standard deviation.
In his own words:
Tested and applied to perf/core.
- Arnaldo
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf stat: Display time in precision based on std deviation
In reply to Jiri Olsaperf stat: Display time in precision based on std deviation
Commit-ID: bc22de9bcdb2249150fb5b3c48fdc4f6bedd3ad7 Gitweb: https://git.kernel.org/tip/bc22de9bcdb2249150fb5b3c48fdc4f6bedd3ad7 Author: Jiri Olsa <[email protected]> AuthorDate: Mon, 23 Apr 2018 11:08:20 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 26 Apr 2018 09:30:27 -0300
perf stat: Display time in precision based on std deviation
Ingo suggested to display elapsed time for multirun workload (perf stat -e) with precision based on the precision of the standard deviation.
In his own words:
Quoted 8 lines
This output is a slightly bit misleading:
Performance counter stats for 'make -j128' (10 runs):
27.988995256 seconds time elapsed ( +- 0.39% )The 9 significant digits in the result, while only 1 is valid, suggests accuracy where none exists.
Quoted 8 lines
It would be better if 'perf stat' would display elapsed time with a precision adjusted to stddev, it should display at most 2 more significant digits than the stddev inaccuracy.
I.e. in the above case 0.39% is 0.109, so we only have accuracy for 1 digit, and so we should only display 3:
27.988 seconds time elapsed ( +- 0.39% )
Plus a suggestion about the output, which is small enough and connected with the above change that I merged both changes together.
Quoted 4 lines
Small output style nit - I think it would be nice if with --repeat the stddev was also displayed in absolute values, besides percentage:
27.988 +- 0.109 seconds time elapsed ( +- 0.39% )
The output is now:
Performance counter stats for './perf bench sched pipe' (5 runs):
SNIP
13.3667 +- 0.0256 seconds time elapsed ( +- 0.19% )
--- tools/perf/builtin-stat.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-)
tools/perf/builtin-stat.c +24 -6
@@ -1764,19 +1764,37 @@ static void print_header(int argc, const char **argv) } } +static int get_precision (double num) +{ +if (num >1 ) +return 0 ; + +return lround (ceil (-log10 (num))); +} +static void print_footer (void ) { +double avg =avg_stats (&walltime_nsecs_stats) /NSEC_PER_SEC ;FILE *output = stat_config.output;int n;if (!null_run)fprintf (output,"\n" ); -fprintf (output," %17.9f seconds time elapsed" , -avg_stats (&walltime_nsecs_stats) /NSEC_PER_SEC ); -if (run_count >1 ) { -fprintf (output," " ); -print_noise_pct (stddev_stats (&walltime_nsecs_stats), -avg_stats (&walltime_nsecs_stats)); + +if (run_count ==1 ) { +fprintf (output," %17.9f seconds time elapsed" , avg); + }else { +double sd =stddev_stats (&walltime_nsecs_stats) /NSEC_PER_SEC ; +/* +* Display at most 2 more significant +* digits than the stddev inaccuracy. +*/ +int precision =get_precision (sd) +2 ; + +fprintf (output," %17.*f +- %.*f seconds time elapsed" , + precision, avg, precision, sd); + +print_noise_pct (sd, avg); }fprintf (output,"\n\n" );
Jiri Olsa
reviewerPATCH 7/9 perf stat: Add --table option to display time of each run
In reply to Jiri OlsaAdding --table option to display time for each
run (-r option), like:
$ perf stat --null -r 5 --table perf bench sched pipe
Performance counter stats for './perf bench sched pipe' (5 runs):
# Table of individual measurements:
5.379 (-0.176)
5.243 (-0.311)
5.238 (-0.317)
5.536 (-0.019)
6.377 (+0.823)
# Final result:
5.555 +- 0.213 seconds time elapsed ( +- 3.83% )--- tools/perf/builtin-stat.c | 56 +++++++++++++++++++++++++++++++++++++++++++---- tools/perf/util/stat.h | 3 +-- 2 files changed, 53 insertions(+), 6 deletions(-)
tools/perf/builtin-stat.c +52 -4
@@ -164,6 +164,7 @@ static bool forever = false;static bool metric_only = false;static bool force_metric_only = false;static bool no_merge = false; +static bool walltime_run_table = false;static struct timespec ref_time;static struct cpu_map *aggr_map;static aggr_get_id_t aggr_get_id;
@@ -172,6 +173,7 @@ static bool interval_count;static const char *output_name;static int output_fd;static int print_free_counters_hint; +static u64 *walltime_run;struct perf_stat {bool record;
@@ -568,7 +570,7 @@ static struct perf_evsel *perf_evsel__reset_weak_group(struct perf_evsel *evsel)return leader; } -static int __run_perf_stat (int argc,const char **argv) +static int __run_perf_stat (int argc,const char **argv,int run_idx) {int interval = stat_config.interval;int times = stat_config.times;
@@ -751,6 +753,9 @@ static int __run_perf_stat(int argc, const char **argv) t1 =rdclock (); +if (walltime_run_table) + walltime_run[run_idx] = t1 - t0; +update_stats (&walltime_nsecs_stats, t1 - t0);/*
@@ -765,7 +770,7 @@ static int __run_perf_stat(int argc, const char **argv)return WEXITSTATUS (status); } -static int run_perf_stat (int argc,const char **argv) +static int run_perf_stat (int argc,const char **argv,int run_idx) {int ret;
@@ -778,7 +783,7 @@ static int run_perf_stat(int argc, const char **argv)if (sync_run)sync (); - ret =__run_perf_stat (argc, argv); + ret =__run_perf_stat (argc, argv, run_idx);if (ret)return ret;
@@ -1741,6 +1746,27 @@ static int get_precision(double num)return lround (ceil (-log10 (num))); } +static void print_table (FILE *output,int precision,double avg) +{ +char tmp[64 ]; +int idx, indent =0 ; + +scnprintf (tmp,64 ," %17.*f" , precision, avg); +while (tmp[indent] ==' ' ) + indent++; + +fprintf (output,"%*s# Table of individual measurements:\n" , indent,"" ); + +for (idx =0 ; idx < run_count; idx++) { +double run = (double ) walltime_run[idx] /NSEC_PER_SEC ; + +fprintf (output," %17.*f (%+.*f)\n" , + precision, run, precision, run - avg); + } + +fprintf (output,"\n%*s# Final result:\n" , indent,"" ); +} +static void print_footer (void ) {double avg =avg_stats (&walltime_nsecs_stats) /NSEC_PER_SEC ;
@@ -1760,6 +1786,9 @@ static void print_footer(void)*/ int precision =get_precision (sd) +2 ; +if (walltime_run_table) +print_table (output, precision, avg); +fprintf (output," %17.*f +- %.*f seconds time elapsed" , precision, avg, precision, sd);
@@ -1934,6 +1963,8 @@ static const struct option stat_options[] = { "be more verbose (show counter open errors, etc)"),OPT_INTEGER ('r' ,"repeat" , &run_count,"repeat command and print average + stddev (max: 100, forever: 0)" ), +OPT_BOOLEAN (0 ,"table" , &walltime_run_table, +"display details about each run (only with -r option)" ),OPT_BOOLEAN ('n' ,"null" , &null_run,"null run - dont start any counters" ), OPT_INCR('d', "detailed", &detailed_run,
@@ -2825,6 +2856,13 @@ int cmd_stat(int argc, const char **argv) goto out; } +if (walltime_run_table && run_count <=1 ) { +fprintf (stderr,"--table is only supported with -r\n" ); +parse_options_usage (stat_usage, stat_options,"r" ,1 ); +parse_options_usage (NULL , stat_options,"table" ,0 ); + goto out; + } +if (output_fd <0 ) {fprintf (stderr,"argument to --log-fd must be a > 0\n" );parse_options_usage (stat_usage, stat_options,"log-fd" ,0 );
@@ -2879,6 +2917,14 @@ int cmd_stat(int argc, const char **argv) run_count =1 ; } +if (walltime_run_table) { + walltime_run =zalloc (run_count *sizeof (walltime_run[0 ])); +if (!walltime_run) { +pr_err ("failed to setup -r option" ); + goto out; + } + } +if ((stat_config.aggr_mode ==AGGR_THREAD ) && !target__has_task (&target)) {if (!target.system_wide || target.cpu_list) {
@@ -2994,7 +3040,7 @@ int cmd_stat(int argc, const char **argv)fprintf (output,"[ perf stat: executing run #%d ... ]\n" , run_idx +1 ); - status =run_perf_stat (argc, argv); + status =run_perf_stat (argc, argv, run_idx);if (forever && status !=-1 ) {print_counters (NULL , argc, argv);perf_stat__reset_stats ();
@@ -3042,6 +3088,8 @@ int cmd_stat(int argc, const char **argv)perf_stat__exit_aggr_mode ();perf_evlist__free_stats (evsel_list); out: +free (walltime_run); +if (smi_cost && smi_reset)sysfs__write_int (FREEZE_ON_SMI_PATH ,0 );
tools/perf/util/stat.h +1 -2
@@ -7,8 +7,7 @@#include "xyarray.h" #include "rblist.h" -struct stats -{ +struct stats {double n, mean, M2;u64 max, min; };
Signature · 1 line
2.13.6
Arnaldo Carvalho de Melo
maintainerRe: [PATCH 7/9] perf stat: Add --table option to display time of each run
Em Mon, Apr 23, 2018 at 11:08:21AM +0200, Jiri Olsa escreveu:
Quoted 2 lines
Adding --table option to display time for each
run (-r option), like:
You forgot to add this to 'perf stat's man page, I'm doing it this time,
- Arnaldo
Re: [PATCH 7/9] perf stat: Add --table option to display time of each run
Quoted 5 lines · Arnaldo Carvalho de Melo
Em Mon, Apr 23, 2018 at 11:08:21AM +0200, Jiri Olsa escreveu:
Quoted 2 lines
Adding --table option to display time for each
run (-r option), like:You forgot to add this to 'perf stat's man page, I'm doing it this time,
ugh, sry.. thanks ;-)
jirka
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf stat: Add --table option to display time of each run
In reply to Jiri Olsaperf stat: Add --table option to display time of each run
Commit-ID: e55c14af488a728d314777f038bd05db18afc1e9 Gitweb: https://git.kernel.org/tip/e55c14af488a728d314777f038bd05db18afc1e9 Author: Jiri Olsa <[email protected]> AuthorDate: Mon, 23 Apr 2018 11:08:21 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 26 Apr 2018 09:30:27 -0300
perf stat: Add --table option to display time of each run
Add --table option to display time for each run (-r option), like:
$ perf stat --null -r 5 --table perf bench sched pipe
Performance counter stats for './perf bench sched pipe' (5 runs):
# Table of individual measurements:
5.379 (-0.176)
5.243 (-0.311)
5.238 (-0.317)
5.536 (-0.019)
6.377 (+0.823)
# Final result:
5.555 +- 0.213 seconds time elapsed ( +- 3.83% )--- tools/perf/Documentation/perf-stat.txt | 16 ++++++++++ tools/perf/builtin-stat.c | 56 +++++++++++++++++++++++++++++++--- tools/perf/util/stat.h | 3 +- 3 files changed, 69 insertions(+), 6 deletions(-)
tools/perf/Documentation/perf-stat.txt +16 -0
@@ -116,6 +116,22 @@ Do not aggregate counts across all monitored CPUs. print counts using a CSV-style output to make it easy to import directly into spreadsheets. Columns are separated by the string specified in SEP. +--table:: Display time for each run (-r option), in a table format, e.g.: + + $ perf stat --null -r 5 --table perf bench sched pipe + + Performance counter stats for 'perf bench sched pipe' (5 runs): + + # Table of individual measurements: + 5.379 (-0.176) + 5.243 (-0.311) + 5.238 (-0.317) + 5.536 (-0.019) + 6.377 (+0.823) + + # Final result: + 5.555 +- 0.213 seconds time elapsed ( +- 3.83% ) + -G name:: --cgroup name:: monitor only in the container (cgroup) called "name". This option is available only
tools/perf/builtin-stat.c +52 -4
134 lines not on this page · raw message
tools/perf/util/stat.h +1 -2
@@ -7,8 +7,7 @@#include "xyarray.h" #include "rblist.h" -struct stats -{ +struct stats {double n, mean, M2;u64 max, min; };
Jiri Olsa
reviewerPATCH 8/9 perf stat: Display length strings of each run for --table option
In reply to Jiri OlsaAdding support to display visual aid 'length strings' to easily spot the biggest difference in time table.
$ perf stat -r 10 --table perf bench sched pipe ...
Performance counter stats for './perf bench sched pipe' (5 runs):
# Table of individual measurements:
5.189 (-0.293) #
5.189 (-0.294) #
5.186 (-0.296) #
5.663 (+0.181) ##
6.186 (+0.703) ####
# Final result:
5.483 +- 0.198 seconds time elapsed ( +- 3.62% )--- tools/perf/builtin-stat.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
tools/perf/builtin-stat.c +7 -1
@@ -1759,9 +1759,15 @@ static void print_table(FILE *output, int precision, double avg)for (idx =0 ; idx < run_count; idx++) {double run = (double ) walltime_run[idx] /NSEC_PER_SEC ; +int h, n =1 +abs ((int ) (100.0 * (run - avg)/run) /5 ); -fprintf (output," %17.*f (%+.*f)\n" , +fprintf (output," %17.*f (%+.*f) " , precision, run, precision, run - avg); + +for (h =0 ; h < n; h++) +fprintf (output,"#" ); + +fprintf (output,"\n" ); }fprintf (output,"\n%*s# Final result:\n" , indent,"" );
Signature · 1 line
2.13.6
tip-bot for Jiri Olsa
merge bot[tip:perf/core] perf stat: Display length strings of each run for --table option
perf stat: Display length strings of each run for --table option
Commit-ID: abc60bad0030193ffb55e438664bc09ac53939cf Gitweb: https://git.kernel.org/tip/abc60bad0030193ffb55e438664bc09ac53939cf Author: Jiri Olsa <[email protected]> AuthorDate: Mon, 23 Apr 2018 11:08:22 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Thu, 26 Apr 2018 09:30:27 -0300
perf stat: Display length strings of each run for --table option
Adding support to display visual aid 'length strings' to easily spot the biggest difference in time table.
$ perf stat -r 10 --table perf bench sched pipe ...
Performance counter stats for './perf bench sched pipe' (5 runs):
# Table of individual measurements:
5.189 (-0.293) #
5.189 (-0.294) #
5.186 (-0.296) #
5.663 (+0.181) ##
6.186 (+0.703) ####
# Final result:
5.483 +- 0.198 seconds time elapsed ( +- 3.62% )--- tools/perf/Documentation/perf-stat.txt | 12 ++++++------ tools/perf/builtin-stat.c | 8 +++++++- 2 files changed, 13 insertions(+), 7 deletions(-)
tools/perf/Documentation/perf-stat.txt +6 -6
@@ -123,14 +123,14 @@ spreadsheets. Columns are separated by the string specified in SEP. Performance counter stats for 'perf bench sched pipe' (5 runs): # Table of individual measurements: - 5.379 (-0.176) - 5.243 (-0.311) - 5.238 (-0.317) - 5.536 (-0.019) - 6.377 (+0.823) + 5.189 (-0.293) # + 5.189 (-0.294) # + 5.186 (-0.296) # + 5.663 (+0.181) ## + 6.186 (+0.703) #### # Final result: - 5.555 +- 0.213 seconds time elapsed ( +- 3.83% ) + 5.483 +- 0.198 seconds time elapsed ( +- 3.62% ) -G name:: --cgroup name::
tools/perf/builtin-stat.c +7 -1
@@ -1790,9 +1790,15 @@ static void print_table(FILE *output, int precision, double avg)for (idx =0 ; idx < run_count; idx++) {double run = (double ) walltime_run[idx] /NSEC_PER_SEC ; +int h, n =1 +abs ((int ) (100.0 * (run - avg)/run) /5 ); -fprintf (output," %17.*f (%+.*f)\n" , +fprintf (output," %17.*f (%+.*f) " , precision, run, precision, run - avg); + +for (h =0 ; h < n; h++) +fprintf (output,"#" ); + +fprintf (output,"\n" ); }fprintf (output,"\n%*s# Final result:\n" , indent,"" );
Jiri Olsa
reviewerPATCH 9/9 perf stat: Display user and system time
In reply to Jiri OlsaAdding the support to read rusage data once the
workload is finished and display the system/user
time values:
$ perf stat --null ./perf bench sched pipe ...
Performance counter stats for './perf bench sched pipe':
5.342599256 seconds time elapsed
2.544434000 seconds user
4.549691000 seconds sysIt works only in non -r mode.
--- tools/perf/builtin-stat.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)
tools/perf/builtin-stat.c +27 -1
@@ -80,6 +80,9 @@#include <sys/stat.h> #include <sys/wait.h> #include <unistd.h> +#include <sys/time.h> +#include <sys/resource.h> +#include <sys/wait.h> #include "sane_ctype.h"
@@ -174,6 +177,8 @@ static const char *output_name;static int output_fd;static int print_free_counters_hint;static u64 *walltime_run; +static bool ru_display = false; +static struct rusage ru_data;struct perf_stat {bool record;
@@ -725,7 +730,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)break ; } } -waitpid (child_pid, &status,0 ); +wait4 (child_pid, &status,0 , &ru_data);if (workload_exec_errno) {const char *emsg =str_error_r (workload_exec_errno, msg,sizeof (msg));
@@ -1773,6 +1778,11 @@ static void print_table(FILE *output, int precision, double avg)fprintf (output,"\n%*s# Final result:\n" , indent,"" ); } +static double timeval2double (struct timeval *t) +{ +return t->tv_sec + (double ) t->tv_usec/USEC_PER_SEC ; +} +static void print_footer (void ) {double avg =avg_stats (&walltime_nsecs_stats) /NSEC_PER_SEC ;
@@ -1784,6 +1794,15 @@ static void print_footer(void)if (run_count ==1 ) {fprintf (output," %17.9f seconds time elapsed" , avg); + +if (ru_display) { +double utime =timeval2double (&ru_data.ru_utime); +double stime =timeval2double (&ru_data.ru_stime); + +fprintf (output,"\n\n" ); +fprintf (output," %17.9f seconds user\n" , utime); +fprintf (output," %17.9f seconds sys\n" , stime); + } }else {double sd =stddev_stats (&walltime_nsecs_stats) /NSEC_PER_SEC ;/*
@@ -2869,6 +2888,13 @@ int cmd_stat(int argc, const char **argv) goto out; } +/* +* Display user/system times only for single +* run and when there's specified tracee. +*/ +if ((run_count ==1 ) &&target__none (&target)) + ru_display = true; +if (output_fd <0 ) {fprintf (stderr,"argument to --log-fd must be a > 0\n" );parse_options_usage (stat_usage, stat_options,"log-fd" ,0 );
Signature · 1 line
2.13.6
Arnaldo Carvalho de Melo
maintainerRe: [PATCH 9/9] perf stat: Display user and system time
Em Mon, Apr 23, 2018 at 11:08:23AM +0200, Jiri Olsa escreveu:
Quoted 7 lines
Adding the support to read rusage data once the
workload is finished and display the system/user
time values:$ perf stat --null ./perf bench sched pipe ...
Quoted 6 lines
Performance counter stats for './perf bench sched pipe':
5.342599256 seconds time elapsed
2.544434000 seconds user
4.549691000 seconds sysPlease write a setence or two explaining the above three timings, do it nicely so that we can add it to the man page and avoid people scratching heads :-)
All the other patches were applied, some to perf/urgent (fixes) the remaining ones, new features, added to perf/core, up to Ingo to decide where to merge when I get to ask him to pull.
- Arnaldo
Quoted 85 lines
It works only in non -r mode.
Suggested-by Ingo Molnar <[email protected]>Signed-off-by Jiri Olsa <[email protected]>--- tools/perf/builtin-stat.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)tools/perf/builtin-stat.c +27
-1@@ -80,6 +80,9 @@#include <sys/stat.h> #include <sys/wait.h> #include <unistd.h> +#include <sys/time.h> +#include <sys/resource.h> +#include <sys/wait.h> #include "sane_ctype.h" @@ -174,6 +177,8 @@ static const char *output_name;static int output_fd;static int print_free_counters_hint;static u64 *walltime_run; +static bool ru_display = false; +static struct rusage ru_data;struct perf_stat {bool record;@@ -725,7 +730,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)break ; } } -waitpid (child_pid, &status,0 ); +wait4 (child_pid, &status,0 , &ru_data);if (workload_exec_errno) {const char *emsg =str_error_r (workload_exec_errno, msg,sizeof (msg));@@ -1773,6 +1778,11 @@ static void print_table(FILE *output, int precision, double avg)fprintf (output,"\n%*s# Final result:\n" , indent,"" ); } +static double timeval2double (struct timeval *t) +{ +return t->tv_sec + (double ) t->tv_usec/USEC_PER_SEC ; +} +static void print_footer (void ) {double avg =avg_stats (&walltime_nsecs_stats) /NSEC_PER_SEC ;@@ -1784,6 +1794,15 @@ static void print_footer(void)if (run_count ==1 ) {fprintf (output," %17.9f seconds time elapsed" , avg); + +if (ru_display) { +double utime =timeval2double (&ru_data.ru_utime); +double stime =timeval2double (&ru_data.ru_stime); + +fprintf (output,"\n\n" ); +fprintf (output," %17.9f seconds user\n" , utime); +fprintf (output," %17.9f seconds sys\n" , stime); + } }else {double sd =stddev_stats (&walltime_nsecs_stats) /NSEC_PER_SEC ;/* @@ -2869,6 +2888,13 @@ int cmd_stat(int argc, const char **argv) goto out; } +/* +* Display user/system times only for single +* run and when there's specified tracee. +*/ +if ((run_count ==1 ) &&target__none (&target)) + ru_display = true; +if (output_fd <0 ) {fprintf (stderr,"argument to --log-fd must be a > 0\n" );parse_options_usage (stat_usage, stat_options,"log-fd" ,0 );Signature · 1 line
2.13.6
Re: [PATCH 9/9] perf stat: Display user and system time
Quoted 10 lines · Arnaldo Carvalho de Melo
Em Mon, Apr 23, 2018 at 11:08:23AM +0200, Jiri Olsa escreveu:
Quoted 9 lines
Adding the support to read rusage data once the
workload is finished and display the system/user
time values:$ perf stat --null ./perf bench sched pipe ...Performance counter stats for './perf bench sched pipe':
Quoted 8 lines
Quoted 4 lines
5.342599256 seconds time elapsed 2.544434000 seconds user 4.549691000 seconds sysPlease write a setence or two explaining the above three timings, do it nicely so that we can add it to the man page and avoid people scratching heads :-)
will do ;-)
Quoted 4 lines
All the other patches were applied, some to perf/urgent (fixes) the remaining ones, new features, added to perf/core, up to Ingo to decide where to merge when I get to ask him to pull.
cool, thanks
jirka
Quoted 88 lines
- Arnaldo
Quoted 85 lines
It works only in non -r mode.
Suggested-by Ingo Molnar <[email protected]>Signed-off-by Jiri Olsa <[email protected]>--- tools/perf/builtin-stat.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)tools/perf/builtin-stat.c +27
-1@@ -80,6 +80,9 @@#include <sys/stat.h> #include <sys/wait.h> #include <unistd.h> +#include <sys/time.h> +#include <sys/resource.h> +#include <sys/wait.h> #include "sane_ctype.h" @@ -174,6 +177,8 @@ static const char *output_name;static int output_fd;static int print_free_counters_hint;static u64 *walltime_run; +static bool ru_display = false; +static struct rusage ru_data;struct perf_stat {bool record;@@ -725,7 +730,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)break ; } } -waitpid (child_pid, &status,0 ); +wait4 (child_pid, &status,0 , &ru_data);if (workload_exec_errno) {const char *emsg =str_error_r (workload_exec_errno, msg,sizeof (msg));@@ -1773,6 +1778,11 @@ static void print_table(FILE *output, int precision, double avg)fprintf (output,"\n%*s# Final result:\n" , indent,"" ); } +static double timeval2double (struct timeval *t) +{ +return t->tv_sec + (double ) t->tv_usec/USEC_PER_SEC ; +} +static void print_footer (void ) {double avg =avg_stats (&walltime_nsecs_stats) /NSEC_PER_SEC ;@@ -1784,6 +1794,15 @@ static void print_footer(void)if (run_count ==1 ) {fprintf (output," %17.9f seconds time elapsed" , avg); + +if (ru_display) { +double utime =timeval2double (&ru_data.ru_utime); +double stime =timeval2double (&ru_data.ru_stime); + +fprintf (output,"\n\n" ); +fprintf (output," %17.9f seconds user\n" , utime); +fprintf (output," %17.9f seconds sys\n" , stime); + } }else {double sd =stddev_stats (&walltime_nsecs_stats) /NSEC_PER_SEC ;/* @@ -2869,6 +2888,13 @@ int cmd_stat(int argc, const char **argv) goto out; } +/* +* Display user/system times only for single +* run and when there's specified tracee. +*/ +if ((run_count ==1 ) &&target__none (&target)) + ru_display = true; +if (output_fd <0 ) {fprintf (stderr,"argument to --log-fd must be a > 0\n" );parse_options_usage (stat_usage, stat_options,"log-fd" ,0 );Signature · 1 line
2.13.6
Arnaldo Carvalho de Melo
maintainerEm Mon, Apr 23, 2018 at 11:08:14AM +0200, Jiri Olsa escreveu:
Quoted 8 lines
hi,
sending assorted general fixes that queued
up in my other branches.Arnaldo,
I added wait4 call in the last patch and am wondering if it will pass your all-distros-docker test ;-) If not I'll need to put some build detection code.
That wasn't a problem, but centos:5, centos:6 didn't like this:
CC /tmp/build/perf/util/evsel.o
cc1: warnings being treated as errorsbuiltin-stat.c: In function 'print_footer':
builtin-stat.c:1800: warning: declaration of 'stime' shadows a global declaration /usr/include/time.h:297: warning: shadowed declaration is here
mv: cannot stat `/tmp/build/perf/.builtin-stat.o.tmp': No such file or directory make[3]: *** [/tmp/build/perf/builtin-stat.o] Error 1
make[3]: *** Waiting for unfinished jobs....
debian:7 didn't like something else, unrelated to your patches:
CC /tmp/build/perf/util/ctype.obuiltin-buildid-cache.c: In function 'cmd_buildid_cache':
builtin-buildid-cache.c:267:2: error: 'err' may be used uninitialized in this function [-Werror=uninitialized] builtin-buildid-cache.c:247:6: note: 'err' was declared here
MKDIR /tmp/build/perf/util/
I'm hunting down the patch that introduced this last one...
- Arnaldo