| 1 |
<?xml version='1.0'?> |
| 2 |
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [ |
| 3 |
]> |
| 4 |
|
| 5 |
|
| 6 |
<section id="syscallsbyprocpidsect"> |
| 7 |
<title>Tracking System Call Volume Per Process</title> |
| 8 |
<indexterm> |
| 9 |
<primary>script examples</primary> |
| 10 |
<secondary>monitoring system calls (volume per process)</secondary> |
| 11 |
</indexterm> |
| 12 |
|
| 13 |
<indexterm> |
| 14 |
<primary>examples of SystemTap scripts</primary> |
| 15 |
<secondary>monitoring system calls (volume per process)</secondary> |
| 16 |
</indexterm> |
| 17 |
|
| 18 |
<indexterm> |
| 19 |
<primary>monitoring system calls (volume per process)</primary> |
| 20 |
<secondary>examples of SystemTap scripts</secondary> |
| 21 |
</indexterm> |
| 22 |
|
| 23 |
<!-- |
| 24 |
<indexterm> |
| 25 |
<primary>counting function calls</primary> |
| 26 |
<secondary>examples of SystemTap scripts</secondary> |
| 27 |
</indexterm> |
| 28 |
--> |
| 29 |
|
| 30 |
<indexterm> |
| 31 |
<primary>system calls volume (per process), monitoring</primary> |
| 32 |
<secondary>examples of SystemTap scripts</secondary> |
| 33 |
</indexterm> |
| 34 |
|
| 35 |
<remark> |
| 36 |
uses systemtap/testsuite/systemtap.examples/process/syscalls_by_p*.stp |
| 37 |
</remark> |
| 38 |
|
| 39 |
<para> |
| 40 |
This section illustrates how to determine which processes |
| 41 |
are performing the highest volume of system calls. In |
| 42 |
previous sections, we've described how to monitor the top system |
| 43 |
calls used by the system over time (<xref linkend="topsyssect"/>). |
| 44 |
We've also described how to identify which applications use a |
| 45 |
specific set of "polling suspect" system calls the most |
| 46 |
(<xref linkend="timeoutssect"/>). Monitoring the volume of |
| 47 |
system calls made by each process provides more data in |
| 48 |
investigating your system for polling processes and other resource |
| 49 |
hogs. |
| 50 |
</para> |
| 51 |
|
| 52 |
<formalpara id="syscallsbyprocpid"> |
| 53 |
<title>syscalls_by_proc.stp</title> |
| 54 |
<para> |
| 55 |
<programlisting><xi:include parse="text" href="../testsuite/systemtap.examples/process/syscalls_by_proc.stp" xmlns:xi="http://www.w3.org/2001/XInclude" /></programlisting> |
| 56 |
</para> |
| 57 |
</formalpara> |
| 58 |
|
| 59 |
<para> |
| 60 |
<xref linkend="syscallsbyprocpid"/> lists the top 20 processes performing the |
| 61 |
highest number of system calls. It also lists how many system calls each process |
| 62 |
performed during the time period. Refer to |
| 63 |
<xref linkend="syscallsbyprocpidoutput"/> for a sample output. |
| 64 |
|
| 65 |
</para> |
| 66 |
|
| 67 |
<example id="syscallsbyprocpidoutput"> |
| 68 |
<title><xref linkend="topsys"/> Sample Output</title> |
| 69 |
<screen>Collecting data... Type Ctrl-C to exit and display results |
| 70 |
#SysCalls Process Name |
| 71 |
1577 multiload-apple |
| 72 |
692 synergyc |
| 73 |
408 pcscd |
| 74 |
376 mixer_applet2 |
| 75 |
299 gnome-terminal |
| 76 |
293 Xorg |
| 77 |
206 scim-panel-gtk |
| 78 |
95 gnome-power-man |
| 79 |
90 artsd |
| 80 |
85 dhcdbd |
| 81 |
84 scim-bridge |
| 82 |
78 gnome-screensav |
| 83 |
66 scim-launcher |
| 84 |
[...]</screen> |
| 85 |
</example> |
| 86 |
|
| 87 |
<para> |
| 88 |
To display the process IDs instead of the process names, |
| 89 |
use the following script instead. |
| 90 |
</para> |
| 91 |
|
| 92 |
<formalpara id="syscallsbypid"> |
| 93 |
<title>syscalls_by_pid.stp</title> |
| 94 |
<para> |
| 95 |
<programlisting><xi:include parse="text" href="../testsuite/systemtap.examples/process/syscalls_by_pid.stp" xmlns:xi="http://www.w3.org/2001/XInclude" /></programlisting> |
| 96 |
</para> |
| 97 |
</formalpara> |
| 98 |
|
| 99 |
|
| 100 |
<para> |
| 101 |
As indicated in the output, you need to manually exit the script in order to display the |
| 102 |
results. You can add a timed expiration to either script by simply adding |
| 103 |
a <command>timer.s()</command> probe; for example, to instruct the script to expire after |
| 104 |
5 seconds, add the following probe to the script: |
| 105 |
</para> |
| 106 |
|
| 107 |
<screen>probe timer.s(5) |
| 108 |
{ |
| 109 |
exit() |
| 110 |
}</screen> |
| 111 |
|
| 112 |
<!--probe kernel.function(@1) { # probe function passed as argument from stdin |
| 113 |
called[probefunc()] <<< 1 # add a count efficiently |
| 114 |
} |
| 115 |
global called |
| 116 |
probe end,timer.ms(30000) { |
| 117 |
foreach (fn+ in called) # Sort by function name |
| 118 |
# (fn in called-) # Sort by call count (in decreasing order) |
| 119 |
printf("%s %d\n", fn, @count(called[fn])) |
| 120 |
exit() |
| 121 |
}--> |
| 122 |
|
| 123 |
</section> |
| 124 |
|