<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>4.3.2. Call Graph Tracing</title><link rel="stylesheet" href="./Common_Content/css/default.css" type="text/css" /><meta name="generator" content="publican 1.6" /><meta name="package" content="Systemtap-SystemTap_Beginners_Guide-1.0-en-US-2.0-2" /><link rel="home" href="index.html" title="SystemTap Beginners Guide" /><link rel="up" href="mainsect-profiling.html" title="4.3. Profiling" /><link rel="prev" href="mainsect-profiling.html" title="4.3. Profiling" /><link rel="next" href="threadtimessect.html" title="4.3.3. Determining Time Spent in Kernel and User Space" /></head><body class=""><p id="title"><a class="left" href="http://www.fedoraproject.org"><img src="Common_Content/images/image_left.png" alt="Product Site" /></a><a class="right" href="http://docs.fedoraproject.org"><img src="Common_Content/images/image_right.png" alt="Documentation Site" /></a></p><ul class="docnav"><li class="previous"><a accesskey="p" href="mainsect-profiling.html"><strong>Prev</strong></a></li><li class="next"><a accesskey="n" href="threadtimessect.html"><strong>Next</strong></a></li></ul><div xml:lang="en-US" class="section" title="4.3.2. Call Graph Tracing" lang="en-US"><div class="titlepage"><div><div><h3 class="title" id="paracallgraph">4.3.2. Call Graph Tracing</h3></div></div></div><a id="id2966667" class="indexterm"></a><a id="id2987507" class="indexterm"></a><a id="id2763523" class="indexterm"></a><a id="id4363373" class="indexterm"></a><a id="id2997709" class="indexterm"></a><a id="id4371244" class="indexterm"></a><a id="id2908003" class="indexterm"></a><div class="para"> This section describes how to trace incoming and outgoing function calls. </div><div class="formalpara"><h5 class="formalpara" id="scriptcallgraph">para-callgraph-simple.stp</h5> <pre class="programlisting"> function trace(entry_p) { if(tid() in trace) printf("%s%s%s\n",thread_indent(entry_p), (entry_p>0?"->":"<-"), probefunc()) } global trace probe kernel.function(@1).call { if (execname() == "stapio") next # skip our own helper process trace[tid()] = 1 trace(1) } probe kernel.function(@1).return { trace(-1) delete trace[tid()] } probe kernel.function(@2).call { trace(1) } probe kernel.function(@2).return { trace(-1) } function trace(entry_p) { if(tid() in trace) printf("%s%s%s\n",thread_indent(entry_p), (entry_p>0?"->":"<-"), probefunc()) } global trace probe kernel.function(@1).call { if (execname() == "stapio") next # skip our own helper process trace[tid()] = 1 trace(1) } probe kernel.function(@1).return { trace(-1) delete trace[tid()] } probe kernel.function(@2).call { trace(1) } probe kernel.function(@2).return { trace(-1) } </pre> </div><a id="id3033177" class="indexterm"></a><a id="id2990007" class="indexterm"></a><a id="id3028772" class="indexterm"></a><a id="id3116223" class="indexterm"></a><div class="para"> <a class="xref" href="paracallgraph.html#scriptcallgraph" title="para-callgraph-simple.stp">para-callgraph-simple.stp</a> takes two command-line arguments: </div><a id="id3100201" class="indexterm"></a><a id="id2733813" class="indexterm"></a><a id="id2868461" class="indexterm"></a><div class="itemizedlist"><ul><li class="listitem"><div class="para"> A <em class="firstterm">trigger function</em> (<code class="command">@1</code>), which enables or disables tracing on a per-thread basis. Tracing in each thread will continue as long as the trigger function has not exited yet. </div></li><li class="listitem"><div class="para"> The kernel function/s whose entry/exit call you'd like to trace (<code class="command">@2</code>). </div></li></ul></div><a id="id2851850" class="indexterm"></a><a id="id2929056" class="indexterm"></a><a id="id2990527" class="indexterm"></a><div class="para"> <a class="xref" href="paracallgraph.html#scriptcallgraph" title="para-callgraph-simple.stp">para-callgraph-simple.stp</a> uses <code class="command">thread_indent()</code>; as such, its output contains the timestamp, process name, and thread ID of <code class="command">@2</code> (i.e. the probe function you are tracing). For more information about <code class="command">thread_indent()</code>, refer to its entry in <a class="xref" href="systemtapscript-handler.html#systemtapscript-functions" title="SystemTap Functions">SystemTap Functions</a>. </div><div class="para"> The following example contains an excerpt from the output for <code class="command">stap para-callgraph.stp sys_read '*@fs/*.c'</code>: </div><div class="example" id="paracallgraphoutput"><div class="example-contents"><pre class="screen"> [...] 0 klogd(1391):->sys_read 14 klogd(1391): ->fget_light 22 klogd(1391): <-fget_light 27 klogd(1391): ->vfs_read 35 klogd(1391): ->rw_verify_area 43 klogd(1391): <-rw_verify_area 49 klogd(1391): ->kmsg_read 0 sendmail(1696):->sys_read 17 sendmail(1696): ->fget_light 26 sendmail(1696): <-fget_light 34 sendmail(1696): ->vfs_read 44 sendmail(1696): ->rw_verify_area 52 sendmail(1696): <-rw_verify_area 58 sendmail(1696): ->proc_file_read 70 sendmail(1696): ->loadavg_read_proc 84 sendmail(1696): ->proc_calc_metrics 92 sendmail(1696): <-proc_calc_metrics 95 sendmail(1696): <-loadavg_read_proc 101 sendmail(1696): <-proc_file_read 106 sendmail(1696): ->dnotify_parent 115 sendmail(1696): <-dnotify_parent 119 sendmail(1696): ->inotify_dentry_parent_queue_event 127 sendmail(1696): <-inotify_dentry_parent_queue_event 133 sendmail(1696): ->inotify_inode_queue_event 141 sendmail(1696): <-inotify_inode_queue_event 146 sendmail(1696): <-vfs_read 151 sendmail(1696):<-sys_read </pre></div><h6>Example 4.14. <a class="xref" href="paracallgraph.html#scriptcallgraph" title="para-callgraph-simple.stp">para-callgraph-simple.stp</a> Sample Output</h6></div><br class="example-break" /></div><ul class="docnav"><li class="previous"><a accesskey="p" href="mainsect-profiling.html"><strong>Prev</strong>4.3. Profiling</a></li><li class="up"><a accesskey="u" href="#"><strong>Up</strong></a></li><li class="home"><a accesskey="h" href="index.html"><strong>Home</strong></a></li><li class="next"><a accesskey="n" href="threadtimessect.html"><strong>Next</strong>4.3.3. Determining Time Spent in Kernel and User ...</a></li></ul></body></html>