日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

如何使用oprofile对软件做profiling

發布時間:2023/12/15 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 如何使用oprofile对软件做profiling 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.


排行榜?收藏?打印?發給朋友?舉報發布者:jackzhang 熱度112票??瀏覽1257次 【共0條評論】【我要評論】時間:2014年1月08日 11:04

關于Xilinx Zynq-7000帶來的新的系統設計思路,以及Profiling的對象libjpeg,前文已經描述過了,再此不再贅述。

?

?

一. Oprofile簡介

?

Profiling是對不同性能特征的數據的形式化總結或分析,它通常以圖形和表的形式出現。它提供為特定的處理器事件收集的采樣百分數或數量,比如cache miss rate、TLB miss rate等等。一般來說,主要目的是為了找出軟件中的性能瓶頸,然后有針對性的優化以提升軟件的整體性能。

?

Oprofile 是用于 Linux 的若干種評測和性能監控工具中的一種。它可以工作在不同的體系結構上,包括ARM, PowerPC, MIPS, IA32, IA64 和 AMD Athlon等等。它的開銷很小,從Linux 2.6 版起,它被包含進了Linux內核中。

?

Oprofile可以收集有關處理器事件的信息,幫助用戶識別諸如循環的展開、cache的使用率低、低效的類型轉換和冗余操作、錯誤預測轉移等問題。Oprofile是一種細粒度的工具,可以為指令集或者為函數、系統調用或中斷處理例程收集采樣。Oprofile 通過取樣來工作。使用收集到的評測數據,用戶可以很容易地找出性能問題。

?

通過監察CPU的hardware events,oprofile可以在運行狀態下對整個Linux系統進行profiling。Profiling的對象可以是Linux kernel (包括modules和interrupt handlers), shared libraries或者應用程序。

?

從0.9.8版本開始,oprofile支持Perf_events profiling mode模式。應用程序operf被用來控制profiling過程;而在legacy mode下,是通過opcontrol腳本和oprofiled daemon來完成的。Operf不再象legacy mode那樣需要OProfile kernel driver,它直接和Linux Kernel Performance Events Subsystem打交道。使用operf,就可以用普通用戶的身份來profiling用戶的應用程序了,當然如果需要對整個系統來profiling的時候還是需要root權限的。

?

如果硬件不支持OProfile使用performance counters,OProfile就只能工作在Timer Mode下了。Timer Mode只能在legacy profiling mode下使用,即只能通過opcontrol腳本來控制。

?

Oprofile的website為:http://oprofile.sourceforge.net/

可以支持的處理器的hardware event類型:http://oprofile.sourceforge.net/docs/

對于Zynq-7000來說,http://oprofile.sourceforge.net/docs/armv7-ca9-events.php?列出了ARM Cortex-A9內核PMU(Performance Monitor Unit)所支持的所有hardware event種類,可以看出oprofile可以支持很多深入處理器內部的分析。

?

http://oprofile.sourceforge.net/examples/?提供了一些oprofile生成的結果,可以方便開發者在開始使用之前了解oprofile能夠做到哪些事情。

?

Oprofile的詳細使用文檔:http://oprofile.sourceforge.net/doc/index.html

?

Oprofile的優勢:

??? 比較低的運行開銷

??? 對被profiling的對象影響很小

??? 可以profiling中斷服務程序(interrupt handlers)

??? 可以profiling應用程序和shared libraries

??? 可以profiling dynamically compiled (JIT) code

??? 可以對整個系統做profiling

??? 可以觀察CPU內部的細節,例如cache miss rate

??? 可以多源代碼做annotation

??? 可以支持instruction-level的profiling

??? 可以生成call-graph profiles

?

不過OProfile也不是萬能的,它也有自己的局限性:

??? 只能在x86, ARM, 和PowerPC架構上生成call graph profiles

??? 不支持100%精確的instruction-level profiling

??? 對dynamically compiled (JIT) code profiling的支持還不完善。

?

無論如何,Oprofile的功能都比gprof要強很多,代價是配置起來會比較麻煩。

?

?

二. 編譯Oprofile

?

首先最好在Linux kernel里面選中Oprofile driver,以獲得全面的支持。

?

下載Linux kernel Source:從https://github.com/Xilinx/linux-xlnx?可以下載到Xilinx提供的驗證好的內核。如果不方便使用Linux下的git工具,可以單擊頁面上的releases找到相應的版本下載tar ball。下載的時候最好選tar.gz格式的,而不是zip格式的,因為后者在處理symbol link的時候有可能會出問題。

?

因為筆者使用的是Xilinx Linux pre-built 14.7,所以這里下載的是linux-xlnx-xilinx-v14.7.tar.gz

?

解壓縮后,用以下命令調出Linux kernel的配置界面:

export ARCH=arm

export CROSS_COMPILE=arm-xilinx-linux-gnueabi-

make xilinx_zynq_defconfig

make xconfig 或者make menuconfig

?

在配置界面上將以下兩項勾上:

General setup --->

[*] Profiling support

<*> OProfile system profiling

?

然后make uImage即可生成新的uImage,用來替換Xilinx Linux pre-built 14.7中的Linux kernel image。同時我們也需要vmlinux來檢查profiling的結果。

?

?

Oprofile需要popt, bfd, liberty庫,要在嵌入式單板上使用這些庫,需要手工完成交叉編譯。

?

針對popt 1.7,用以下命令完成編譯:

./configure --prefix=/home/wave/xilinx/oprofileprj/rootfs --host=arm-xilinx-linux-gnueabi --with-kernel-support --disable-nls && make && make install

?

針對binutils 2.24,用以下命令完成編譯:

./configure --host=arm-xilinx-linux-gnueabi --prefix=/home/wave/xilinx/oprofileprj/rootfs --enable-install-libbfd --enable-install-libiberty? --enable-shared && make && make install

不過--enable-install-libiberty沒有效果,所以需要手工把libiberty.a和libiberty.h拷貝到相應的位置。

?

針對oprofile 0.9.9,用以下命令完成編譯:

./configure --host=arm-xilinx-linux-gnueabi --prefix=/home/wave/xilinx/oprofileprj/rootfs --with-kernel-support? --with-binutils=/home/wave/xilinx/oprofileprj/rootfs && make && make install

配置過程結束后可能會有以下提示,因為沒有打算用GUI和profile JITed code,所以直接忽視之。

config.status: executing libtool commands

Warning: QT version 3 was requested but not found. No GUI will be built.

Warning: The user account 'oprofile:oprofile' does not exist on the system.

???????? To profile JITed code, this special user account must exist.

???????? Please ask your system administrator to add the following user and group:

???????????? user name : 'oprofile'

???????????? group name: 'oprofile'

???????? The 'oprofile' group must be the default group for the 'oprofile' user.

?

將編譯完成的uImage,vmlinux,oprofile binary,重新編譯的沒有-pg的libjpeg binary以及tool chain的libc打包放到SD卡中,準備在ZC706開發板上嘗試profile djpeg。

?

三. 運行Oprofile

?

正常啟動嵌入式Linux后,在開發板的console上一次輸入以下命令:

?

mount /dev/mmcblk0p1 /mnt

?

mkdir -p /home/root/work

cd /home/root/work

tar zxvf /mnt/jpeg-bin-nopg.tar.gz

cd jpeg-bin/bin

cp /mnt/park-2880x1800.jpg .

export LD_LIBRARY_PATH=/home/root/work/jpeg-bin/lib

?

cd /home/root/work

tar zxvf /mnt/rootfs.tar.gz

cd rootfs

chown root:root -R *

cp -R bin/* /usr/bin

cp -R lib/* /lib

cp /bin/which /usr/bin

cp /bin/dirname /usr/bin

mkdir -p /home/wave/xilinx/oprofileprj/rootfs/share

cp -R ./rootfs/* /home/wave/xilinx/oprofileprj/rootfs

?

cd /home/root/work

tar zxvf /mnt/libc.tar.gz

cp ./lib/libstdc*.* /lib

?

mkdir -p /home/wave/xilinx/libjpeg

cd /home/wave/xilinx/libjpeg

tar zxvf /mnt/jpeg-9.tar.gz

?

cp /mnt/vmlinux ?/home/root/work

?

cd /home/root/work/jpeg-bin/bin

?

opcontrol --init

opcontrol --vmlinux=/home/root/work/vmlinux

opcontrol --setup --event=CPU_CYCLES:100000::0:1 --session-dir=/home/root/

?

operf --vmlinux /home/root/work/vmlinux ./djpeg -bmp park-2880x1800.jpg > result.bmp

opreport -l ./djpeg

?

完成這一步后,我們就可以看到profiling的結果了,在筆者的平臺上看到的內容的主要部分如下:

root@zynq:~/work/jpeg-bin/bin# opreport -l ./djpeg

Using /home/root/work/jpeg-bin/bin/oprofile_data/samples/ for samples directory.

CPU: ARM Cortex-A9, speed 666667 MHz (estimated)

Counted CPU_CYCLES events (CPU cycle) with a unit mask of 0x00 (No unit mask) count 100000

samples? %??????? image name?????? ????????symbol name

15293??? 58.6253? libc-2.17.so???????????? /lib/libc-2.17.so

2044 ? ?

總結

以上是生活随笔為你收集整理的如何使用oprofile对软件做profiling的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。