当前位置: 首页> 科技> 名企 > 帝国cms使用教程_百度投放广告流程_网球排名即时最新排名_十大中文网站排名

帝国cms使用教程_百度投放广告流程_网球排名即时最新排名_十大中文网站排名

时间:2025/7/12 2:49:58来源:https://blog.csdn.net/Long_xu/article/details/144592426 浏览次数:0次
帝国cms使用教程_百度投放广告流程_网球排名即时最新排名_十大中文网站排名

在Windows 11 WSL2 Ubuntu 环境下完整安装和配置perf性能分析工具

  • 一、背景
  • 二、准备工作
  • 三、获取并编译Linux内核源码
  • 四、安装和配置perf
  • 五、测试perf
  • 六、总结

一、背景

由于WSL2使用的是微软定制的内核,并非标准的Ubuntu内核,因此直接使用apt安装linux-tools包会失败。

sudo apt install linux-tools-common linux-tools-generic linux-tools-$(uname -r)

会遇到如下错误:

E: Unable to locate package linux-tools-5.15.167.4-microsoft-standard-WSL2
E: Couldn't find any package by glob 'linux-tools-5.15.167.4-microsoft-standard-WSL2'

这个时候需要手动编译安装内核代码。本文详细介绍如何在Windows 11的WSL2 (Ubuntu 22.04)环境中成功安装并配置perf性能分析工具,一步步从获取内核源码到最终测试perf的完整过程,并提供更全面的依赖库安装方法以确保perf功能完整。

在这里插入图片描述

二、准备工作

  1. 更新WSL2: 在Windows PowerShell中运行以下命令更新WSL2到最新版本:

    wsl --update
    
  2. 安装必要的编译工具和依赖库: 在Ubuntu终端中执行以下命令,安装编译perf所需的工具链和基础依赖库:

    sudo apt update
    sudo apt install -y bc build-essential flex bison git cmake libelf-dev
    

    这里我们预先安装了 cmake ,在后续编译过程中可能会用到,避免了不必要的安装错误。

三、获取并编译Linux内核源码

  1. 确定内核版本: 在Ubuntu终端中运行以下命令获取当前WSL2内核版本:

    uname -r
    

    输出可能类似于

    5.15.167.4-microsoft-standard-WSL2
    

    我们仅提取主版本号,例如 5.15.167.4。注意:这个版本号可能会有变化, 你的实际操作结果跟这里的版本号可能会不同。

  2. 克隆内核源码: 使用Git克隆微软提供的WSL2内核源码。为了提高效率,我们只克隆必要的代码分支:

    # 设置一个环境变量方便引用
    export KERNEL_VERSION=$(uname -r | cut -d'-' -f1)
    git clone --depth 1 --single-branch --branch=linux-msft-wsl-${KERNEL_VERSION} https://github.com/microsoft/WSL2-Linux-Kernel.git
    

    这将克隆指定版本的内核源码到 WSL2-Linux-Kernel 目录。

  3. 编译内核及perf工具: 进入克隆的目录,并使用 make 命令编译内核。为了加快编译速度,可以使用 -j 参数指定并行编译的进程数,例如使用 -j$(nproc) 使用所有可用CPU核心进行并行编译。请注意,此步骤无需root权限。

    cd WSL2-Linux-Kernel
    make KCONFIG_CONFIG=Microsoft/config-wsl -j$(nproc)
    

    这个过程会让你输入y/n,一直输入y就好。例如:

     ** Mitigations for CPU vulnerabilities*Mitigations for CPU vulnerabilities (CPU_MITIGATIONS) [Y/n/?] (NEW) yRemove the kernel mapping in user mode (PAGE_TABLE_ISOLATION) [Y/n/?] yAvoid speculative indirect branches in kernel (RETPOLINE) [Y/n/?] yEnable return-thunks (RETHUNK) [Y/n/?] yEnable UNRET on kernel entry (CPU_UNRET_ENTRY) [Y/n/?] yEnable IBPB on kernel entry (CPU_IBPB_ENTRY) [Y/n/?] yEnable IBRS on kernel entry (CPU_IBRS_ENTRY) [Y/n/?] yMitigate speculative RAS overflow on AMD (CPU_SRSO) [Y/n/?] yMitigate Straight-Line-Speculation (SLS) [N/y/?] nForce GDS Mitigation (GDS_FORCE_MITIGATION) [N/y/?] nRFDS Mitigation (MITIGATION_RFDS) [Y/n/?] (NEW) yMitigate Spectre-BHB (Branch History Injection) (MITIGATION_SPECTRE_BHI) [Y/n/?] (NEW) y** Core Netfilter Configuration*
    
  4. 编译完成后,进入 tools/perf 目录,编译perf工具:

    cd tools/perf
    make
    

四、安装和配置perf

  1. 安装perf: 编译完成后,使用以下命令将 perf 可执行文件复制到系统目录:

    sudo cp perf /usr/bin/
    
  2. 安装全功能perf的依赖库: 为了确保perf拥有全部功能,需要安装额外的依赖库。这步比之前的例子更全面,涵盖更多:

    sudo apt install binutils-dev dwarves debuginfod default-jdk default-jre libaio-dev libbabeltrace-dev libcap-dev libdw-dev libdwarf-dev libelf-dev libiberty-dev liblzma-dev libnuma-dev libperl-dev libpfm4-dev libslang2-dev libssl-dev libtraceevent-dev libunwind-dev libzstd-dev libzstd1 python3-dev python3-setuptools systemtap-sdt-dev zlib1g-dev
    
  3. 重新编译perf (可选): 安装完所有依赖库后,建议重新编译perf以确保所有功能都被启用。

    make clean && make
    

    编译完成后,再次执行第三章节中的安装命令。编译过程中会显示哪些功能被支持。

五、测试perf

运行以下命令测试perf是否成功安装:

perf --version

如果成功安装,将显示perf的版本信息。

perf version 5.15.167.4.g6ac7abbd97a0
$ perfusage: perf [--version] [--help] [OPTIONS] COMMAND [ARGS]The most commonly used perf commands are:annotate        Read perf.data (created by perf record) and display annotated codearchive         Create archive with object files with build-ids found in perf.data filebench           General framework for benchmark suitesbuildid-cache   Manage build-id cache.buildid-list    List the buildids in a perf.data filec2c             Shared Data C2C/HITM Analyzer.config          Get and set variables in a configuration file.daemon          Run record sessions on backgrounddata            Data file related processingdiff            Read perf.data files and display the differential profileevlist          List the event names in a perf.data fileftrace          simple wrapper for kernel's ftrace functionalityinject          Filter to augment the events stream with additional informationiostat          Show I/O performance metricskallsyms        Searches running kernel for symbolskmem            Tool to trace/measure kernel memory propertieskvm             Tool to trace/measure kvm guest oslist            List all symbolic event typeslock            Analyze lock eventsmem             Profile memory accessesrecord          Run a command and record its profile into perf.datareport          Read perf.data (created by perf record) and display the profilesched           Tool to trace/measure scheduler properties (latencies)script          Read perf.data (created by perf record) and display trace outputstat            Run a command and gather performance counter statisticstest            Runs sanity tests.timechart       Tool to visualize total system behavior during a workloadtop             System profiling tool.version         display the version of perf binaryprobe           Define new dynamic tracepointstrace           strace inspired toolSee 'perf help COMMAND' for more information on a specific command.

六、总结

  • 内核版本号可能因WSL2更新而变化,请根据实际情况修改相应的版本号。
  • 编译内核是一个耗时的过程,请耐心等待。
  • 确保系统具有足够的磁盘空间,内核源码和编译过程会占用大量的磁盘空间。

参考:

  • https://github.com/microsoft/WSL2-Linux-Kernel
  • abel0b/install-linux-perf-on-wsl2.sh, https://gist.github.com/abel0b/b1881e41b9e1c4b16d84e5e083c38a13
  • https://medium.com/@manas.marwah/building-perf-tool-fc838f084f71
    在这里插入图片描述
关键字:帝国cms使用教程_百度投放广告流程_网球排名即时最新排名_十大中文网站排名

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: