= DEBUG / profiler = * [參考] [http://alephnull.com/perf.html Linux Performance and Development Tools] - 列舉了許多自由軟體的效能分析工具(Performance Analysis Tools) == callgraph : 了解程式流程 == * ([wiki:jazz/11-03-31 2011-03-31]) * C/C++ * Rex 在 [http://people.debian.org.tw/~chihchun/2011/03/30/callgraphviz/ CallGraphviz – call graph visualzer based on csope, graphviz and xdot] 一文中介紹了許多不同的 callgraph 產生方式。 * 搭配[http://en.wikipedia.org/wiki/Call_graph 維基百科 Call_graph]的軟體簡介,大概整理如下: * [http://www.skynet.ie/~mel/projects/codeviz/ CodeViz] - 缺點:必須 patch GCC 然後用 Perl 來產生圖形 * [http://students.ceid.upatras.gr/~sxanth/ncc/ ncc] - 目標是取代 cflow 跟 cscope,[http://blog.linux.org.tw/~jserv/archives/001723.html jserv 有介紹過] - 缺點:相依 GCC 環境版本 * 有 [http://packages.debian.org/ncc Debian 套件 ncc] * [http://www.gnu.org/software/cflow/ cflow] - 老字號 GNU 的流程分析工具 - [http://fred-zone.blogspot.com/2009/09/trace-cflow.html Fred 有寫過用在分析 Android Dalvik VM 的示範] - 產生文字輸出 * 有 [http://packages.debian.org/cflow Debian 套件 cflow] * [http://cscope.sourceforge.net/ cscope]/[http://www.gnu.org/software/global/ global] - Interactively examine a C program source - 我想 cscope 要強調的是 interactive 互動式除錯,而且照 Rex 的講法,可以只針對某個函數當進入點,而不是整個程式原始碼。 * 有 [http://packages.debian.org/cscope Debian 套件 cscope] 跟 [http://packages.debian.org/global global] * [http://www.vim.org/scripts/script.php?script_id=2368 CCTree] - C Call-Tree Explorer - Cscope based source-code browser, code flow analysis tool - 給 VIM 用的 cscope plugin * [http://code.google.com/p/seascope/ seascope] - A pyQt GUI front-end for cscope - pyQt 寫的 cscope 圖形介面 * [http://sourceforge.net/projects/kscope/ kscope] - A source-code browsing, analysis and editing environment for large C projects. - KDE 版本的 cscope 圖形介面 - 有 [http://packages.debian.org/kscope Debian 套件 kscope] * [http://kcachegrind.sourceforge.net/ KCachegrind] - Profiling Visualization - 這個工具是搭配 Valgrind 這個 Profiler 可以在 runtime 產生 callgrah * [http://code.google.com/p/jrfonseca/wiki/Gprof2Dot Gprof2Dot] - 也是透過 profiler 產生的輸出來作視覺化動作,最初是支援 gprof 現在已經支援更多不同 profiler 了。 * [http://www.gson.org/egypt/ egypt] - 用 Perl 寫的 * Python * [http://pycallgraph.slowchop.com/ pycallgraph] - Python Call Graph * Bash * 我一直想找的是 Bash 的遞迴式 callgraph 產生器,雖然 Bash 可以加入 -X 參數來做 runtime 除錯,不過還沒有找到可以查出多層該怎麼追。 * [http://bashdb.sourceforge.net/ bashdb] - BASH Debugger - 可以用類似 GDB 的指令來 DEBUG Bash * shprof - a line profiler for shell scripts * [http://dev.gentoo.org/~dberkholz/scripts/shprof 原始碼] * 這邊有一招是蠻好玩的,居然只要設定 PS4 環境變數就可以秀出每個呼叫的開始時間。(這算是 bash 的簡易版 profiler 嘛?) [http://www.myunitsconverter.com/thread/885124/time%20profiling%20a%20linux%20command%20or%20script <參考討論> time profiling a linux command or script] {{{ Least invasive you may want to play with some variant of... set -x PS4='$( date ): ' sleep 1 sleep 3 sleep 2 exit 0 which produces timestamps in front of the commands... Mon Mar 17 02:39:35 CET 2008: PS4='$( date ): ' Mon Mar 17 02:39:35 CET 2008: sleep 1 Mon Mar 17 02:39:36 CET 2008: sleep 3 Mon Mar 17 02:39:39 CET 2008: sleep 2 Mon Mar 17 02:39:41 CET 2008: exit 0 }}} == Profiling / Profiler : 了解程式特性(CPU、記憶體、I/O) == * ([wiki:jazz/10-06-07 2010-06-07]) * [http://www.pixelbeat.org/programming/profiling/ Linux Profiling tools and techniques] (2011-04-27) * Java * [http://blog.trifork.com/2012/03/13/java-profiler-comparison/ Java Profiler Comparison] * [http://www.eclipse.org/tptp/ Eclipse Test & Performance Tools Platform Project (TPTP)] - Eclipse 的 Profiling 工具 * [http://www.eclipse.org/tptp/home/documents/tutorials/profilingtool/profilingexample_32.html An introduction to profiling Java applications] * [http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse.tptp.platform.doc.user/concepts/ceproftl.htm Overview of the Profiling Tool] - Eclipse 說明文件有蠻詳細的 Monitoring and profiling applications 觀念與操作步驟介紹 * [http://profiler.netbeans.org/ Netbean Java Profiler] - CPU, memory and threads profiling - 搭配 Netbean * [http://www.ej-technologies.com/company/profile.html JProfiler] - [http://en.wikipedia.org/wiki/JProfiler 維基百科] - 搭配 Eclipse * [http://www.khelekore.org/jmp/ jmp] - Java Memory Profiler (主攻記憶體的 Profiler) * [http://packages.debian.org/jmp Debian 套件 jmp] - Profiler for Java to trace object and method timings (舊的) * [http://www.khelekore.org/jmp/tijmp/ tijmp] - [http://packages.debian.org/tijmp Debian 套件 tijmp] - Profiler for Java to trace object and method timings (比較新) * Runtime Profiler * http://profiler4j.sourceforge.net/ - 看起來不錯,不過大約 2006 之後就比較少更新了。 * Monitoring - JMX * [http://klaas.homeip.net/mcs/jmeasurement/ JMeasurement] - 支援 JMX 的 Profiler * [http://xdprof.sourceforge.net/ xdprof] - a cross-platform tool that captures and analyzes stack traces sent at a fixed interval from Java Virtual Machines in a distributed system - 因為是針對分散式系統的 profiler,所以有可能可以用在 Hadoop 效能分析上 * C - check [raw-attachment:wiki:jazz/10-06-07:Advanced_C_Programming_Profiling.pdf slides of "Advanced C Programming - Profiling"] * [http://www.gnu.org/software/binutils/ gprof] - 屬於 GNU binutils 的一部分 - [http://packages.debian.org/binutils Debian 套件 - binutils] * [http://blog.superd.org/index.php/2004/11/02/39/ gprof 看 performance 分析…] * [http://awkzone.blogspot.com/2010/11/gprof.html gprof - linux program profiling tool] * [http://kprof.sourceforge.net/ kprof] - a KDE3 visual tool to help analyze profiling results - [http://packages.debian.org/kprof Debian 套件 kprof] * [http://code.google.com/p/jrfonseca/wiki/Gprof2Dot#Example gprof2dot] - 把 gprof log 轉成 graphviz 的 dot 格式,就可以畫出圖形了 * gcov - 統計 code coverage 的工具,可以在 gcc 編譯時加參數來達成。 {{{ Use GCC flags -fprofile-arcs: collect info about jumps -ftest-coverage: collect info about code coverage }}} * [http://awkzone.blogspot.com/2010/11/gcov-linux-code-coverage-analysis-tool.html gcov - linux code coverage analysis tool] * mtrace() 函數 - 檢查記憶體溢出(memory leakage)問題 ([wiki:jazz/10-03-04 2010-03-04]) * [http://itzone.hk/article/article.php?aid=200406221149442361 Linux C編程偵測記憶體溢出工具(一):mtrace ] * [http://valgrind.org/ valgrind] - [http://packages.debian.org/valgrind Debian 套件 - valgrind] - ([wiki:jazz/10-03-04 2010-03-04]) * [http://daydreamer.idv.tw/rewrite.php/read-18.html 檢查程式記憶體的小工具-valgrind] * [http://www.jeffhung.net/blog/articles/jeffhung/1007/ Detecting C/C++ memory leaks with valgrind] * 在 [raw-attachment:wiki:jazz/10-06-07:Advanced_C_Programming_Profiling.pdf slides of "Advanced C Programming - Profiling"] 投影片介紹中,有三個主要工具 memcheck、cachegrind、callgrind * cachegrind - 模擬 L1/L2 Cache, 找出 cache misses * [http://packages.debian.org/kcachegrind Debian 套件 kcachegrind] - visualisation tool for valgrind profiling output - 可以用視覺化圖形介面顯示 cachegrind 的輸出 * [http://packages.debian.org/kcachegrind-converters Debian 套件 kcachegrind-converters] - format converters for KCachegrind profiling visualisation tool * callgrind - 紀錄函數呼叫圖(call graph) * [http://live.gnome.org/iogrind iogrind] - I/O profiling tool - 用來顯示應用程式的 I/O Profile * [http://oprofile.sourceforge.net oprofile] - a system-wide profiler for Linux systems, capable of profiling all running code at low overhead. * 有 [http://packages.debian.org/oprofile Debian 套件 - oprofile] {{{ #!sh ~# opcontrol --init # to load module and daemon ~# opcontrol -s # to start sampling ~# opcontrol -t # to stop sampling ~# opcontrol --dump # ?ushes the event log ~# opcontrol --list-events # shows available performance counters ~# opreport -l prog-name # gives breakdown of samples per function in prog-name }}} * [http://packages.debian.org/oprofile-gui Debian 套件 oprofile-gui] - system-wide profiler for Linux systems (GUI components) * [http://hi.baidu.com/colin719/blog/item/3d78da8032ba72d79123d9ed.html 使用 gprof 和 oprofile 查找性能瓶頸] * [http://packages.debian.org/sid/qprof qprof] - Profiling utilities for Linux * sysprof - [http://packages.debian.org/sysprof Debian 套件 sysprof] - ([wiki:jazz/10-03-04 2010-03-04]) * 2005-09 [http://blog.linux.org.tw/~jserv/archives/001302.html sysprof - System-wide Linux Profiler] - jserv 推薦 * Perl * [http://search.cpan.org/dist/Devel-Profile/ Devel::Profile] - [http://packages.debian.org/libdevel-profile-perl Debian 套件 - libdevel-profile-perl] - a Perl code profiler * [http://search.cpan.org/dist/Devel-Cover/ Devel::Cover] - Code coverage metrics for Perl - [http://packages.debian.org/libdevel-cover-perl Debian 套件 libdevel-cover-perl] * PHP - references for armorize * [http://www.linuxjournal.com/article/7213 PHP Performance Profiling] * [http://www.php-editors.com/php-tools/php-profiler.php php-profiler] * Bash * 看樣子,bash 編譯時如果加入 [http://www.faqs.org/docs/bashman/bashref_120.html --enable-profiling] 就可以透過 gprof 進行 profiling。至於怎麼用,暫且還沒找到範例。 * MPI * [http://packages.debian.org/tau Debian 套件 tau] - Tuning and Analysis Utilities - base profiling toolkit * TAU is a profiling toolkit specially made for parallel computing (multi-thread, multi-process, MPI, PVM). - 針對平行程式的 Profiler 不過套件裡面包的只有 pthread 的支援,因此無法做 MPI, PVM 分析。 * [http://packages.debian.org/tau-examples Debian 套件 tau-examples] - Tuning and Analysis Utilities - examples - 一些 TAU 的範例 * [http://packages.debian.org/python-tau Debian 套件 python-tau] - Tuning and Analysis Utilities - support for python bindings * Python * [http://packages.debian.org/python-profiler Debian 套件 python-profiler] - deterministic profiling of any Python programs * Ruby * [http://packages.debian.org/ruby-prof Debian 套件 ruby-prof] - A fast code profiler for Ruby * C# / Mono * [http://packages.debian.org/mono-profiler mono-profiler] - Mono profiler - [http://packages.debian.org/mono-profiler 有 Debian 套件 mono-profiler] == Systemtap / DTrace / ftrace == * ([wiki:jazz/10-03-04 2010-03-04]) * [http://lwn.net/Articles/291091/ Tracing: no shortage of options] - Linux 追查 User Space / Kernel Space 的 trace 工具一覽 * !SystemTap * 官方網站 - http://sourceware.org/systemtap/ * [http://packages.debian.org/systemtap Debian 套件 - systemtap] * IBM Redbook - [http://www.redbooks.ibm.com/abstracts/redp4469.html SystemTap: Instrumenting the Linux Kernel for Analyzing Performance and Functional Problems] - 先前有看過一小段,目前暫時還沒有需要用到這種工具的時機。 * [http://gnu.wildebeest.org/diary/2009/12/07/fudcon-success-systemtap-meets-python/ FudCon Success – Systemtap meets Python] * [http://sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps Adding User Space Probing to an Application (heapsort example)] * [http://people.redhat.com/roland/utrace/ utrace] - a new kernel-side API for kernel modules * [http://lwn.net/Articles/224772/ Introducing utrace] * 看起來是 !SystemTap 用在追蹤 User Space 的工具,但核心必須支援。 * DTrace * 3/3 聽完 Sun 的 Open Solaris 簡介,對於 DTrace 興起一些好奇,看了一些討論發現 DTrace 是比較友善,但要學 D 語言,而 !SystemTap 比較合適追 Kernel Space 的錯誤,User Space 必須靠 utrace 的支援。當然現階段最麻煩的還是授權,跟 ZFS, Lustre 一樣,DTrace 之所以沒有移植到 Linux 都是因為授權是 CDDL 而非 GPL。唉...自由軟體的授權真是一件複雜的事情啊!! * 2010-07-25 - [http://dtracehol.com/ Observing and Optimizing your Application with DTrace] - [http://www.oscon.com/oscon2010/public/schedule/detail/13601 OSCON 2010 dTrace Tutorial] 的實作網站,共設計了 17 個練習。Cool~ * [http://assets.en.oreilly.com/1/event/45/Observing%20and%20Optimizing%20your%20Application%20with%20DTrace%20Presentation.pdf OSCON 2010 dTrace 投影片] * [http://blog.xuite.net/evereasy/solarpower/19400612 免費的私家偵探-跟著 DTrace 探索 Process] * [http://www.solarisinternals.com/wiki/index.php/DTrace_Topics_Intro DTrace Topics Intro] * [ftp://crisp.dynalias.com/pub/release/website/dtrace/ 不太合乎授權的 DTrace Porting for Linux] * 2008-06 - [http://blogs.sun.com/bmc/entry/dtrace_on_linux DTrace on Linux] * 2007-07 - [http://developers.sun.com/solaris/articles/dtrace_ajax.html End-to-End Tracing of Ajax/Java Applications Using DTrace] * 2007-03 - [http://blogs.sun.com/jmr/entry/adding_dtrace_probes_to_mozilla Adding Dtrace Probes to Mozilla] * 2006-09 - [http://blogs.sun.com/brendan/entry/dtrace_meets_javascript DTrace meets JavaScript] * [http://lttng.org/ LTTng] * allow tracing of the kernel, of userspace, trace viewing and analysis and trace streaming. * [http://sourceware.org/systemtap/wiki/SystemtapDtraceComparison SystemTap / DTrace / LTTng 比較一覽表] * Ftrace * [http://www.linuxhq.com/kernel/v2.6/29/Documentation/ftrace.txt Documentation/ftrace.txt] @ Kernel 2.6.29 * [http://lwn.net/Articles/322666/ A look at ftrace] * strace - 還算常用的 DEBUG 工具 - <參考> [http://mlwmlw.no-ip.org/2011/12/linux-tracing-tools/ linux tracing tools] * [http://www.ibm.com/developerworks/cn/linux/l-tsl/ 這篇提到還有 ltrace, truss 兩種工具] * strace (1): lists all system calls used - [http://packages.debian.org/strace Debian 套件 - strace] * ltrace (1): lists all shared library calls - [http://packages.debian.org/ltrace Debian 套件 - ltrace] * truss (1): trace system calls and signals - * 【註】出於安全方面的考慮,在 FreeBSD 5 之後系統預設已經不再自動掛載 proc 檔案系統,因此,要想使用 truss 或 strace 跟蹤程序,你必須手工掛載 proc 檔案系統:mount -t procfs proc /proc;ltrace 不需要使用 procfs。 * 較少聽過的: * [http://people.redhat.com/jolsa/latrace/index.shtml latrace] - LD_AUDIT 2.4+ libc frontend * ptrace() - process trace * 2008-03 : jserv - [http://blog.linux.org.tw/~jserv/archives/002027.html 以 ptrace 系統呼叫來追蹤/修改行程] * 2002-11 : [http://www.linuxjournal.com/article/6100 Playing with ptrace, Part I] * 2002-12 : [http://www.linuxjournal.com/article/6210 Playing with ptrace, Part II] == Code Peer Review == * http://groogle.sourceforge.net/ * http://trac-hacks.org/wiki/PeerReviewPlugin == Perl Debugger == * [專案] [http://packages.debian.org/lenny/libcrypt-ssleay-perl libcrypt-ssleay-perl] - 讓 Perl 的 LWP 支援 HTTPS 協定所需的套件。 * [備忘] [http://debugger.perl.org/580/perldebtut.html perldebtut] - Perl debugging tutorial 官方文件 * 由於以往寫 Perl 的程式都只會用 print 把變數印出來,好觀察到底判斷式寫得正不正確,正規表示法所擷取出來的內容到底是不是自己想要的。不過今天花了一整天 Debug 某一段程式邏輯,輸入的資料量又不少,有時候還真的蠻想要有 step trace 的功能。寫 C 可以用 gdb 作 debugger,那 Perl 呢?? 答案是__'''加一個 -d 參數'''__下去跑。 * [http://docstore.mik.ua/orelly/perl/prog3/ch20_01.htm The Perl Debugger (Programming Perl 3rd Edition)] * [http://www.thegeekstuff.com/2010/05/perl-debugger/ Perl Debugger Tutorial: 10 Easy Steps to Debug Perl Program] * [http://www.linuxjournal.com/article/7581?page=0,3 The Perl Debugger] * [http://aspn.activestate.com/ASPN/Downloads/VisualPerl/ Visual Perl] - !ActiveState ends development of dynamic language plug-ins for Microsoft Visual Studio * [http://www.gnu.org/software/ddd/ ddd] 可以對 perl 程式除錯, 用 ddd --perl 起動 ddd 來對 perl 程式除錯,或者在 preference 設 perl 模式 * [http://www.epic-ide.org/ EPIC] - Perl Editor and IDE for Eclipse * 互動式介面 * [http://www.focusresearch.com/gregor/sw/psh/ psh] - interactive perl shell * Debian / Ubuntu 有 [http://packages.debian.org/psh psh] 套件 * [http://www.tudou.com/programs/view/x5pyBpSOxcg/ 土豆網的 psh 介紹] * [http://search.cpan.org/~jberger/Zoidberg-0.98/ Zoidberg]: A Shell That Speaks Perl * Debian / Ubuntu 有 [http://packages.debian.org/zoidberg zoidberg] 套件 * [http://drdobbs.com/web-development/184416203 Zoidberg: A Shell That Speaks Perl]