| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61  | <?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 xmlns:d="http://docbook.org/ns/docbook">5.3.3. Determining Time Spent in Kernel and User Space</title><link rel="stylesheet" type="text/css" href="Common_Content/css/default.css" /><link rel="stylesheet" media="print" href="Common_Content/css/print.css" type="text/css" /><meta xmlns:d="http://docbook.org/ns/docbook" name="generator" content="not publican" /><meta xmlns:d="http://docbook.org/ns/docbook" name="package" content="" /><link rel="home" href="index.html" title="SystemTap Beginners Guide" /><link rel="up" href="mainsect-profiling.html" title="5.3. Profiling" /><link rel="prev" href="paracallgraph.html" title="5.3.2. Call Graph Tracing" /><link rel="next" href="timeoutssect.html" title="5.3.4. Monitoring Polling Applications" /></head><body><p id="title"></p><ul class="docnav top"><li class="previous"><a accesskey="p" href="paracallgraph.html"><strong>Prev</strong></a></li><li class="home">SystemTap Beginners Guide</li><li class="next"><a accesskey="n" href="timeoutssect.html"><strong>Next</strong></a></li></ul><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="threadtimessect"> </a>5.3.3. Determining Time Spent in Kernel and User Space</h3></div></div></div><a id="idm47006125079824" class="indexterm"></a><a id="idm47006119147744" class="indexterm"></a><a id="idm47006121468384" class="indexterm"></a><a id="idm47006117322064" class="indexterm"></a><a id="idm47006121546576" class="indexterm"></a><a id="idm47006120130352" class="indexterm"></a><div class="para">This section illustrates how to determine the amount of time any given thread is spending in either kernel or user-space.</div><div class="para"><div xmlns:d="http://docbook.org/ns/docbook" class="title">thread-times.stp</div> <pre class="programlisting">#! /usr/bin/env stap probe perf.sw.cpu_clock!, timer.profile { // NB: To avoid contention on SMP machines, no global scalars/arrays used, // only contention-free statistics aggregates. tid=tid(); e=execname() if (!user_mode()) kticks[e,tid] <<< 1 else uticks[e,tid] <<< 1 ticks <<< 1 tids[e,tid] <<< 1 } global uticks%, kticks%, ticks global tids% probe timer.s(5), end { allticks = @count(ticks) printf ("%16s %5s %7s %7s (of %d ticks)\n", "comm", "tid", "%user", "%kernel", allticks) foreach ([e,tid] in tids- limit 20) { uscaled = @count(uticks[e,tid])*10000/allticks kscaled = @count(kticks[e,tid])*10000/allticks printf ("%16s %5d %3d.%02d%% %3d.%02d%%\n", e, tid, uscaled/100, uscaled%100, kscaled/100, kscaled%100) } printf("\n") delete uticks delete kticks delete ticks delete tids } </pre> </div><a id="idm47006126385616" class="indexterm"></a><a id="idm47006122898416" class="indexterm"></a><a id="idm47006128476480" class="indexterm"></a><div class="para"><a class="xref" href="threadtimessect.html#threadtimes">thread-times.stp</a> lists the top 20 processes currently taking up CPU time within a 5-second sample, along with the total number of CPU ticks made during the sample. The output of this script also notes the percentage of CPU time each process used, as well as whether that time was spent in kernel space or user space. </div><div class="para"><a class="xref" href="threadtimessect.html#threadtimesoutput">Example 5.15, “thread-times.stp Sample Output”</a> contains a 5-second sample of the output for <a class="xref" href="threadtimessect.html#threadtimes">thread-times.stp</a>:</div><div class="example"><a id="threadtimesoutput"> </a><p class="title"><strong>Example 5.15. <a class="xref" href="threadtimessect.html#threadtimes">thread-times.stp</a> Sample Output</strong></p><div class="example-contents"><pre class="screen"> tid %user %kernel (of 20002 ticks) 0 0.00% 87.88% 32169 5.24% 0.03% 9815 3.33% 0.36% 9859 0.95% 0.00% 3611 0.56% 0.12% 9861 0.62% 0.01% 11106 0.37% 0.02% 32167 0.08% 0.08% 3897 0.01% 0.08% 3800 0.03% 0.00% 2886 0.02% 0.00% 3243 0.00% 0.01% 3862 0.01% 0.00% 3782 0.00% 0.00% 21767 0.00% 0.00% 2522 0.00% 0.00% 3883 0.00% 0.00% 3775 0.00% 0.00% 3943 0.00% 0.00% 3873 0.00% 0.00%</pre></div></div></div><ul class="docnav"><li class="previous"><a accesskey="p" href="paracallgraph.html"><strong>Prev</strong>5.3.2. Call Graph Tracing</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="timeoutssect.html"><strong>Next</strong>5.3.4. Monitoring Polling Applications</a></li></ul></body></html> 
 |