| Server IP : 104.21.93.65 / Your IP : 104.23.197.32 Web Server : Apache System : Linux server.localhost.com 6.8.0-85-generic #85-Ubuntu SMP PREEMPT_DYNAMIC Thu Sep 18 15:26:59 UTC 2025 x86_64 User : pahana ( 1029) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /lib/python3/dist-packages/perf/ |
Upload File : |
import os
import importlib.util
from glob import glob
class KernelNotFoundError(Exception):
def __init__(self):
kernel_version = os.uname().release
flavor = kernel_version.split("-", 2)[2]
super().__init__(
f"\nWARNING: python perf module not found for kernel {kernel_version}\n\n"
f" You may need to install the following package for this specific kernel:\n"
f" linux-tools-{kernel_version}\n\n"
f" You may also want to install the following package to keep up to date:\n"
f" linux-tools-{flavor}"
)
# Load the actual python-perf module for the running kernel
_kernel_version = os.uname().release
_perf_dir = f"/usr/lib/linux-tools/{_kernel_version}/lib"
if not os.path.exists(_perf_dir):
_abi_version = "-".join(_kernel_version.split("-")[0:2])
_perf_dir = f"/usr/lib/python3/dist-packages/linux-tools-{_abi_version}"
if not os.path.exists(_perf_dir):
raise KernelNotFoundError()
_perf_lib = glob(os.path.join(_perf_dir, "perf.*.so"))[-1]
_spec = importlib.util.spec_from_file_location("perf", _perf_lib)
_perf = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(_perf)
# Expose the 'perf' module.
__all__ = ["perf"]