perf top: Use active evsel for non-sample events on old kernel
PATCH 1/5 perf top: Use active evsel for non-sample events on old kernel
If multiple events are specified on old kernel, perf_evlist__id2evsel() returns NULL for non-sampling events since the sample.id doesn't contain valid value, and it triggers assert below. If only one event is given, the function returns the evsel regardless of sample.id, this is why most case cause no problem on old kernel.
Fix it by using active evsel.
--- tools/perf/builtin-top.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
tools/perf/builtin-top.c +8 -0
@@ -771,6 +771,14 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx) } evsel =perf_evlist__id2evsel (session->evlist, sample.id); +if (evsel ==NULL && !session->sample_id_all && + event->header.type !=PERF_RECORD_SAMPLE ) { +/* +* Old kernel, no sample_id_all field. +* Just use active evsel. +*/ + evsel = top->sym_evsel; + }assert (evsel !=NULL ); origin = event->header.misc &PERF_RECORD_MISC_CPUMODE_MASK ;
Signature · 1 line
1.7.8.2
PATCH 3/5 perf stat: Add error message for EMFILE
When a user tries to open so many events, perf_event_oen syscall may fail with EMFILE. Provide an advice for that case.
--- tools/perf/builtin-stat.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
tools/perf/builtin-stat.c +3 -0
@@ -477,6 +477,9 @@ static int run_perf_stat(int argc __used, const char **argv)"\t Consider tweaking" " /proc/sys/kernel/perf_event_paranoid or running as root." , system_wide ? "system-wide " : ""); + }else if (errno ==EMFILE ) { +error ("Too many events are opened.\n" +"\t Try again after reducing the number of events.\n" ); }else { error("open_counter returned with %d (%s). " "/bin/dmesg may provide additional information.\n",
Signature · 1 line
1.7.8.2
PATCH 2/5 perf record: Add error message for EMFILE
In reply to Namhyung KimWhen a user tries to open so many events, perf_event_oen syscall may fail with EMFILE. Provide an advice for that case.
--- tools/perf/builtin-record.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
tools/perf/builtin-record.c +4 -0
@@ -249,6 +249,10 @@ try_again:ui__warning ("The %s event is not supported.\n" ,event_name (pos));exit (EXIT_FAILURE ); + }else if (err ==EMFILE ) { +ui__warning ("Too many events are opened.\n" +"Try again after reducing the number of events.\n" ); +exit (EXIT_FAILURE ); }printf ("\n" );
Signature · 1 line
1.7.8.2
PATCH 4/5 perf tools: Remove unnecessary ctype.h inclusion
In reply to Namhyung KimThere are unnecessary #include <ctype.h> out there, and they might cause a nasty build failure in some environment. As we already have most of ctype macros in util.h, just get rid of them.
A few of exceptions are util/symbol.c which needs isupper() macro util.h doesn't provide and perl scripting support code which includes ctype.h internally.
--- tools/perf/bench/mem-memcpy.c | 1 - tools/perf/bench/mem-memset.c | 1 - tools/perf/util/probe-finder.c | 1 - .../util/scripting-engines/trace-event-python.c | 1 - tools/perf/util/trace-event-parse.c | 1 - tools/perf/util/trace-event-read.c | 1 - tools/perf/util/trace-event-scripting.c | 1 - tools/perf/util/ui/browsers/map.c | 2 +- 8 files changed, 1 insertions(+), 8 deletions(-)
tools/perf/bench/mem-memcpy.c +0 -1
@@ -5,7 +5,6 @@* * Written by Hitoshi Mitake <[email protected]> */ -#include <ctype.h> #include "../perf.h" #include "../util/util.h"
tools/perf/bench/mem-memset.c +0 -1
@@ -5,7 +5,6 @@* * Trivial clone of mem-memcpy.c. */ -#include <ctype.h> #include "../perf.h" #include "../util/util.h"
tools/perf/util/probe-finder.c +0 -1
@@ -30,7 +30,6 @@#include <stdlib.h> #include <string.h> #include <stdarg.h> -#include <ctype.h> #include <dwarf-regs.h> #include <linux/bitops.h>
tools/perf/util/scripting-engines/trace-event-python.c +0 -1
@@ -24,7 +24,6 @@#include <stdio.h> #include <stdlib.h> #include <string.h> -#include <ctype.h> #include <errno.h> #include "../../perf.h"
tools/perf/util/trace-event-parse.c +0 -1
@@ -25,7 +25,6 @@#include <stdio.h> #include <stdlib.h> #include <string.h> -#include <ctype.h> #include <errno.h> #include "../perf.h"
tools/perf/util/trace-event-read.c +0 -1
@@ -33,7 +33,6 @@#include <pthread.h> #include <fcntl.h> #include <unistd.h> -#include <ctype.h> #include <errno.h> #include "../perf.h"
tools/perf/util/trace-event-scripting.c +0 -1
@@ -22,7 +22,6 @@#include <stdio.h> #include <stdlib.h> #include <string.h> -#include <ctype.h> #include <errno.h> #include "../perf.h"
tools/perf/util/ui/browsers/map.c +1 -1
@@ -3,9 +3,9 @@#include <newt.h> #include <inttypes.h> #include <sys/ttydefaults.h> -#include <ctype.h> #include <string.h> #include <linux/bitops.h> +#include "../../util.h" #include "../../debug.h" #include "../../symbol.h" #include "../browser.h"
Signature · 1 line
1.7.8.2
PATCH 5/5 perf lock: Document lock info subcommand
In reply to Namhyung KimThe commit 26242d859c9be ("perf lock: Add "info" subcommand for dumping misc information") added the subcommand but missed documentation. Add it. Also update stale 'trace' subcommand to 'script'.
--- tools/perf/Documentation/perf-lock.txt | 20 +++++++++++++++++--- tools/perf/builtin-lock.c | 4 ++-- 2 files changed, 19 insertions(+), 5 deletions(-)
tools/perf/Documentation/perf-lock.txt +17 -3
@@ -8,7 +8,7 @@ perf-lock - Analyze lock events SYNOPSIS -------- [verse] -'perf lock' {record|report|trace} +'perf lock' {record|report|script|info} DESCRIPTION -----------
@@ -20,10 +20,13 @@ and statistics with this 'perf lock' command. produces the file "perf.data" which contains tracing results of lock events. - 'perf lock trace' shows raw lock events. - 'perf lock report' reports statistical data. + 'perf lock script' shows raw lock events. + + 'perf lock info' shows metadata like threads or addresses + of lock instances. + COMMON OPTIONS --------------
@@ -47,6 +50,17 @@ REPORT OPTIONS Sorting key. Possible values: acquired (default), contended, wait_total, wait_max, wait_min. +INFO OPTIONS +------------ + +-t:: +--threads:: + dump thread list in perf.data + +-m:: +--map:: + dump map of lock instances (address:name table) + SEE ALSO -------- linkperf:perf[1]
tools/perf/builtin-lock.c +2 -2
@@ -922,12 +922,12 @@ static const struct option info_options[] = {OPT_BOOLEAN ('t' ,"threads" , &info_threads,"dump thread list in perf.data" ),OPT_BOOLEAN ('m' ,"map" , &info_map, -"map of lock instances (name:address table)" ), +"map of lock instances (address:name table)" ), OPT_END() };static const char *const lock_usage[] = { -"perf lock [<options>] {record|trace|report}" , +"perf lock [<options>] {record|report|script|info}" ,NULL };
Signature · 1 line
1.7.8.2
Re: [PATCH 2/5] perf record: Add error message for EMFILE
In reply to Namhyung KimQuoted 13 lines · Namhyung Kim
When a user tries to open so many events,
perf_event_oensyscall may fail with EMFILE. Provide an advice for that case.Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/builtin-record.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)tools/perf/builtin-record.c +0
-0
tools/perf/builtin-record.c try_again: · line 258
Quoted 10 lines
tools/perf/builtin-record.c +4
-0@@ -249,6 +249,10 @@ try_again:ui__warning ("The %s event is not supported.\n" ,event_name (pos));exit (EXIT_FAILURE ); + }else if (err ==EMFILE ) { +ui__warning ("Too many events are opened.\n" +"Try again after reducing the number of events.\n" ); +exit (EXIT_FAILURE ); }printf ("\n" );
It's not just the number of events: an fd is opened for each specified event on each specified cpu and for each specified task. See __perf_evsel__open(). e.g., the new --uid option on a 16 cpu server can hit the limit pretty fast.
David
Re: [PATCH 2/5] perf record: Add error message for EMFILE
Hello,
Quoted 23 lines · David Ahern
Quoted 22 lines · Namhyung Kim
When a user tries to open so many events,
perf_event_oensyscall may fail with EMFILE. Provide an advice for that case.Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/builtin-record.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)tools/perf/builtin-record.c +4
-0@@ -249,6 +249,10 @@ try_again:ui__warning ("The %s event is not supported.\n" ,event_name (pos));exit (EXIT_FAILURE ); + }else if (err ==EMFILE ) { +ui__warning ("Too many events are opened.\n" +"Try again after reducing the number of events.\n" ); +exit (EXIT_FAILURE ); }
Quoted 8 lines
tools/perf/builtin-record.c try_again: · line 258
Quoted 1 line
tools/perf/builtin-record.c +0
-0printf ("\n" );It's not just the number of events: an fd is opened for each specified event on each specified cpu and for each specified task. See
__perf_evsel__open(). e.g., the new --uid option on a 16 cpu server can hit the limit pretty fast.David
Right. How about this then? If it looks OK to you, I'll resend the patch for record, top, stat:
Too many events are opened.
Try again after reducing the number of events, tasks and/or cpus.
Thanks,
Namhyung
Em Sun, Jan 29, 2012 at 05:55:52PM +0900, Namhyung Kim escreveu:
Quoted 8 lines
If multiple events are specified on old kernel,
perf_evlist__id2evsel()returns NULL for non-sampling events since the sample.id doesn't contain valid value, and it triggers assert below. If only one event is given, the function returns the evsel regardless of sample.id, this is why most case cause no problem on old kernel.Fix it by using active evsel.
How about this one instead:
tools/perf/util/evlist.c +4 -0
@@ -349,6 +349,10 @@ struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id)hlist_for_each_entry (sid, pos, head, node)if (sid->id == id)return sid->evsel; + +if (!perf_evlist__sample_id_all (evlist)) + return list_entry(evlist->entries.next, struct perf_evsel, node); +return NULL ; }
That way we won't have to patch other tools that would get the same problem in such new tool/old kernel combos, right?
Do you see any problem with not checking the header type?
Also please try to avoid using perf_session fields, prefer to use perf_{evlist,evsel} when possible, in this case you could use perf_evlist__sample_id_all(evlist), for instance.
- Arnaldo
Quoted 26 lines
Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/builtin-top.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)tools/perf/builtin-top.c +8
-0@@ -771,6 +771,14 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx) } evsel =perf_evlist__id2evsel (session->evlist, sample.id); +if (evsel ==NULL && !session->sample_id_all && + event->header.type !=PERF_RECORD_SAMPLE ) { +/* +* Old kernel, no sample_id_all field. +* Just use active evsel. +*/ + evsel = top->sym_evsel; + }assert (evsel !=NULL ); origin = event->header.misc &PERF_RECORD_MISC_CPUMODE_MASK ;Signature · 1 line
1.7.8.2
Re: [PATCH 2/5] perf record: Add error message for EMFILE
In reply to a message not in the archiveEm Sun, Jan 29, 2012 at 07:10:08PM -0700, David Ahern escreveu:
Quoted 11 lines · Namhyung Kim
Quoted 2 lines
2012-01-30 12:28 AM, David Ahern wrote:
Right. How about this then? If it looks OK to you, I'll resend the patchfor record, top, stat:
Quoted 5 lines
Too many events are opened.
Try again after reducing the number of events, tasks and/or cpus.Looks ok to me.
Ok, waiting for the resend,
- Arnaldo
Quoted 27 lines · Arnaldo Carvalho de Melo
Em Sun, Jan 29, 2012 at 05:55:52PM +0900, Namhyung Kim escreveu:
Quoted 8 lines
If multiple events are specified on old kernel,
perf_evlist__id2evsel()returns NULL for non-sampling events since the sample.id doesn't contain valid value, and it triggers assert below. If only one event is given, the function returns the evsel regardless of sample.id, this is why most case cause no problem on old kernel.Fix it by using active evsel.
How about this one instead:
tools/perf/util/evlist.c +4
-0@@ -349,6 +349,10 @@ struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id)hlist_for_each_entry (sid, pos, head, node)if (sid->id == id)return sid->evsel; + +if (!perf_evlist__sample_id_all (evlist)) + return list_entry(evlist->entries.next, struct perf_evsel, node); +return NULL ; }
Quoted 3 lines
That way we won't have to patch other tools that would get the same problem in such new tool/old kernel combos, right?
Right, looks good to me.
Quoted 2 lines
Do you see any problem with not checking the header type?
No, I don't, at least for now :)
Quoted 6 lines
Also please try to avoid using
perf_sessionfields, prefer to use perf_{evlist,evsel} when possible, in this case you could useperf_evlist__sample_id_all(evlist), for instance.- Arnaldo
OK, will do that later.
Thanks,
Namhyung
Em Tue, Jan 31, 2012 at 09:31:13AM +0900, Namhyung Kim escreveu:
Quoted 28 lines
Quoted 27 lines · Arnaldo Carvalho de Melo
Em Sun, Jan 29, 2012 at 05:55:52PM +0900, Namhyung Kim escreveu:
Quoted 8 lines
If multiple events are specified on old kernel,
perf_evlist__id2evsel()returns NULL for non-sampling events since the sample.id doesn't contain valid value, and it triggers assert below. If only one event is given, the function returns the evsel regardless of sample.id, this is why most case cause no problem on old kernel.Fix it by using active evsel.
How about this one instead:
tools/perf/util/evlist.c +4
-0@@ -349,6 +349,10 @@ struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id)hlist_for_each_entry (sid, pos, head, node)if (sid->id == id)return sid->evsel; + +if (!perf_evlist__sample_id_all (evlist)) + return list_entry(evlist->entries.next, struct perf_evsel, node); +return NULL ; }
Quoted 5 lines
Quoted 3 lines
That way we won't have to patch other tools that would get the same problem in such new tool/old kernel combos, right?
Right, looks good to me.
Please resend that way and I'll apply, or lemme know if you prefer for me to do it and just stick your 'Acked-by: ' or 'Tested-by:' on it.
Quoted 18 lines
Quoted 3 lines
Do you see any problem with not checking the header type?
No, I don't, at least for now :)
Quoted 6 lines
Also please try to avoid using
perf_sessionfields, prefer to use perf_{evlist,evsel} when possible, in this case you could useperf_evlist__sample_id_all(evlist), for instance.- Arnaldo
OK, will do that later.
Thanks,
Namhyung
[tip:perf/core] perf lock: Document lock info subcommand
In reply to Namhyung KimCommit-ID: d1eec3ecaef083affaf3210246b01b6e80d3a44e Gitweb: http://git.kernel.org/tip/d1eec3ecaef083affaf3210246b01b6e80d3a44e Author: Namhyung Kim <[email protected]> AuthorDate: Sun, 29 Jan 2012 17:55:56 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 30 Jan 2012 18:30:48 -0200
perf lock: Document lock info subcommand
The commit 26242d859c9be ("perf lock: Add "info" subcommand for dumping misc information") added the subcommand but missed documentation. Add it. Also update stale 'trace' subcommand to 'script'.
--- tools/perf/Documentation/perf-lock.txt | 20 +++++++++++++++++--- tools/perf/builtin-lock.c | 4 ++-- 2 files changed, 19 insertions(+), 5 deletions(-)
tools/perf/Documentation/perf-lock.txt +17 -3
@@ -8,7 +8,7 @@ perf-lock - Analyze lock events SYNOPSIS -------- [verse] -'perf lock' {record|report|trace} +'perf lock' {record|report|script|info} DESCRIPTION -----------
@@ -20,10 +20,13 @@ and statistics with this 'perf lock' command. produces the file "perf.data" which contains tracing results of lock events. - 'perf lock trace' shows raw lock events. - 'perf lock report' reports statistical data. + 'perf lock script' shows raw lock events. + + 'perf lock info' shows metadata like threads or addresses + of lock instances. + COMMON OPTIONS --------------
@@ -47,6 +50,17 @@ REPORT OPTIONS Sorting key. Possible values: acquired (default), contended, wait_total, wait_max, wait_min. +INFO OPTIONS +------------ + +-t:: +--threads:: + dump thread list in perf.data + +-m:: +--map:: + dump map of lock instances (address:name table) + SEE ALSO -------- linkperf:perf[1]
tools/perf/builtin-lock.c +2 -2
@@ -922,12 +922,12 @@ static const struct option info_options[] = {OPT_BOOLEAN ('t' ,"threads" , &info_threads,"dump thread list in perf.data" ),OPT_BOOLEAN ('m' ,"map" , &info_map, -"map of lock instances (name:address table)" ), +"map of lock instances (address:name table)" ), OPT_END() };static const char *const lock_usage[] = { -"perf lock [<options>] {record|trace|report}" , +"perf lock [<options>] {record|report|script|info}" ,NULL };
[tip:perf/core] perf tools: Remove unnecessary ctype.h inclusion
In reply to Namhyung KimCommit-ID: d30d4a080d195892091ad7d014fc9293cc08ea0f Gitweb: http://git.kernel.org/tip/d30d4a080d195892091ad7d014fc9293cc08ea0f Author: Namhyung Kim <[email protected]> AuthorDate: Sun, 29 Jan 2012 17:55:55 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 30 Jan 2012 18:37:35 -0200
perf tools: Remove unnecessary ctype.h inclusion
There are unnecessary #include <ctype.h> out there, and they might cause a nasty build failure in some environment. As we already have most of ctype macros in util.h, just get rid of them.
A few of exceptions are util/symbol.c which needs isupper() macro util.h doesn't provide and perl scripting support code which includes ctype.h internally.
--- tools/perf/bench/mem-memcpy.c | 1 - tools/perf/bench/mem-memset.c | 1 - tools/perf/util/probe-finder.c | 1 - .../util/scripting-engines/trace-event-python.c | 1 - tools/perf/util/trace-event-parse.c | 1 - tools/perf/util/trace-event-read.c | 1 - tools/perf/util/trace-event-scripting.c | 1 - tools/perf/util/ui/browsers/map.c | 2 +- 8 files changed, 1 insertions(+), 8 deletions(-)
tools/perf/bench/mem-memcpy.c +0 -1
@@ -5,7 +5,6 @@* * Written by Hitoshi Mitake <[email protected]> */ -#include <ctype.h> #include "../perf.h" #include "../util/util.h"
tools/perf/bench/mem-memset.c +0 -1
@@ -5,7 +5,6 @@* * Trivial clone of mem-memcpy.c. */ -#include <ctype.h> #include "../perf.h" #include "../util/util.h"
tools/perf/util/probe-finder.c +0 -1
@@ -30,7 +30,6 @@#include <stdlib.h> #include <string.h> #include <stdarg.h> -#include <ctype.h> #include <dwarf-regs.h> #include <linux/bitops.h>
tools/perf/util/scripting-engines/trace-event-python.c +0 -1
@@ -24,7 +24,6 @@#include <stdio.h> #include <stdlib.h> #include <string.h> -#include <ctype.h> #include <errno.h> #include "../../perf.h"
tools/perf/util/trace-event-parse.c +0 -1
@@ -25,7 +25,6 @@#include <stdio.h> #include <stdlib.h> #include <string.h> -#include <ctype.h> #include <errno.h> #include "../perf.h"
tools/perf/util/trace-event-read.c +0 -1
@@ -33,7 +33,6 @@#include <pthread.h> #include <fcntl.h> #include <unistd.h> -#include <ctype.h> #include <errno.h> #include "../perf.h"
tools/perf/util/trace-event-scripting.c +0 -1
@@ -22,7 +22,6 @@#include <stdio.h> #include <stdlib.h> #include <string.h> -#include <ctype.h> #include <errno.h> #include "../perf.h"
tools/perf/util/ui/browsers/map.c +1 -1
@@ -3,9 +3,9 @@#include <newt.h> #include <inttypes.h> #include <sys/ttydefaults.h> -#include <ctype.h> #include <string.h> #include <linux/bitops.h> +#include "../../util.h" #include "../../debug.h" #include "../../symbol.h" #include "../browser.h"