| 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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153  | <?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.4. Monitoring Polling Applications</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="threadtimessect.html" title="5.3.3. Determining Time Spent in Kernel and User Space" /><link rel="next" href="topsyssect.html" title="5.3.5. Tracking Most Frequently Used System Calls" /></head><body><p id="title"></p><ul class="docnav top"><li class="previous"><a accesskey="p" href="threadtimessect.html"><strong>Prev</strong></a></li><li class="home">SystemTap Beginners Guide</li><li class="next"><a accesskey="n" href="topsyssect.html"><strong>Next</strong></a></li></ul><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="timeoutssect"> </a>5.3.4. Monitoring Polling Applications</h3></div></div></div><a id="id5246" class="indexterm"></a><a id="id5249" class="indexterm"></a><a id="id5252" class="indexterm"></a><a id="id5255" class="indexterm"></a><div class="para">	This section describes how to identify and monitor which applications are polling. Doing so allows you to track	unnecessary or excessive polling, which can help you pinpoint areas for improvement in terms of CPU usage	and power savings. </div><div class="para"><div xmlns:d="http://docbook.org/ns/docbook" class="title">timeout.stp</div> <pre class="programlisting">#! /usr/bin/env stap # Copyright (C) 2009-2018 Red Hat, Inc. # Written by Ulrich Drepper <drepper@redhat.com> # Modified by William Cohen <wcohen@redhat.com> global process, timeout_count, to global poll_timeout, epoll_timeout, select_timeout, itimer_timeout global nanosleep_timeout, futex_timeout, signal_timeout probe syscall.{poll,epoll_wait} { if (timeout) to[pid()]=timeout } probe syscall.poll.return { if (retval == 0 && to[pid()] > 0 ) { poll_timeout[pid()]++ timeout_count[pid()]++ process[pid()] = execname() delete to[pid()] } } probe syscall.epoll_wait.return { if (retval == 0 && to[pid()] > 0 ) { epoll_timeout[pid()]++ timeout_count[pid()]++ process[pid()] = execname() delete to[pid()] } } probe syscall.select.return { if (retval == 0) { select_timeout[pid()]++ timeout_count[pid()]++ process[pid()] = execname() } } probe syscall.futex.return { if (errno_str(retval) == "ETIMEDOUT") { futex_timeout[pid()]++ timeout_count[pid()]++ process[pid()] = execname() } } probe syscall.nanosleep.return { if (retval == 0) { nanosleep_timeout[pid()]++ timeout_count[pid()]++ process[pid()] = execname() } } probe kernel.function("it_real_fn") { itimer_timeout[pid()]++ timeout_count[pid()]++ process[pid()] = execname() } probe syscall.rt_sigtimedwait.return { if (errno_str(retval) == "EAGAIN") { signal_timeout[pid()]++ timeout_count[pid()]++ process[pid()] = execname() } } probe syscall.exit { if (pid() in process) { delete process[pid()] delete timeout_count[pid()] delete poll_timeout[pid()] delete epoll_timeout[pid()] delete select_timeout[pid()] delete itimer_timeout[pid()] delete futex_timeout[pid()] delete nanosleep_timeout[pid()] delete signal_timeout[pid()] } } probe timer.s(1) { ansi_clear_screen() printf (" pid | poll select epoll itimer futex nanosle signal| process\n") foreach (p in timeout_count- limit 20) { printf ("%5d |%7d %7d %7d %7d %7d %7d %7d| %-.38s\n", p, poll_timeout[p], select_timeout[p], epoll_timeout[p], itimer_timeout[p], futex_timeout[p], nanosleep_timeout[p], signal_timeout[p], process[p]) } } global prom_arr probe prometheus { foreach (p in timeout_count- limit 20) { prom_arr[poll_timeout[p], select_timeout[p], epoll_timeout[p], itimer_timeout[p], futex_timeout[p], nanosleep_timeout[p], signal_timeout[p]] = process[p] } @prometheus_dump_array7(prom_arr, "process_timeouts", "poll_timeout", "select_timeout", "epoll_timeout", "itimer_timeout", "futex_timeout", "nanosleep_timeout", "signal_timeout") delete prom_arr } </pre> </div><div class="para"> <a class="xref" href="timeoutssect.html#timeouts">timeout.stp</a> tracks how many times each	of the following system calls completed	due to time expiring rather than due to an actual event	occurring: </div><div xmlns:d="http://docbook.org/ns/docbook" class="itemizedlist"><ul><li class="listitem"><div class="para"><code class="command">poll</code></div></li><li class="listitem"><div class="para"><code class="command">select</code></div></li><li class="listitem"><div class="para"><code class="command">epoll</code></div></li><li class="listitem"><div class="para"><code class="command">itimer</code></div></li><li class="listitem"><div class="para"><code class="command">futex</code></div></li><li class="listitem"><div class="para"><code class="command">nanosleep</code></div></li><li class="listitem"><div class="para"><code class="command">signal</code></div></li></ul></div><a id="id5288" class="indexterm"></a><a id="id5291" class="indexterm"></a><a id="id5294" class="indexterm"></a><div class="example"><a id="timeoutsoutput"> </a><p class="title"><strong>Example 5.16. <a class="xref" href="timeoutssect.html#timeouts">timeout.stp</a> Sample Output</strong></p><div class="example-contents"><pre class="screen"> uid | poll select epoll itimer futex nanosle signal| process 28937 | 148793 0 0 4727 37288 0 0| firefox 22945 | 0 56949 0 1 0 0 0| scim-bridge 0 | 0 0 0 36414 0 0 0| swapper 4275 | 23140 0 0 1 0 0 0| mixer_applet2 4191 | 0 14405 0 0 0 0 0| scim-launcher 22941 | 7908 1 0 62 0 0 0| gnome-terminal 4261 | 0 0 0 2 0 7622 0| escd 3695 | 0 0 0 0 0 7622 0| gdm-binary 3483 | 0 7206 0 0 0 0 0| dhcdbd 4189 | 6916 0 0 2 0 0 0| scim-panel-gtk 1863 | 5767 0 0 0 0 0 0| iscsid 2562 | 0 2881 0 1 0 1438 0| pcscd 4257 | 4255 0 0 1 0 0 0| gnome-power-man 4278 | 3876 0 0 60 0 0 0| multiload-apple 4083 | 0 1331 0 1728 0 0 0| Xorg 3921 | 1603 0 0 0 0 0 0| gam_server 4248 | 1591 0 0 0 0 0 0| nm-applet 3165 | 0 1441 0 0 0 0 0| xterm 29548 | 0 1440 0 0 0 0 0| httpd 1862 | 0 0 0 0 0 1438 0| iscsid</pre></div></div><div class="para">	You can increase the sample time by editing the second probe (<code class="command">timer.s(1)</code>).	The output of <a class="xref" href="timeoutssect.html#timeouts">timeout.stp</a> contains the name and UID of the top 20 polling applications,	along with how many times each application performed each polling system call (over time). <a class="xref" href="timeoutssect.html#timeoutsoutput">Example 5.16, “timeout.stp Sample Output”</a> contains an excerpt of the script.	In this particular example firefox is doing an excessive amount of	polling due to a plugin module. </div></div><ul class="docnav"><li class="previous"><a accesskey="p" href="threadtimessect.html"><strong>Prev</strong>5.3.3. Determining Time Spent in Kernel and User ...</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="topsyssect.html"><strong>Next</strong>5.3.5. Tracking Most Frequently Used System Calls</a></li></ul></body></html> 
 |