3 回答

TA貢獻(xiàn)1775條經(jīng)驗(yàn) 獲得超8個(gè)贊
System Tap可以在現(xiàn)代的Linux機(jī)器(Fedora 10,RHEL 5等)上使用。
首先下載para-callgraph.stp腳本。
然后運(yùn)行:
$ sudo stap para-callgraph.stp 'process("/bin/ls").function("*")' -c /bin/ls
0 ls(12631):->main argc=0x1 argv=0x7fff1ec3b038
276 ls(12631): ->human_options spec=0x0 opts=0x61a28c block_size=0x61a290
365 ls(12631): <-human_options return=0x0
496 ls(12631): ->clone_quoting_options o=0x0
657 ls(12631): ->xmemdup p=0x61a600 s=0x28
815 ls(12631): ->xmalloc n=0x28
908 ls(12631): <-xmalloc return=0x1efe540
950 ls(12631): <-xmemdup return=0x1efe540
990 ls(12631): <-clone_quoting_options return=0x1efe540
1030 ls(12631): ->get_quoting_style o=0x1efe540

TA貢獻(xiàn)1842條經(jīng)驗(yàn) 獲得超22個(gè)贊
假設(shè)您可以使用gcc選項(xiàng)重新編譯(無(wú)需更改源代碼)要跟蹤的代碼-finstrument-functions,則可以使用etrace來(lái)獲取函數(shù)調(diào)用圖。
輸出如下所示:
\-- main
| \-- Crumble_make_apple_crumble
| | \-- Crumble_buy_stuff
| | | \-- Crumble_buy
| | | \-- Crumble_buy
| | | \-- Crumble_buy
| | | \-- Crumble_buy
| | | \-- Crumble_buy
| | \-- Crumble_prepare_apples
| | | \-- Crumble_skin_and_dice
| | \-- Crumble_mix
| | \-- Crumble_finalize
| | | \-- Crumble_put
| | | \-- Crumble_put
| | \-- Crumble_cook
| | | \-- Crumble_put
| | | \-- Crumble_bake
在Solaris上,truss(等效于strace)可以過(guò)濾要跟蹤的庫(kù)。當(dāng)我發(fā)現(xiàn)strace不具備這種功能時(shí),我感到很驚訝。
添加回答
舉報(bào)