| 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="topsyssect"> |
| 7 |
<title>Tracking Most Frequently Used System Calls</title> |
| 8 |
<indexterm> |
| 9 |
<primary>script examples</primary> |
| 10 |
<secondary>monitoring system calls</secondary> |
| 11 |
</indexterm> |
| 12 |
|
| 13 |
<indexterm> |
| 14 |
<primary>examples of SystemTap scripts</primary> |
| 15 |
<secondary>monitoring system calls</secondary> |
| 16 |
</indexterm> |
| 17 |
|
| 18 |
<indexterm> |
| 19 |
<primary>monitoring system calls</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, monitoring</primary> |
| 32 |
<secondary>examples of SystemTap scripts</secondary> |
| 33 |
</indexterm> |
| 34 |
|
| 35 |
<para> |
| 36 |
<xref linkend="timeouts"/> from <xref linkend="timeoutssect"/> |
| 37 |
helps you identify which applications |
| 38 |
are polling by examining a small subset of system calls ( |
| 39 |
<command>poll</command>, |
| 40 |
<command>select</command>, |
| 41 |
<command>epoll</command>, |
| 42 |
<command>itimer</command>, |
| 43 |
<command>futex</command>, |
| 44 |
<command>nanosleep</command>, and |
| 45 |
<command>signal</command>). |
| 46 |
However, in some systems, an excessive number of system calls |
| 47 |
outside that small subset |
| 48 |
might be responsible for time spent in the |
| 49 |
kernel. If you suspect that an application is using |
| 50 |
system calls excessively, you need to |
| 51 |
identify the most frequently used system calls on the |
| 52 |
system. To do this, use <xref linkend="topsys"/>. |
| 53 |
</para> |
| 54 |
|
| 55 |
<formalpara id="topsys"> |
| 56 |
<title>topsys.stp</title> |
| 57 |
<para> |
| 58 |
<programlisting><xi:include parse="text" href="../testsuite/systemtap.examples/profiling/topsys.stp" xmlns:xi="http://www.w3.org/2001/XInclude" /></programlisting> |
| 59 |
</para> |
| 60 |
</formalpara> |
| 61 |
|
| 62 |
<para> |
| 63 |
<xref linkend="topsys"/> lists the top 20 system calls used by the system per 5-second interval. It also lists |
| 64 |
how many times each system call was used during that period. Refer to <xref linkend="topsysoutput"/> for a sample output. |
| 65 |
</para> |
| 66 |
|
| 67 |
<indexterm> |
| 68 |
<primary>script examples</primary> |
| 69 |
<secondary>timer.s(), sample usage</secondary> |
| 70 |
</indexterm> |
| 71 |
|
| 72 |
<indexterm> |
| 73 |
<primary>examples of SystemTap scripts</primary> |
| 74 |
<secondary>timer.s(), sample usage</secondary> |
| 75 |
</indexterm> |
| 76 |
|
| 77 |
<indexterm> |
| 78 |
<primary>timer.s(), sample usage</primary> |
| 79 |
<secondary>examples of SystemTap scripts</secondary> |
| 80 |
</indexterm> |
| 81 |
|
| 82 |
|
| 83 |
<example id="topsysoutput"> |
| 84 |
<title><xref linkend="topsys"/> Sample Output</title> |
| 85 |
<screen>-------------------------------------------------------------- |
| 86 |
SYSCALL COUNT |
| 87 |
gettimeofday 1857 |
| 88 |
read 1821 |
| 89 |
ioctl 1568 |
| 90 |
poll 1033 |
| 91 |
close 638 |
| 92 |
open 503 |
| 93 |
select 455 |
| 94 |
write 391 |
| 95 |
writev 335 |
| 96 |
futex 303 |
| 97 |
recvmsg 251 |
| 98 |
socket 137 |
| 99 |
clock_gettime 124 |
| 100 |
rt_sigprocmask 121 |
| 101 |
sendto 120 |
| 102 |
setitimer 106 |
| 103 |
stat 90 |
| 104 |
time 81 |
| 105 |
sigreturn 72 |
| 106 |
fstat 66 |
| 107 |
--------------------------------------------------------------</screen> |
| 108 |
</example> |
| 109 |
<!--probe kernel.function(@1) { # probe function passed as argument from stdin |
| 110 |
called[probefunc()] <<< 1 # add a count efficiently |
| 111 |
} |
| 112 |
global called |
| 113 |
probe end,timer.ms(30000) { |
| 114 |
foreach (fn+ in called) # Sort by function name |
| 115 |
# (fn in called-) # Sort by call count (in decreasing order) |
| 116 |
printf("%s %d\n", fn, @count(called[fn])) |
| 117 |
exit() |
| 118 |
}--> |
| 119 |
|
| 120 |
</section> |
| 121 |
|