perf/core improvements and fixes
From: Arnaldo Carvalho de Melo <[email protected]>
Hi Ingo,
Please consider pulling,
- Arnaldo
The following changes since commit 7bfb7e6bdd906f11ee9e751b3fec4f4fc728e818:
perf: Convert kmalloc_node(...GFP_ZERO...) to kzalloc_node() (2013-09-02 08:42:49 +0200)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux tags/perf-core-for-mingo
for you to fetch changes up to 31cd3855c98119cae287b761d8d2e75018714c5d:
perf trace: Tell arg formatters the arg index (2013-09-02 16:40:40 -0300)
----------------------------------------------------------------
perf/core improvements and fixes:
. 'perf trace' arg formatting improvements to allow masking arguments
in syscalls such as futex and open, where the some arguments are ignored and thus should not be printed depending on other args.
. Beautify futex open, openat, open_by_handle_at, lseek and futex syscalls.
. Add dummy software event to use when wanting just to keep receiving
PERF_RECORD_{MMAP,COMM,etc}, add test for it, from Adrian Hunter.
. Fix symbol offset computation for some dsos in 'perf script', from David Ahern.
. Skip unsupported hardware events in 'perf list', from Namhyung Kim.
----------------------------------------------------------------
Adrian Hunter (3):
perf: Add a dummy software event to keep tracking perf tools: Add support for PERF_COUNT_SW_DUMMY perf tests: Add 'keep tracking' test
Arnaldo Carvalho de Melo (5):
perf trace: Allow syscall arg formatters to mask args perf trace: Add beautifier for futex 'operation' parm perf trace: Add beautifier for lseek's whence arg perf trace: Add beautifier for open's flags arg perf trace: Tell arg formatters the arg index
David Ahern (1):
perf tools: Fix symbol offset computation for some dsos
Namhyung Kim (1):
perf list: Skip unsupported events
include/uapi/linux/perf_event.h | 1 + tools/perf/Makefile | 1 + tools/perf/builtin-trace.c | 180 ++++++++++++++++++++++++++++++++++++--- tools/perf/tests/builtin-test.c | 4 + tools/perf/tests/keep-tracking.c | 154 +++++++++++++++++++++++++++++++++ tools/perf/tests/tests.h | 1 + tools/perf/util/evlist.c | 42 ++++++++- tools/perf/util/evlist.h | 5 ++ tools/perf/util/evsel.c | 1 + tools/perf/util/parse-events.c | 45 +++++++++- tools/perf/util/parse-events.l | 1 + tools/perf/util/python.c | 1 + tools/perf/util/session.c | 1 + tools/perf/util/symbol.c | 5 +- 14 files changed, 424 insertions(+), 18 deletions(-) create mode 100644 tools/perf/tests/keep-tracking.c
PATCH 1/10 perf trace: Allow syscall arg formatters to mask args
From: Arnaldo Carvalho de Melo <[email protected]>
The futex syscall ignores some arguments according to the 'operation' arg, so allow arg formatters to mask those.
--- tools/perf/builtin-trace.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-)
tools/perf/builtin-trace.c +22 -11
@@ -15,14 +15,16 @@#include <stdlib.h> #include <sys/mman.h> -static size_t syscall_arg__scnprintf_hex (char *bf,size_t size,unsigned long arg) +static size_t syscall_arg__scnprintf_hex (char *bf,size_t size, +unsigned long arg,u8 *arg_mask__maybe_unused ) {return scnprintf (bf, size,"%#lx" , arg); }#define SCA_HEX syscall_arg__scnprintf_hex -static size_t syscall_arg__scnprintf_mmap_prot (char *bf,size_t size,unsigned long arg) +static size_t syscall_arg__scnprintf_mmap_prot (char *bf,size_t size, +unsigned long arg,u8 *arg_mask__maybe_unused ) {int printed =0 , prot = arg;
@@ -52,7 +54,8 @@ static size_t syscall_arg__scnprintf_mmap_prot(char *bf, size_t size, unsigned l#define SCA_MMAP_PROT syscall_arg__scnprintf_mmap_prot -static size_t syscall_arg__scnprintf_mmap_flags (char *bf,size_t size,unsigned long arg) +static size_t syscall_arg__scnprintf_mmap_flags (char *bf,size_t size, +unsigned long arg,u8 *arg_mask__maybe_unused ) {int printed =0 , flags = arg;
@@ -92,7 +95,8 @@ static size_t syscall_arg__scnprintf_mmap_flags(char *bf, size_t size, unsigned#define SCA_MMAP_FLAGS syscall_arg__scnprintf_mmap_flags -static size_t syscall_arg__scnprintf_madvise_behavior (char *bf,size_t size,unsigned long arg) +static size_t syscall_arg__scnprintf_madvise_behavior (char *bf,size_t size, +unsigned long arg,u8 *arg_mask__maybe_unused ) {int behavior = arg;
@@ -136,7 +140,7 @@ static size_t syscall_arg__scnprintf_madvise_behavior(char *bf, size_t size, uns static struct syscall_fmt { const char *name; const char *alias; - size_t (*arg_scnprintf[6])(char *bf, size_t size, unsigned long arg); + size_t (*arg_scnprintf[6])(char *bf, size_t size, unsigned long arg, u8 *arg_mask); bool errmsg; bool timeout; bool hexret;
@@ -198,7 +202,8 @@ struct syscall {const char *name;bool filtered;struct syscall_fmt *fmt; -size_t (**arg_scnprintf)(char *bf,size_t size,unsigned long arg); +size_t (**arg_scnprintf)(char *bf,size_t size, +unsigned long arg,u8 *args_mask); };static size_t fprintf_duration (unsigned long t,FILE *fp)
@@ -443,17 +448,23 @@ static size_t syscall__scnprintf_args(struct syscall *sc, char *bf, size_t size,if (sc->tp_format !=NULL ) {struct format_field *field; +u8 mask =0 , bit =1 ; + +for (field = sc->tp_format->format.fields->next; field; + field = field->next, ++i, bit <<=1 ) { +if (mask & bit) +continue ; -for (field = sc->tp_format->format.fields->next; field; field = field->next) { printed +=scnprintf (bf + printed, size - printed,"%s%s: " , printed ?", " :"" , field->name); -if (sc->arg_scnprintf && sc->arg_scnprintf[i]) - printed += sc->arg_scnprintf[i](bf + printed, size - printed, args[i]); -else +if (sc->arg_scnprintf && sc->arg_scnprintf[i]) { + printed += sc->arg_scnprintf[i](bf + printed, size - printed, + args[i], &mask); + }else { printed +=scnprintf (bf + printed, size - printed,"%ld" , args[i]); - ++i; + } } }else {while (i <6 ) {
Signature · 1 line
1.8.1.4
PATCH 2/10 perf trace: Add beautifier for futex 'operation' parm
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
That uses the arg mask mechanism just introduced to suppress ignored arguments according to the futex operation.
Based on an initial patch from David Ahern that showed the need for some way to allow args to tell how many further args should be shown.
--- tools/perf/builtin-trace.c | 47 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-)
tools/perf/builtin-trace.c +46 -1
@@ -14,6 +14,7 @@#include <libaudit.h> #include <stdlib.h> #include <sys/mman.h> +#include <linux/futex.h> static size_t syscall_arg__scnprintf_hex (char *bf,size_t size,unsigned long arg,u8 *arg_mask__maybe_unused )
@@ -137,6 +138,49 @@ static size_t syscall_arg__scnprintf_madvise_behavior(char *bf, size_t size,#define SCA_MADV_BHV syscall_arg__scnprintf_madvise_behavior +static size_t syscall_arg__scnprintf_futex_op (char *bf,size_t size,unsigned long arg,u8 *arg_mask) +{ +enum syscall_futex_args { +SCF_UADDR = (1 <<0 ), +SCF_OP = (1 <<1 ), +SCF_VAL = (1 <<2 ), +SCF_TIMEOUT = (1 <<3 ), +SCF_UADDR2 = (1 <<4 ), +SCF_VAL3 = (1 <<5 ), + }; +int op = arg; +int cmd = op &FUTEX_CMD_MASK ; +size_t printed =0 ; + +switch (cmd) { +#define P_FUTEX_OP (n) case FUTEX_##n: printed = scnprintf(bf, size, #n); +P_FUTEX_OP (WAIT ); *arg_mask |=SCF_VAL3 |SCF_UADDR2 ;break ; +P_FUTEX_OP (WAKE ); *arg_mask |=SCF_VAL3 |SCF_UADDR2 |SCF_TIMEOUT ;break ; +P_FUTEX_OP (FD ); *arg_mask |=SCF_VAL3 |SCF_UADDR2 |SCF_TIMEOUT ;break ; +P_FUTEX_OP (REQUEUE ); *arg_mask |=SCF_VAL3 |SCF_TIMEOUT ;break ; +P_FUTEX_OP (CMP_REQUEUE ); *arg_mask |=SCF_TIMEOUT ;break ; +P_FUTEX_OP (CMP_REQUEUE_PI ); *arg_mask |=SCF_TIMEOUT ;break ; +P_FUTEX_OP (WAKE_OP );break ; +P_FUTEX_OP (LOCK_PI ); *arg_mask |=SCF_VAL3 |SCF_UADDR2 |SCF_TIMEOUT ;break ; +P_FUTEX_OP (UNLOCK_PI ); *arg_mask |=SCF_VAL3 |SCF_UADDR2 |SCF_TIMEOUT ;break ; +P_FUTEX_OP (TRYLOCK_PI ); *arg_mask |=SCF_VAL3 |SCF_UADDR2 ;break ; +P_FUTEX_OP (WAIT_BITSET ); *arg_mask |=SCF_UADDR2 ;break ; +P_FUTEX_OP (WAKE_BITSET ); *arg_mask |=SCF_UADDR2 ;break ; +P_FUTEX_OP (WAIT_REQUEUE_PI );break ; +default : printed =scnprintf (bf, size,"%#x" , cmd);break ; + } + +if (op &FUTEX_PRIVATE_FLAG ) + printed +=scnprintf (bf + printed, size - printed,"|PRIV" ); + +if (op &FUTEX_CLOCK_REALTIME ) + printed +=scnprintf (bf + printed, size - printed,"|CLKRT" ); + +return printed; +} + +#define SCA_FUTEX_OP syscall_arg__scnprintf_futex_op + static struct syscall_fmt { const char *name; const char *alias;
@@ -153,7 +197,8 @@ static struct syscall_fmt { { .name = "connect", .errmsg = true, }, { .name = "fstat", .errmsg = true, .alias = "newfstat", }, { .name = "fstatat", .errmsg = true, .alias = "newfstatat", }, - { .name = "futex", .errmsg = true, }, + { .name = "futex", .errmsg = true, + .arg_scnprintf = { [1] = SCA_FUTEX_OP, /* op */ }, }, { .name = "ioctl", .errmsg = true, .arg_scnprintf = { [2] = SCA_HEX, /* arg */ }, }, { .name = "lstat", .errmsg = true, .alias = "newlstat", },
Signature · 1 line
1.8.1.4
PATCH 3/10 perf: Add a dummy software event to keep tracking
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
When an event is disabled the "tracking" events selected by the 'mmap', 'comm' and 'task' bits of struct perf_event_attr, are also disabled. However, the information those events provide is necessary to resolve symbols for when the main event is re-enabled.
The "tracking" events can be kept enabled by putting them on another event, but that requires an event that otherwise does nothing. A new software event PERF_COUNT_SW_DUMMY is added for that purpose.
--- include/uapi/linux/perf_event.h | 1 + 1 file changed, 1 insertion(+)
include/uapi/linux/perf_event.h +1 -0
@@ -109,6 +109,7 @@ enum perf_sw_ids {PERF_COUNT_SW_PAGE_FAULTS_MAJ =6 ,PERF_COUNT_SW_ALIGNMENT_FAULTS =7 ,PERF_COUNT_SW_EMULATION_FAULTS =8 , +PERF_COUNT_SW_DUMMY =9 , PERF_COUNT_SW_MAX, /* non-ABI */ };
Signature · 1 line
1.8.1.4
PATCH 4/10 perf tools: Add support for PERF_COUNT_SW_DUMMY
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Add support for the new dummy software event PERF_COUNT_SW_DUMMY.
--- tools/perf/util/evsel.c | 1 + tools/perf/util/parse-events.c | 4 ++++ tools/perf/util/parse-events.l | 1 + tools/perf/util/python.c | 1 + 4 files changed, 7 insertions(+)
tools/perf/util/evsel.c +1 -0
@@ -323,6 +323,7 @@ const char *perf_evsel__sw_names[PERF_COUNT_SW_MAX] = {"major-faults" ,"alignment-faults" ,"emulation-faults" , + "dummy", };static const char *__perf_evsel__sw_name (u64 config)
tools/perf/util/parse-events.c +4 -0
@@ -108,6 +108,10 @@ static struct event_symbol event_symbols_sw[PERF_COUNT_SW_MAX] = { .symbol = "emulation-faults", .alias = "", }, + [PERF_COUNT_SW_DUMMY] = { + .symbol = "dummy", + .alias = "", + }, };#define __PERF_EVENT_FIELD (config, name) \
tools/perf/util/parse-events.l +1 -0
@@ -145,6 +145,7 @@ context-switches|cs { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW cpu-migrations|migrations { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_MIGRATIONS); } alignment-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_ALIGNMENT_FAULTS); } emulation-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_EMULATION_FAULTS); } +dummy { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_DUMMY); } L1-dcache|l1-d|l1d|L1-data | L1-icache|l1-i|l1i|L1-instruction |
tools/perf/util/python.c +1 -0
@@ -987,6 +987,7 @@ static struct { { "COUNT_SW_PAGE_FAULTS_MAJ", PERF_COUNT_SW_PAGE_FAULTS_MAJ }, { "COUNT_SW_ALIGNMENT_FAULTS", PERF_COUNT_SW_ALIGNMENT_FAULTS }, { "COUNT_SW_EMULATION_FAULTS", PERF_COUNT_SW_EMULATION_FAULTS }, + { "COUNT_SW_DUMMY", PERF_COUNT_SW_DUMMY }, { "SAMPLE_IP", PERF_SAMPLE_IP }, { "SAMPLE_TID", PERF_SAMPLE_TID },
Signature · 1 line
1.8.1.4
PATCH 5/10 perf tests: Add 'keep tracking' test
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Add a test for the newly added PERF_COUNT_SW_DUMMY event. The test checks that tracking events continue when an event is disabled but a dummy software event is not disabled.
--- tools/perf/Makefile | 1 + tools/perf/tests/builtin-test.c | 4 + tools/perf/tests/keep-tracking.c | 154 +++++++++++++++++++++++++++++++++++++++ tools/perf/tests/tests.h | 1 + tools/perf/util/evlist.c | 42 ++++++++++- tools/perf/util/evlist.h | 5 ++ 6 files changed, 205 insertions(+), 2 deletions(-) create mode 100644 tools/perf/tests/keep-tracking.c
tools/perf/Makefile +1 -0
@@ -465,6 +465,7 @@ endif # NO_LIBELF ifndef NO_LIBUNWIND LIB_OBJS += $(OUTPUT)util/unwind.o endif +LIB_OBJS += $(OUTPUT)tests/keep-tracking.o ifndef NO_LIBAUDIT BUILTIN_OBJS += $(OUTPUT)builtin-trace.o
tools/perf/tests/builtin-test.c +4 -0
@@ -108,6 +108,10 @@ static struct test { .func = test__sample_parsing, }, { + .desc = "Test using a dummy software event to keep tracking", + .func = test__keep_tracking, + }, + { .func = NULL, }, };
tools/perf/tests/keep-tracking.c new file +154 -0
154 lines not on this page · raw message
tools/perf/tests/tests.h +1 -0
@@ -38,5 +38,6 @@ int test__sw_clock_freq(void);int test__perf_time_to_tsc (void );int test__code_reading (void );int test__sample_parsing (void ); +int test__keep_tracking (void );#endif /* TESTS_H */
tools/perf/util/evlist.c +40 -2
60 lines not on this page · raw message
tools/perf/util/evlist.h +5 -0
@@ -110,6 +110,11 @@ void perf_evlist__munmap(struct perf_evlist *evlist);void perf_evlist__disable (struct perf_evlist *evlist);void perf_evlist__enable (struct perf_evlist *evlist); +int perf_evlist__disable_event (struct perf_evlist *evlist, +struct perf_evsel *evsel); +int perf_evlist__enable_event (struct perf_evlist *evlist, +struct perf_evsel *evsel); +void perf_evlist__set_selected (struct perf_evlist *evlist,struct perf_evsel *evsel);
Signature · 1 line
1.8.1.4
PATCH 6/10 perf list: Skip unsupported events
In reply to Arnaldo Carvalho de MeloFrom: Namhyung Kim <[email protected]>
Some hardware events might not be supported on a system. Listing those events seems meaningless and confusing to users. Let's skip them.
Before:
$ perf list cache | wc -l 33
After:
$ perf list cache | wc -l 27
--- tools/perf/util/parse-events.c | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-)
tools/perf/util/parse-events.c +39 -2
@@ -15,6 +15,7 @@#define YY_EXTRA_TYPE int#include "parse-events-flex.h" #include "pmu.h" +#include "thread_map.h" #define MAX_NAME_LEN 100
@@ -1076,6 +1077,33 @@ int is_valid_tracepoint(const char *event_string)return 0 ; } +static bool is_event_supported (u8 type,unsigned config) +{ +bool ret = true; +struct perf_evsel *evsel; +struct perf_event_attr attr = { + .type = type, + .config = config, + .disabled =1 , + .exclude_kernel =1 , + }; +struct { +struct thread_map map; +int threads[1 ]; + } tmap = { + .map.nr =1 , + .threads = {0 }, + }; + + evsel =perf_evsel__new (&attr,0 ); +if (evsel) { + ret =perf_evsel__open (evsel,NULL , &tmap.map) >=0 ; +perf_evsel__delete (evsel); + } + +return ret; +} +static void __print_events_type (u8 type,struct event_symbol *syms,unsigned max) {
@@ -1083,14 +1111,16 @@ static void __print_events_type(u8 type, struct event_symbol *syms,unsigned i;for (i =0 ; i < max ; i++, syms++) { +if (!is_event_supported (type, i)) +continue ; +if (strlen (syms->alias))snprintf (name,sizeof (name),"%s OR %s" , syms->symbol, syms->alias);else snprintf (name,sizeof (name),"%s" , syms->symbol); -printf (" %-50s [%s]\n" , name, - event_type_descriptors[type]); +printf (" %-50s [%s]\n" , name, event_type_descriptors[type]); } }
@@ -1119,6 +1149,10 @@ int print_hwcache_events(const char *event_glob, bool name_only)if (event_glob !=NULL && !strglobmatch (name, event_glob))continue ; +if (!is_event_supported (PERF_TYPE_HW_CACHE , + type | (op <<8 ) | (i <<16 ))) +continue ; +if (name_only)printf ("%s " , name);else
@@ -1148,6 +1182,9 @@ static void print_symbol_events(const char *event_glob, unsigned type, (syms->alias && strglobmatch(syms->alias, event_glob)))) continue; +if (!is_event_supported (type, i)) +continue ; +if (name_only) {printf ("%s " , syms->symbol);continue ;
Signature · 1 line
1.8.1.4
PATCH 7/10 perf tools: Fix symbol offset computation for some dsos
In reply to Arnaldo Carvalho de MeloFrom: David Ahern <[email protected]>
For some dsos (e.g., libc, libpthread, kernel modules) the symbol offset is huge. e.g.,
qemu-kvm 17238/17242 [007] 762235.640311:
ffffffff816288a1 __schedule+0x451 ([kernel.kallsyms])
ffffffff81629609 schedule+0x29 ([kernel.kallsyms])
ffffffffa00a6ded kvm_vcpu_block+0xffffffffa00a106d (/lib/modules/3.11.0-rc1+/kernel/arch/x86/kvm/kvm.ko)
ffffffffa00bae6b kvm_arch_vcpu_ioctl_run+0xffffffffa00a118b (/lib/modules/3.11.0-rc1+/kernel/arch/x86/kvm/kvm.ko)
ffffffffa00a4d7a kvm_vcpu_ioctl+0xffffffffa00a141a (/lib/modules/3.11.0-rc1+/kernel/arch/x86/kvm/kvm.ko)
ffffffff811a7bdb do_vfs_ioctl+0x8b ([kernel.kallsyms])
ffffffff811a80c1 sys_ioctl+0x91 ([kernel.kallsyms])
ffffffff81633182 system_call+0x72 ([kernel.kallsyms])
7f882a97af27 __GI___ioctl+0x7f882a891007 (/lib64/libc-2.14.90.so)
100000002 [unknown] ([unknown])It seems to be maps with a non-0 start. Taking that into account the offsets are correct:
qemu-kvm 17238/17242 [007] 762235.640311:
ffffffff816288a1 __schedule+0x451 ([kernel.kallsyms])
ffffffff81629609 schedule+0x29 ([kernel.kallsyms])
ffffffffa00a6ded kvm_vcpu_block+0x6d (/lib/modules/3.11.0-rc1+/kernel/arch/x86/kvm/kvm.ko)
ffffffffa00bae6b kvm_arch_vcpu_ioctl_run+0x18b (/lib/modules/3.11.0-rc1+/kernel/arch/x86/kvm/kvm.ko)
ffffffffa00a4d7a kvm_vcpu_ioctl+0x41a (/lib/modules/3.11.0-rc1+/kernel/arch/x86/kvm/kvm.ko)
ffffffff811a7bdb do_vfs_ioctl+0x8b ([kernel.kallsyms])
ffffffff811a80c1 sys_ioctl+0x91 ([kernel.kallsyms])
ffffffff81633182 system_call+0x72 ([kernel.kallsyms])
7f882a97af27 __GI___ioctl+0x7 (/lib64/libc-2.14.90.so)
100000002 [unknown] ([unknown])--- tools/perf/util/session.c | 1 + tools/perf/util/symbol.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-)
tools/perf/util/session.c +1 -0
@@ -1513,6 +1513,7 @@ void perf_evsel__print_ip(struct perf_evsel *evsel, union perf_event *event,printf (" " );if (print_symoffset) { al.addr = node->ip; + al.map = node->map;symbol__fprintf_symname_offs (node->sym, &al, stdout); }else symbol__fprintf_symname (node->sym, stdout);
tools/perf/util/symbol.c +4 -1
@@ -259,7 +259,10 @@ size_t symbol__fprintf_symname_offs(const struct symbol *sym,if (sym && sym->name) { length =fprintf (fp,"%s" , sym->name);if (al) { - offset = al->addr - sym->start; +if (al->addr < sym->end) + offset = al->addr - sym->start; +else + offset = al->addr - al->map->start - sym->start; length +=fprintf (fp,"+0x%lx" , offset); }return length;
Signature · 1 line
1.8.1.4
PATCH 8/10 perf trace: Add beautifier for lseek's whence arg
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
[root@zoo ~]# perf trace -a -e lseek | head -1
546.922 ( 0.004 ms): 1184 lseek(fd: 26, offset: 0, whence: CUR) = 2
[root@zoo ~]#
--- tools/perf/builtin-trace.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
tools/perf/builtin-trace.c +27 -0
@@ -24,6 +24,31 @@ static size_t syscall_arg__scnprintf_hex(char *bf, size_t size,#define SCA_HEX syscall_arg__scnprintf_hex +static size_t syscall_arg__scnprintf_whence (char *bf,size_t size, +unsigned long arg,u8 *arg_mask__maybe_unused ) +{ +int whence = arg; + +switch (whence) { +#define P_WHENCE (n) case SEEK_##n: return scnprintf(bf, size, #n) +P_WHENCE (SET ); +P_WHENCE (CUR ); +P_WHENCE (END ); +#ifdef SEEK_DATA +P_WHENCE (DATA ); +#endif +#ifdef SEEK_HOLE +P_WHENCE (HOLE ); +#endif +#undef P_WHENCE +default :break ; + } + +return scnprintf (bf, size,"%#x" , whence); +} + +#define SCA_WHENCE syscall_arg__scnprintf_whence +static size_t syscall_arg__scnprintf_mmap_prot (char *bf,size_t size,unsigned long arg,u8 *arg_mask__maybe_unused ) {
@@ -201,6 +226,8 @@ static struct syscall_fmt { .arg_scnprintf = { [1] = SCA_FUTEX_OP, /* op */ }, }, { .name = "ioctl", .errmsg = true, .arg_scnprintf = { [2] = SCA_HEX, /* arg */ }, }, + { .name = "lseek", .errmsg = true, + .arg_scnprintf = { [2] = SCA_WHENCE, /* whence */ }, }, { .name = "lstat", .errmsg = true, .alias = "newlstat", }, { .name = "madvise", .errmsg = true, .arg_scnprintf = { [0] = SCA_HEX, /* start */
Signature · 1 line
1.8.1.4
PATCH 9/10 perf trace: Add beautifier for open's flags arg
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Suppressing the mode when O_CREAT not present, needs improvements on the arg masking mechanism to be reused in openat, open_by_handle_at, mq_open:
[root@zoo ~]# perf trace -a -e open | grep -v 'flags: RDONLY' | head -5
147.541 ( 0.028 ms): 1188 open(filename: 0x33c17782fb, flags: CLOEXEC ) = 23
229.898 ( 0.020 ms): 2071 open(filename: 0x3d93c80, flags: NOATIME ) = -1 EPERM Operation not permitted
[root@zoo ~]# perf trace -a -e open | grep CREAT
1406.697 ( 0.024 ms): 616 open(filename: 0x7fffc3a0f910, flags: CREAT|TRUNC|WRONLY, mode: 438 ) = -1 ENOENT No such file or directory
2032.770 ( 0.804 ms): 4354 open(filename: 0x7f33ac814368, flags: CREAT|EXCL|RDWR, mode: 384 ) = 115
^C[root@zoo ~]#
--- tools/perf/builtin-trace.c | 59 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-)
tools/perf/builtin-trace.c +58 -1
@@ -206,6 +206,62 @@ static size_t syscall_arg__scnprintf_futex_op(char *bf, size_t size, unsigned lo#define SCA_FUTEX_OP syscall_arg__scnprintf_futex_op +static size_t syscall_arg__scnprintf_open_flags (char *bf,size_t size, +unsigned long arg,u8 *arg_mask) +{ +int printed =0 , flags = arg; + +if (!(flags &O_CREAT )) + *arg_mask |=1 <<2 ;/* Mask the mode parm */ + +if (flags ==0 ) +return scnprintf (bf, size,"RDONLY" ); +#define P_FLAG (n) \ + if (flags & O_##n) { \ + printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \ + flags &= ~O_##n; \ + } + +P_FLAG (APPEND ); +P_FLAG (ASYNC ); +P_FLAG (CLOEXEC ); +P_FLAG (CREAT ); +P_FLAG (DIRECT ); +P_FLAG (DIRECTORY ); +P_FLAG (EXCL ); +P_FLAG (LARGEFILE ); +P_FLAG (NOATIME ); +P_FLAG (NOCTTY ); +#ifdef O_NONBLOCK +P_FLAG (NONBLOCK ); +#elif O_NDELAY +P_FLAG (NDELAY ); +#endif +#ifdef O_PATH +P_FLAG (PATH ); +#endif +P_FLAG (RDWR ); +#ifdef O_DSYNC +if ((flags &O_SYNC ) ==O_SYNC ) + printed +=scnprintf (bf + printed, size - printed,"%s%s" , printed ?"|" :"" ,"SYNC" ); +else { +P_FLAG (DSYNC ); + } +#else +P_FLAG (SYNC ); +#endif +P_FLAG (TRUNC ); +P_FLAG (WRONLY ); +#undef P_FLAG + +if (flags) + printed +=scnprintf (bf + printed, size - printed,"%s%#x" , printed ?"|" :"" , flags); + +return printed; +} + +#define SCA_OPEN_FLAGS syscall_arg__scnprintf_open_flags + static struct syscall_fmt { const char *name; const char *alias;
@@ -244,7 +300,8 @@ static struct syscall_fmt { [4] = SCA_HEX, /* new_addr */ }, }, { .name = "munmap", .errmsg = true, .arg_scnprintf = { [0] = SCA_HEX, /* addr */ }, }, - { .name = "open", .errmsg = true, }, + { .name = "open", .errmsg = true, + .arg_scnprintf = { [1] = SCA_OPEN_FLAGS, /* flags */ }, }, { .name = "poll", .errmsg = true, .timeout = true, }, { .name = "ppoll", .errmsg = true, .timeout = true, }, { .name = "pread", .errmsg = true, .alias = "pread64", },
Signature · 1 line
1.8.1.4
PATCH 10/10 perf trace: Tell arg formatters the arg index
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
... so that it can mask args relative to its position, like the 'mode' arg that may or not be printed according to the 'flags' (O_CREAT) value.
[root@zoo ~]# perf trace -a -e openat,open_by_handle_at | head -1
469.754 ( 0.034 ms): 1183 openat(dfd: -100, filename: 0x7fbde40014b0, flags: CLOEXEC|DIRECTORY|NONBLOCK) = 23
[root@zoo ~]#
--- tools/perf/builtin-trace.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-)
tools/perf/builtin-trace.c +25 -11
@@ -17,7 +17,9 @@#include <linux/futex.h> static size_t syscall_arg__scnprintf_hex (char *bf,size_t size, -unsigned long arg,u8 *arg_mask__maybe_unused ) +unsigned long arg, +u8 arg_idx__maybe_unused , +u8 *arg_mask__maybe_unused ) {return scnprintf (bf, size,"%#lx" , arg); }
@@ -25,7 +27,9 @@ static size_t syscall_arg__scnprintf_hex(char *bf, size_t size,#define SCA_HEX syscall_arg__scnprintf_hexstatic size_t syscall_arg__scnprintf_whence (char *bf,size_t size, -unsigned long arg,u8 *arg_mask__maybe_unused ) +unsigned long arg, +u8 arg_idx__maybe_unused , +u8 *arg_mask__maybe_unused ) {int whence = arg;
@@ -50,7 +54,9 @@ static size_t syscall_arg__scnprintf_whence(char *bf, size_t size,#define SCA_WHENCE syscall_arg__scnprintf_whencestatic size_t syscall_arg__scnprintf_mmap_prot (char *bf,size_t size, -unsigned long arg,u8 *arg_mask__maybe_unused ) +unsigned long arg, +u8 arg_idx__maybe_unused , +u8 *arg_mask__maybe_unused ) {int printed =0 , prot = arg;
@@ -81,7 +87,8 @@ static size_t syscall_arg__scnprintf_mmap_prot(char *bf, size_t size,#define SCA_MMAP_PROT syscall_arg__scnprintf_mmap_protstatic size_t syscall_arg__scnprintf_mmap_flags (char *bf,size_t size, -unsigned long arg,u8 *arg_mask__maybe_unused ) +unsigned long arg,u8 arg_idx__maybe_unused , +u8 *arg_mask__maybe_unused ) {int printed =0 , flags = arg;
@@ -122,7 +129,8 @@ static size_t syscall_arg__scnprintf_mmap_flags(char *bf, size_t size,#define SCA_MMAP_FLAGS syscall_arg__scnprintf_mmap_flagsstatic size_t syscall_arg__scnprintf_madvise_behavior (char *bf,size_t size, -unsigned long arg,u8 *arg_mask__maybe_unused ) +unsigned long arg,u8 arg_idx__maybe_unused , +u8 *arg_mask__maybe_unused ) {int behavior = arg;
@@ -163,7 +171,8 @@ static size_t syscall_arg__scnprintf_madvise_behavior(char *bf, size_t size,#define SCA_MADV_BHV syscall_arg__scnprintf_madvise_behavior -static size_t syscall_arg__scnprintf_futex_op (char *bf,size_t size,unsigned long arg,u8 *arg_mask) +static size_t syscall_arg__scnprintf_futex_op (char *bf,size_t size,unsigned long arg, +u8 arg_idx__maybe_unused ,u8 *arg_mask) {enum syscall_futex_args {SCF_UADDR = (1 <<0 ),
@@ -207,12 +216,13 @@ static size_t syscall_arg__scnprintf_futex_op(char *bf, size_t size, unsigned lo#define SCA_FUTEX_OP syscall_arg__scnprintf_futex_opstatic size_t syscall_arg__scnprintf_open_flags (char *bf,size_t size, -unsigned long arg,u8 *arg_mask) +unsigned long arg, +u8 arg_idx,u8 *arg_mask) {int printed =0 , flags = arg;if (!(flags &O_CREAT )) - *arg_mask |=1 <<2 ;/* Mask the mode parm */ + *arg_mask |=1 << (arg_idx +1 );/* Mask the mode parm */ if (flags ==0 )return scnprintf (bf, size,"RDONLY" );
@@ -265,7 +275,7 @@ static size_t syscall_arg__scnprintf_open_flags(char *bf, size_t size, static struct syscall_fmt { const char *name; const char *alias; - size_t (*arg_scnprintf[6])(char *bf, size_t size, unsigned long arg, u8 *arg_mask); + size_t (*arg_scnprintf[6])(char *bf, size_t size, unsigned long arg, u8 arg_idx, u8 *arg_mask); bool errmsg; bool timeout; bool hexret;
@@ -302,6 +312,10 @@ static struct syscall_fmt { .arg_scnprintf = { [0] = SCA_HEX, /* addr */ }, }, { .name = "open", .errmsg = true, .arg_scnprintf = { [1] = SCA_OPEN_FLAGS, /* flags */ }, }, + { .name = "open_by_handle_at", .errmsg = true, + .arg_scnprintf = { [2] = SCA_OPEN_FLAGS, /* flags */ }, }, + { .name = "openat", .errmsg = true, + .arg_scnprintf = { [2] = SCA_OPEN_FLAGS, /* flags */ }, }, { .name = "poll", .errmsg = true, .timeout = true, }, { .name = "ppoll", .errmsg = true, .timeout = true, }, { .name = "pread", .errmsg = true, .alias = "pread64", },
@@ -332,7 +346,7 @@ struct syscall {bool filtered;struct syscall_fmt *fmt;size_t (**arg_scnprintf)(char *bf,size_t size, -unsigned long arg,u8 *args_mask); +unsigned long arg,u8 arg_idx,u8 *args_mask); };static size_t fprintf_duration (unsigned long t,FILE *fp)
@@ -589,7 +603,7 @@ static size_t syscall__scnprintf_args(struct syscall *sc, char *bf, size_t size,if (sc->arg_scnprintf && sc->arg_scnprintf[i]) { printed += sc->arg_scnprintf[i](bf + printed, size - printed, - args[i], &mask); + args[i], i, &mask); }else { printed +=scnprintf (bf + printed, size - printed,"%ld" , args[i]);
Signature · 1 line
1.8.1.4
Quoted 57 lines · Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <[email protected]>
Hi Ingo,
Please consider pulling,
- Arnaldo
The following changes since commit
7bfb7e6bdd906f11ee9e751b3fec4f4fc728e818:perf: Convert
kmalloc_node(...GFP_ZERO...)tokzalloc_node()(2013-09-02 08:42:49 +0200)are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linuxtags/perf-core-for-mingofor you to fetch changes up to
31cd3855c98119cae287b761d8d2e75018714c5d:perf trace: Tell arg formatters the arg index (2013-09-02 16:40:40 -0300)
----------------------------------------------------------------
perf/core improvements and fixes:. 'perf trace' arg formatting improvements to allow masking arguments
in syscalls such as futex and open, where the some arguments are ignored and thus should not be printed depending on other args.. Beautify futex open, openat,
open_by_handle_at, lseek and futex syscalls.. Add dummy software event to use when wanting just to keep receiving
PERF_RECORD_{MMAP,COMM,etc}, add test for it, from Adrian Hunter.. Fix symbol offset computation for some dsos in 'perf script', from David Ahern.
. Skip unsupported hardware events in 'perf list', from Namhyung Kim.
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>----------------------------------------------------------------
Adrian Hunter (3):
perf: Add a dummy software event to keep tracking perf tools: Add support forPERF_COUNT_SW_DUMMYperf tests: Add 'keep tracking' testArnaldo Carvalho de Melo (5):
perf trace: Allow syscall arg formatters to mask args perf trace: Add beautifier for futex 'operation' parm perf trace: Add beautifier for lseek's whence arg perf trace: Add beautifier for open's flags arg perf trace: Tell arg formatters the arg indexDavid Ahern (1):
perf tools: Fix symbol offset computation for some dsosNamhyung Kim (1):
perf list: Skip unsupported events
Quoted 16 lines
include/uapi/linux/perf_event.h | 1 + tools/perf/Makefile | 1 + tools/perf/builtin-trace.c | 180 ++++++++++++++++++++++++++++++++++++--- tools/perf/tests/builtin-test.c | 4 + tools/perf/tests/keep-tracking.c | 154 +++++++++++++++++++++++++++++++++ tools/perf/tests/tests.h | 1 + tools/perf/util/evlist.c | 42 ++++++++- tools/perf/util/evlist.h | 5 ++ tools/perf/util/evsel.c | 1 + tools/perf/util/parse-events.c | 45 +++++++++- tools/perf/util/parse-events.l | 1 + tools/perf/util/python.c | 1 + tools/perf/util/session.c | 1 + tools/perf/util/symbol.c | 5 +- 14 files changed, 424 insertions(+), 18 deletions(-) create mode 100644 tools/perf/tests/keep-tracking.c
Pulled, thanks Arnaldo!
Ingo