There are apparently some counters in Linux perf
like syscall:sys_enter_select
, but on my system perf list
does not show any of them
Evidence that other people do have these counters is here: http://www.brendangregg.com/blog/2014-07-03/perf-counting.html
If I run perf top -e 'syscalls:sys_enter_*'
it says:
Can't open event dir: Permission denied
invalid or unsupported event: 'syscalls:sys_enter_*'
Other event types (the ones in perf list
) work fine.
What do I need to do to access syscall counters in perf
? I'm using Linux kernel and perf version 3.10 on x86_64.
A system call is implemented by a ``software interrupt'' that transfers control to kernel code; in Linux/i386 this is ``interrupt 0x80''. The specific system call being invoked is stored in the EAX register, abd its arguments are held in the other processor registers.
A call to perf_event_open() creates a file descriptor that allows measuring performance information. Each file descriptor corresponds to one event that is measured; these can be grouped together to measure multiple events simultaneously. Events can be enabled and disabled in two ways: via ioctl(2) and via prctl(2).
Syscall parameters are passed in registers rdi, rsi, rdx, r10, r8, r9, which you'll notice is *somewhat* like a function call but with slightly different registers! The return value, normally an integer error code, is returned in rax.
syscall() is a small library function that invokes the system call whose assembly language interface has the specified number with the specified arguments. Employing syscall() is useful, for example, when invoking a system call that has no wrapper function in the C library.
Some perf
counters, including all the syscall
ones, are only available to the root user. sudo perf list
will show all the counters, including syscall
ones assuming the kernel is built with CONFIG_HAVE_SYSCALL_TRACEPOINTS
(see Grisha Levit's answer regarding that).
So, to make perf top -e 'syscalls:sys_enter_*'
work, run it under sudo
--even if you do not need sudo
for other counters like cycles
.
You must have an old version of perf
to go with your crusty old 3.10 kernel.
On a modern system (x86-64 Arch Linux with Linux 4.15.8-1-ARCH, and a matching version of perf
), perf
answers this question for you:
$ perf stat -e 'syscalls:sys_enter_*stat*' ls -l
event syntax error: 'syscalls:sys_enter_*stat*'
\___ can't access trace events
Error: No permissions to read /sys/kernel/debug/tracing/events/syscalls/sys_enter_*stat*
Hint: Try 'sudo mount -o remount,mode=755 /sys/kernel/debug/tracing'
Run 'perf list' for a list of valid events
...
$ ll /sys/kernel/debug/ -d
drwx------ 33 root root 0 Mar 14 00:02 /sys/kernel/debug/
Interesting that you could make it world-readable, similar to how you can put kernel.perf_event_paranoid = 0
and kernel.yama.ptrace_scope = 0
in /etc/sysctl.d/99-local.conf
for convenient debugging / tracing / profiling on a single-user desktop without using root
all the time.
These will be missing if the kernel was not built with CONFIG_HAVE_SYSCALL_TRACEPOINTS
.
You can check like so:
# grep TRACEPOINTS "/boot/config-$(uname -r)"
CONFIG_TRACEPOINTS=y
CONFIG_HAVE_SYSCALL_TRACEPOINTS=y
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With