Perf是Linux内核自带的调试工具,在分析Linux系统的性能的时候,需要用到这个工具。下面从编译和基本使用的角度来了解perf
apt install binutils elfutils libasm1 zlib1g
git clone http://10.3.4.182/arm-embedded/stable-4.4.194-rk3399-linux.git (这里只要是你板子上匹配的内核即可)
git clone https://github.com/brendangregg/FlameGraph.git
cd tools/perf/ && ARCH=arm64 WERROR=0 NO_LIBPERL=1 NO_LIBPYTHON=1 make -f Makefile.perf perf
perf建议在arm上编译,交叉编译容易出问题
echo -1 > /proc/sys/kernel/perf_event_paranoid
echo 0 > /proc/sys/kernel/kptr_restrict
kylin@kylin:~$ ./perf -v perf version 4.4.194.g9ca7d7
./perf top -d 2 -p 528
./perf list
Hardware [Cache] Events: These instrument low-level processor activity based on CPU performance counters. For example, CPU cycles, instructions retired, memory stall cycles, level 2 cache misses, etc. Some will be listed as Hardware Cache Events. Software Events: These are low level events based on kernel counters. For example, CPU migrations, minor faults, major faults, etc. Tracepoint Events: This are kernel-level events based on the ftrace framework. These tracepoints are placed in interesting and logical locations of the kernel, so that higher-level behavior can be easily traced. For example, system calls, TCP events, file system I/O, disk I/O, etc. These are grouped into libraries of tracepoints; eg, "sock:" for socket events, "sched:" for CPU scheduler events. Dynamic Tracing: Software can be dynamically instrumented, creating events in any location. For kernel software, this uses the kprobes framework. For user-level software, uprobes. Timed Profiling: Snapshots can be collected at an arbitrary frequency, using perf record -FHz. This is commonly used for CPU usage profiling, and works by creating custom timed interrupt events.
./perf stat -p 528
./perf record -g -p 528 -o perf.data
./perf report -i perf.data
./perf script -i perf.data | FlameGraph/stackcollapse-perf.pl | FlameGraph/flamegraph.pl > flame.html
perf record -a -g -p 1 perf report -g --tui