树莓派perf执行报错

root@raspberrypi:/home/curtis# perf
/usr/bin/perf: line 13: exec: perf_6.1: not found
E: linux-perf-6.1 is not installed.

从提示信息来看,perf命令去系统中招perf_6.1,但是没有找到该文件,结果发现/usr/bin/perf是一个shell脚本。

root@raspberrypi:/home/curtis# cat /usr/bin/perf
#!/bin/bash

# Execute the right version of perf for the current kernel.
# Remove flavour or custom suffix and fix number of version components to 2.
version="$(uname -r)"
version="${version%%-*}"
case "$version" in
    *.*.*)
        version="${version%.*}"
        ;;
esac
shopt -s execfail
exec "perf_$version" "$@"

# Not found? Tell the user which package to install.
case "$version" in
    3.* | 4.0 | 4.0.*)
        package=linux-tools-$version
        ;;
    *)
        package=linux-perf-$version
        ;;
esac
echo >&2 "E: $package is not installed."
exit 1

使用unmar -r来获取当前内核版本,然后去执行perf_$version,也就是/usr/bin/perf_6.1,原始的raspios没有安装该包。

root@raspberrypi:/home/curtis# uname -r
6.1.35-v8
root@raspberrypi:/home/curtis# lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 11 (bullseye)
Release:        11
Codename:       bullseye

查找适合当前系统的package,从结果来看,当前系统支持的报名为linux-perf-5.10,尝试安装。

root@raspberrypi:/home/curtis# apt-cache search linux-tools
linux-perf-5.10 - Performance analysis tools for Linux 5.10

root@raspberrypi:/home/curtis# apt-get install linux-perf-5.10
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following package was automatically installed and is no longer required:
  libfuse2
Use 'apt autoremove' to remove it.
The following additional packages will be installed:
  libopencsd0
Suggested packages:
  linux-doc-5.10
The following NEW packages will be installed:
  libopencsd0 linux-perf-5.10
0 upgraded, 2 newly installed, 0 to remove and 33 not upgraded.
Need to get 2,094 kB of archives.
After this operation, 5,641 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://security.debian.org/debian-security bullseye-security/main arm64 linux-perf-5.10 arm64 5.10.179-1 [1,929 kB]
Get:2 http://deb.debian.org/debian bullseye/main arm64 libopencsd0 arm64 0.14.4-1 [165 kB]
Fetched 2,094 kB in 1min 24s (25.0 kB/s)
Selecting previously unselected package libopencsd0:arm64.
(Reading database ... 98877 files and directories currently installed.)
Preparing to unpack .../libopencsd0_0.14.4-1_arm64.deb ...
Unpacking libopencsd0:arm64 (0.14.4-1) ...
Selecting previously unselected package linux-perf-5.10.
Preparing to unpack .../linux-perf-5.10_5.10.179-1_arm64.deb ...
Unpacking linux-perf-5.10 (5.10.179-1) ...
Setting up libopencsd0:arm64 (0.14.4-1) ...
Setting up linux-perf-5.10 (5.10.179-1) ...
Processing triggers for man-db (2.9.4-2) ...
Processing triggers for libc-bin (2.31-13+rpt2+rpi1+deb11u5) ...

安装过后执行perf命令仍然报错,问题处在/usr/bin/perf上,需要简单修改下shell脚本,修改perf版本信息为刚才安装pef版本就行。

#!/bin/bash

# Execute the right version of perf for the current kernel.
# Remove flavour or custom suffix and fix number of version components to 2.
#version="$(uname -r)"
#version="${version%%-*}"
#case "$version" in
#    *.*.*)
#       version="${version%.*}"
#       ;;
#esac
version="5.10"
shopt -s execfail
exec "perf_$version" "$@"

# Not found? Tell the user which package to install.
case "$version" in
    3.* | 4.0 | 4.0.*)
        package=linux-tools-$version
        ;;
    *)
        package=linux-perf-$version
        ;;
esac
echo >&2 "E: $package is not installed."
exit 1

修改过后可以正常使用perf工具。

root@raspberrypi:/home/curtis# perf

 usage: perf [--version] [--help] [OPTIONS] COMMAND [ARGS]

 The most commonly used perf commands are:
   annotate        Read perf.data (created by perf record) and display annotated code
   archive         Create archive with object files with build-ids found in perf.data file
   bench           General framework for benchmark suites
   buildid-cache   Manage build-id cache.
   buildid-list    List the buildids in a perf.data file
   c2c             Shared Data C2C/HITM Analyzer.
   config          Get and set variables in a configuration file.
   data            Data file related processing
   diff            Read perf.data files and display the differential profile
   evlist          List the event names in a perf.data file
   ftrace          simple wrapper for kernel's ftrace functionality
   inject          Filter to augment the events stream with additional information
   kallsyms        Searches running kernel for symbols
   kmem            Tool to trace/measure kernel memory properties
   kvm             Tool to trace/measure kvm guest os
   list            List all symbolic event types
   lock            Analyze lock events
   mem             Profile memory accesses
   record          Run a command and record its profile into perf.data
   report          Read perf.data (created by perf record) and display the profile
   sched           Tool to trace/measure scheduler properties (latencies)
   script          Read perf.data (created by perf record) and display trace output
   stat            Run a command and gather performance counter statistics
   test            Runs sanity tests.
   timechart       Tool to visualize total system behavior during a workload
   top             System profiling tool.
   version         display the version of perf binary
   probe           Define new dynamic tracepoints
   trace           strace inspired tool

 See 'perf help COMMAND' for more information on a specific command.

linux - How to use the perf utility on raspbian? - Raspberry Pi Stack Exchange

你可能感兴趣的:(树莓派,linux,运维,服务器)