tag:blogger.com,1999:blog-4982215793068879977.post5554534148253852646..comments2023-09-07T02:56:05.540+08:00Comments on fcamel 技術隨手記: 在 Linux 上找執行時間的瓶頸fcamelhttp://www.blogger.com/profile/04792244455260595133noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-4982215793068879977.post-46827838286581180892012-06-14T01:49:53.050+08:002012-06-14T01:49:53.050+08:00另外, "perf script" 類似 "perf report&q...另外, "perf script" 類似 "perf report" 但輸出一行一個文字紀錄,滿有用的。<br /><br />例: "perf record -e signal:signal_deliver" 用 "perf script" 可看到 signal number。Anonymoushttps://www.blogger.com/profile/18195653023013629876noreply@blogger.comtag:blogger.com,1999:blog-4982215793068879977.post-39430002552054700162012-06-14T01:35:06.344+08:002012-06-14T01:35:06.344+08:00@wens, re: "perf 預設紀錄什麼 event"
perf 預設紀...@wens, re: "perf 預設紀錄什麼 event"<br /><br />perf 預設紀錄的 event 只有一個: "cycles" -- 即在 CPU 跑一定週期後取樣。<br />列出紀錄檔中 event 的種類可用:<br />perf evlist -i perf.data<br />"cycles" event 細節見: https://perf.wiki.kernel.org/index.php/Tutorial#Default_event:_cycle_counting<br /><br /><br />@fcamel, <br />1. 用詞上通常說:『profiler 分兩類:instrumenting based 和 sampling based』。instrumenting / instrumentation based profiler 中的 "instrument" 一詞指的是『加 code』。<br /><br />2. Re: 『最花時間的部份變成 snd_ac97_codec 或 binfmt_misc。不知是否能相信它的結果』<br /><br />若已知程式是 CPU bound 在 userspace 則可忽略花在 kernel space 的時間。我們知道 snd_ac97_codec 與 binfmt_misc 都是在 kernel 內的,因為工具列 report 時欄位有寫,且在你的測試程式內無此名稱的符號。基本上 sampling based profiler 對『program counter 落點』的紀錄可信,要出錯會是在 symbolic name 與驅動取樣的 event 上。<br /><br />3. 你用 VirtualBox 會看到 snd_ac97_codec 這張模擬出來的音效卡的 driver 會出現在 profile 內,代表模擬硬體 / driver 跟 pulseaudio 互動不良,建議你 Linux VM 統一把音效卡移除掉。<br /><br />高 CPU 可能原因: pulseaudio 的 timer based scheduling 會希望 audio codec driver 能盡量準確的回報 PCM data 播到第幾個 byte 由此導出資料消耗率與下次 wakeup 時間。這邊的的演算法會用到早期 driver 只用 interrupt driven mode 驅動時沒用到的 code path。<br /><br />binfmt_misc 會出現比較奇怪。此機制通常是用來『透過模擬器執行不同 OS 或不同 CPU 的可執行檔的』(可看一下 /proc/sys/fs/binfmt_misc/)<br /><br />4. event sampling profiler 在 Virtual Machine 跑會少功能而且取樣比較不準,因為 CPU 硬體原本提供的 cycle count, cache miss 等 event (這需要 driver)在 VM 內存不到。若 sampling profiler 無法使用 CPU performance counter 硬體 而改用『純軟體』的 timer interrupt來取樣的話,在 VM 內 timer interrupt 也比較不準,測量誤差也會高些(?)。<br /><br />perf 不要跑在 VM 下的時候,其實真的很容易上手,且熟悉後可增加紀錄的事件 (cache miss, syscalls, kernel 內的 VM, block I/O, filesystem 等) 越鑽越深。<br /><br /><br />5. profiler 為何想要 "vmlinux"<br /><br />perf 與 oprofile 想要的其實是編譯 kernel 時 gcc -g 產生的 debuginfo,<br />在 Fedora 下 "yum install kernel-debuginfo" 即可。Fedora 這邊有做好不是意外。<br /><br />vmlinux 是 kernel 的 ELF image,格式同我們自己編譯出來的可執行檔。 除了讀 vmlinux 外,perf 與 oprofile 也懂得讀 /usr/lib/debug 下的 separate debug info 檔案取得同樣資訊。另外,Linux kernel 預設 CFLAGS 是沒加 -g 的,因為編譯會慢不少,且 debug info 頗大。Anonymoushttps://www.blogger.com/profile/18195653023013629876noreply@blogger.comtag:blogger.com,1999:blog-4982215793068879977.post-36377756173576118112012-06-13T01:14:44.489+08:002012-06-13T01:14:44.489+08:00perf 你要跟他說你想要紀錄什麼event,
他預設是紀錄什麼我到現在還搞不清楚。
我看到的是用...perf 你要跟他說你想要紀錄什麼event,<br />他預設是紀錄什麼我到現在還搞不清楚。<br /><br />我看到的是用 stall-cycleAnonymoushttps://www.blogger.com/profile/01767428090010460014noreply@blogger.com