實(shí)現(xiàn)高性能服務(wù)器免不了進(jìn)行代碼級性能分析和系統(tǒng)級壓力測試,簡單整理一下代碼級的性能分析工具
1.gprof : 非常易于使用 , 編譯程序時(shí)使用-pg選項(xiàng),然后執(zhí)行程序,只要程序正常退出(從main()返回或exit退出) , 會生成gmon.out文件,這個(gè)文件包含了程序運(yùn)行時(shí)收集的各種統(tǒng)計(jì)數(shù)據(jù),使用gprof分析這個(gè)結(jié)果文件可以顯示flat profile , call graph , annotated source 。值得注意的是無法跟蹤內(nèi)核態(tài)的執(zhí)行情況和進(jìn)程切換帶來的影響。
2.valgrind :強(qiáng)大和全面的工具,主要包括memcheck,call graph , cache check , thread detector , heap profiler,測試server程序時(shí)需要注意信號處理,使程序正常退出。
3.oprofile : 不但可以分析單個(gè)程序性能,還能夠分析系統(tǒng)性能 ,作為獨(dú)立模塊運(yùn)行,使用cpu的計(jì)數(shù)寄存器進(jìn)行數(shù)據(jù)分析。
opcontrol --no-vmlinux --start 啟動(dòng)profile,此時(shí)系統(tǒng)會把收集的數(shù)據(jù)寫入文件,系統(tǒng)的iowait非常高。
opcontrol --stop 關(guān)閉profile。
opreport -l server_program 查看結(jié)果。
4.tcmalloc : google的內(nèi)存分配器和profile工具,包括內(nèi)存檢查和cpu檢查 ,可以編譯進(jìn)代碼,也可以通過LIB_PRELOAD加載,配合環(huán)境變量實(shí)現(xiàn)profile功能。
內(nèi)存分配器:使用了線程cache ,在多線程的環(huán)境中比ptmalloc效率高2倍左右。
5.vtune :intel開發(fā)的付費(fèi)工具。
1.gprof : 非常易于使用 , 編譯程序時(shí)使用-pg選項(xiàng),然后執(zhí)行程序,只要程序正常退出(從main()返回或exit退出) , 會生成gmon.out文件,這個(gè)文件包含了程序運(yùn)行時(shí)收集的各種統(tǒng)計(jì)數(shù)據(jù),使用gprof分析這個(gè)結(jié)果文件可以顯示flat profile , call graph , annotated source 。值得注意的是無法跟蹤內(nèi)核態(tài)的執(zhí)行情況和進(jìn)程切換帶來的影響。
2.valgrind :強(qiáng)大和全面的工具,主要包括memcheck,call graph , cache check , thread detector , heap profiler,測試server程序時(shí)需要注意信號處理,使程序正常退出。
3.oprofile : 不但可以分析單個(gè)程序性能,還能夠分析系統(tǒng)性能 ,作為獨(dú)立模塊運(yùn)行,使用cpu的計(jì)數(shù)寄存器進(jìn)行數(shù)據(jù)分析。
opcontrol --no-vmlinux --start 啟動(dòng)profile,此時(shí)系統(tǒng)會把收集的數(shù)據(jù)寫入文件,系統(tǒng)的iowait非常高。
opcontrol --stop 關(guān)閉profile。
opreport -l server_program 查看結(jié)果。
4.tcmalloc : google的內(nèi)存分配器和profile工具,包括內(nèi)存檢查和cpu檢查 ,可以編譯進(jìn)代碼,也可以通過LIB_PRELOAD加載,配合環(huán)境變量實(shí)現(xiàn)profile功能。
內(nèi)存分配器:使用了線程cache ,在多線程的環(huán)境中比ptmalloc效率高2倍左右。
5.vtune :intel開發(fā)的付費(fèi)工具。