oprofile操作手順課件_第1頁(yè)
oprofile操作手順課件_第2頁(yè)
oprofile操作手順課件_第3頁(yè)
oprofile操作手順課件_第4頁(yè)
oprofile操作手順課件_第5頁(yè)
已閱讀5頁(yè),還剩6頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、435 vi mutiply.c 436 gcc multiply.c -g -o multiply 437 ls 438 mv mutiply.c multiply.c 439 gcc multiply.c -g -o multiply 440 vi multiply.c 441 gcc multiply.c -g -o multiply 442 ls 443 opcontrol -init 444 opcontrol -vmlinux=/usr/src/linux/vmlinux 445 opcontrol -reset 446 opcontrol -start 447 ./multipl

2、y 448 opcontrol -dump 449 opcontrol -start 450 opcontrol deinit 451 opcontrol -deinit 452 echo 0 > /proc/sys/kernel/watchdog 453 opcontrol -init 454 opcontrol -vmlinux=/usr/src/linux/vmlinux 455 opcontrol -reset 456 opcontrol -start 457 ./multiply 458 opcontrol -dump 459 opcontrol -stop 460 opcon

3、trol -shutdown 461 opcontrol -deinit 462 opannotate -source ./multiply 463 opreport -l ./multiply 464 opreport 465 historyrootlocalhost test# gcc multiply.c -g -o multiplyrootlocalhost test# opcontrol -initrootlocalhost test# opcontrol -vmlinux=/usr/src/linux-/vmlinuxThe specified vmlinux fi

4、le "/usr/src/linux-/vmlinux" doesn't exist.rootlocalhost test# opcontrol -vmlinux=/usr/src/linux/vmlinuxrootlocalhost test# opcontrol -resetrootlocalhost test# opcontrol -startATTENTION: Use of opcontrol is discouraged. Please see the man page for operf.Using default event: CPU

5、_CLK_UNHALTED:100000:0:1:1Error: counter 0 not availablerootlocalhost test# opcontrol -deinitrootlocalhost test# echo 0 > /proc/sys/kernel/watchdogrootlocalhost test# opcontrol -initrootlocalhost test# opcontrol -vmlinux=/usr/src/linux/vmlinuxrootlocalhost test# opcontrol -resetrootlocalhost test

6、# opcontrol -startATTENTION: Use of opcontrol is discouraged. Please see the man page for operf.Using default event: CPU_CLK_UNHALTED:100000:0:1:1Using 2.6+ OProfile kernel interface.Reading module info.Using log file /var/lib/oprofile/samples/oprofiled.logDaemon started.Profiler running.rootlocalho

7、st test# ./multiply x=5771, y=5771rootlocalhost test# opcontrol -dumprootlocalhost test# opopannotate op-check-perfevents open openssl operf ophelp opjitconv oprofiled oparchive opcontrol open_init_pty openvt opgprof opimport opreport oprof_start rootlocalhost test# opcontrol -stopStopping profiling

8、.rootlocalhost test# opcontrol -shutdownKilling daemon.rootlocalhost test# opcontrol -deinitrootlocalhost test# opannotate -source ./multiplyUsing /var/lib/oprofile/samples/ for session-dir/* * Command line: opannotate -source ./multiply * * Interpretation of command line: * Output annotated source

9、file with samples * Output all files * * CPU: Intel Sandy Bridge microarchitecture, speed 1800.2 MHz (estimated) * Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000 */* * Total samples for file : "/home/yutingting/test/multiply.c

10、" * * 47 100.000 */ :/*me: multiply.c : * sh# gcc multiply.c -g -o multiply : */ : :#include <stdio.h> :int fast_multiply(x, y) : : return x * y; : : :int slow_multiply(x, y) : /* slow_multiply total: 45 95.7447 */ : int i, j, z; 36 76.5957 : for (i = 0, z = 0; i < x; i+) 8 17.0213 : z

11、 = z + y; 1 2.1277 : return z; : : :int main(int argc, char *argv) : /* main total: 2 4.2553 */ : int i,j; : int x,y; : for (i = 0; i < 200; i +) 1 2.1277 : for (j = 0; j < 30 ; j+) 1 2.1277 : x = fast_multiply(i, j); : y = slow_multiply(i, j); : : : printf("x=%d, y=%dn", x, y); : re

12、turn 0; : :rootlocalhost test# opreport -l ./multiplyUsing /var/lib/oprofile/samples/ for samples directory.CPU: Intel Sandy Bridge microarchitecture, speed 1800.2 MHz (estimated)Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000sample

13、s % symbol name45 95.7447 slow_multiply2 4.2553 mainrootlocalhost test# opreportUsing /var/lib/oprofile/samples/ for samples directory.CPU: Intel Sandy Bridge microarchitecture, speed 1800.2 MHz (estimated)Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No un

14、it mask) count 100000CPU_CLK_UNHALT.| samples| %|- 7749 86.2245 vmlinux 496 5.5191 libc-2.12.so 278 3.0934 bash 127 1.4132 ld-2.12.so 89 0.9903 ext4 51 0.5675 e1000e 47 0.5230 multiply 32 0.3561 oprofiled 31 0.3449 jbd2 31 0.3449 nginxCPU_CLK_UNHALT.| samples| %|- 29 93.5484 nginx 1 3.2258 vdso (tgi

15、d:1335 range:0x7fff9928a000-0x7fff9928b000) 1 3.2258 vdso (tgid:1336 range:0x7fff9928a000-0x7fff9928b000) 13 0.1447 libcrypto.so.1.0.1e 10 0.1113 sshd 8 0.0890 gawk 6 0.0668 cp 4 0.0445 dm_mod 4 0.0445 libahci 3 0.0334 grep 2 0.0223 ls 2 0.0223 libpthread-2.12.so 1 0.0111 cat 1 0.0111 rm 1 0.0111 id

16、 1 0.0111 libgmp.so.3.5.0rootlocalhost test#誰(shuí)動(dòng)了我的cpuoprofile使用札記引言cpu無(wú)端占用高?應(yīng)用程序響應(yīng)慢?苦于沒(méi)有分析的工具?oprofile利用cpu硬件層面提供的性能計(jì)數(shù)器(performance counter),通過(guò)計(jì)數(shù)采樣,幫助我們從進(jìn)程、函數(shù)、代碼層面找出占用cpu的"罪魁禍?zhǔn)?quot;。下面我們通過(guò)實(shí)例,了解oprofile的具體使用方法。 常用命令使用oprofile進(jìn)行cpu使用情況檢測(cè),需要經(jīng)過(guò)初始化、啟動(dòng)檢測(cè)、導(dǎo)出檢測(cè)數(shù)據(jù)、查看檢測(cè)結(jié)果等步驟,以下為常用的oprofile命令。初始化

17、3; opcontrol -no-vmlinux : 指示oprofile啟動(dòng)檢測(cè)后,不記錄內(nèi)核模塊、內(nèi)核代碼相關(guān)統(tǒng)計(jì)數(shù)據(jù)· opcontrol -init : 加載oprofile模塊、oprofile驅(qū)動(dòng)程序檢測(cè)控制· opcontrol -start : 指示oprofile啟動(dòng)檢測(cè)· opcontrol -dump : 指示將oprofile檢測(cè)到的數(shù)據(jù)寫(xiě)入文件· opcontrol -reset : 清空之前檢測(cè)的數(shù)據(jù)記錄· opcontrol -h : 關(guān)閉oprofile

18、進(jìn)程查看檢測(cè)結(jié)果· opreport : 以鏡像(image)的角度顯示檢測(cè)結(jié)果,進(jìn)程、動(dòng)態(tài)庫(kù)、內(nèi)核模塊屬于鏡像范疇· opreport -l : 以函數(shù)的角度顯示檢測(cè)結(jié)果· opreport -l test : 以函數(shù)的角度,針對(duì)test進(jìn)程顯示檢測(cè)結(jié)果· opannotate -s test : 以代碼的角度,針對(duì)test進(jìn)程顯示檢測(cè)結(jié)果· opannotate -s /lib64/libc-2.4.so : 以代碼的角度,針對(duì)libc-2.4.so庫(kù)顯示檢測(cè)結(jié)果 opreport

19、輸出解析正如以上命令解析所言,不加參數(shù)的opreport命令從鏡像的角度顯示cpu的使用情況:linux # opreportCPU: Core 2, speed 2128.07 MHz (estimated)Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (Unhalted core cycles) count 100000CPU_CLK_UNHALT.| samples | %|- 31645719 87.6453 no-vmlinux 4361113 10.35

20、92 libend.so 7683 0.1367 libpython2.4.so.1.0 7046 0.1253 op_test 以上列表按以下形式輸出: samples | %|- 鏡像內(nèi)發(fā)生的采樣次數(shù) 采樣次數(shù)所占總采樣次數(shù)的百分比 鏡像名稱(chēng) 因我們?cè)诔跏蓟瘯r(shí)執(zhí)行了"opcontrol -no-vmlinux"命令,指示oprofile不對(duì)模塊和內(nèi)核進(jìn)行檢測(cè),因而在探測(cè)結(jié)果中,模塊和內(nèi)核一同顯示成no-vmlinux鏡像。輸出中,libend.so和libpython2.4.so.1.0均為動(dòng)態(tài)庫(kù),op_test為進(jìn)程。以上采樣數(shù)據(jù)表明,檢測(cè)時(shí)間內(nèi),cpu主要

21、執(zhí)行內(nèi)核和模塊代碼,用于執(zhí)行l(wèi)ibend.so庫(kù)函數(shù)的比重亦較大,達(dá)到10左右。  進(jìn)一步地,我們可以查看到進(jìn)程、動(dòng)態(tài)庫(kù)中的每個(gè)函數(shù)在檢測(cè)時(shí)間內(nèi)占用cpu的情況:linux # opreport -l samples % image name app name symbol name31645719 87.4472 no-vmlinux no-vmlinux /no-vmlinux 4361113 10.3605 libend.so libend.so endless 7046 0.1253 op_test op_test main 以上輸出顯示消耗cpu的函數(shù)為liben

22、d.so庫(kù)中的endless函數(shù),以及op_test程序中的main函數(shù)。 進(jìn)行oprofile初始化時(shí),若我們執(zhí)行opcontrol -vmlinux=vmlinux-uname -r,指定oprofile對(duì)內(nèi)核和內(nèi)核模塊進(jìn)行探測(cè),在執(zhí)行opreport查看檢測(cè)結(jié)果時(shí),內(nèi)核和內(nèi)核模塊就不再顯示為no-vmlinux,而是內(nèi)核和各個(gè)內(nèi)核模塊作為單獨(dú)的鏡像,顯示相應(yīng)cpu占用情況。 使用opannotate從代碼層看cpu占用情況以上介紹了使用oprofile的opreport命令,分別從進(jìn)程和函數(shù)層面查看cpu使用情況的方法??吹竭@里,有的同學(xué)可能有這樣的疑問(wèn):使用opre

23、port,我找到了消耗cpu的進(jìn)程A,找到了進(jìn)程A中最消耗cpu的函數(shù)B,進(jìn)一步地,是否有辦法找到函數(shù)B中最消耗cpu的那一行代碼呢? oprofile中的opannotate命令可以幫助我們完成這個(gè)任務(wù),結(jié)合具備調(diào)試信息的程序、帶有debuginfo的動(dòng)態(tài)庫(kù),opannotate命令可顯示代碼層面占用cpu的統(tǒng)計(jì)信息。下面我們通過(guò)幾個(gè)簡(jiǎn)單的程序?qū)嵗?,說(shuō)明opannotate命令的使用方法。 首先,我們需要一個(gè)消耗cpu的程序,該程序代碼如下:/op_test.cextern void endless();int main()int i = 0, j = 0;for (;

24、i < 10000000; i+ ) j+; endless();return 0;該程序引用了外部函數(shù)endless,endless函數(shù)定義如下:/end.cvoid endless()int i = 0;while(1) i+; endless函數(shù)同樣很簡(jiǎn)單,下面我們將定義了endless函數(shù)的end.c進(jìn)行帶調(diào)試信息地編譯,并生成libend.so動(dòng)態(tài)庫(kù)文件:linux # gcc -c -g -fPIC end.clinux # gcc -shared -fPIC -o libend.so end.olinux # cp libend.so /usr/lib64/libend.s

25、o接著,帶調(diào)試信息地編譯op_test.c,生成op_test執(zhí)行文件:linux # gcc -g -lend -o op_test op_test.c 之后,我們開(kāi)啟oprofile進(jìn)行檢測(cè),并拉起op_test進(jìn)程:linux # opcontrol -resetlinux # opcontrol -startlinux # ./op_test &在程序運(yùn)行一段時(shí)間后,導(dǎo)出檢測(cè)數(shù)據(jù),使用opannotate進(jìn)行結(jié)果查看:linux # opcontrol -dumplinux # opannotate -s op_test/* * Total samples for f

26、ile : "/tmp/lx/op_test.c" * * 7046 100.00 */ : int main() : /*main total : 7046 100.000 */ : int i = 0, j = 0;6447 91.4987 : for (; i < 10000000; i+ ) : 599 8.5013 : j+; : : endless(); : return 0; :以上輸出表明,在op_test程序的main函數(shù)中,主要消耗cpu的是for循環(huán)所在行代碼,因該段代碼不僅包含變量i的自增運(yùn)算,還將i與10000000進(jìn)行比較。 下面

27、顯示對(duì)自編動(dòng)態(tài)庫(kù)libend.so的檢測(cè)結(jié)果:linux # opannotate -s /usr/lib64/libend.so/* * Total samples for file : "/tmp/lx/end.c" * * 4361113 100.00 */ : void endless() : : int i = 0; : while(1) : 25661 0.6652 : i+;4335452 99.3348 : :  查看c庫(kù)代碼占用cpu情況以上使用opannotate,分別查看了應(yīng)用程序代碼、自編動(dòng)態(tài)庫(kù)代碼的cpu占用情況,對(duì)于c庫(kù)中的代碼,我們是否也能查看其消耗cpu的情況呢? 在使用oprofile查看c庫(kù)代碼信息前,需要安裝glibc的debuginfo包,安裝debuginfo包之后,我們即可以通過(guò)opannotate查看到c庫(kù)代碼,以下展示了malloc底層實(shí)現(xiàn)函數(shù)_int_malloc的部分代碼:linux # opannotate -s /lib64/libc-2.4.so/* -malloc- */ :Void_t * :_int_malloc( mstate av, size_t bytes ) : /

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論