| 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="kernelprofsect"> |
| 7 |
<title>Kernel Profiling</title> |
| 8 |
|
| 9 |
|
| 10 |
<remark> |
| 11 |
WAR STORY: Kernel Profiling http://sourceware.org/systemtap/wiki/WSKernelProfile?highlight=((WarStories)) |
| 12 |
</remark> |
| 13 |
|
| 14 |
<remark> |
| 15 |
http://sourceware.org/systemtap/examples/process/pf2.stp |
| 16 |
</remark> |
| 17 |
|
| 18 |
|
| 19 |
<para>In <xref linkend="countcallssect"/>, you can revise the wildcards used in the probe to target <emphasis>all</emphasis> kernel functions. This can be useful if you are interested in indentifying what the kernel is performing over a specific time period.</para> |
| 20 |
|
| 21 |
<para>However, doing so can cause considerable stress on the machine. In addition, this does not provide any indication of whether a specific function is being called too often during small time increments.</para> |
| 22 |
|
| 23 |
<para>This section describes how to profile the kernel properly. <xref linkend="kernelprof"/> does this by providing a list of the top ten kernel functions called within a specific time period, and how many times each function was called during that time.</para> |
| 24 |
|
| 25 |
|
| 26 |
<formalpara id="kernelprof"> |
| 27 |
<title>kernelprof.stp</title> |
| 28 |
<para> |
| 29 |
<programlisting>#! /usr/bin/env stap |
| 30 |
|
| 31 |
global profile, pcount |
| 32 |
probe timer.profile { |
| 33 |
pcount <<< 1 |
| 34 |
fn = probefunc () |
| 35 |
if (fn != "") profile[fn] <<< 1 |
| 36 |
} |
| 37 |
probe timer.ms(5000) { |
| 38 |
printf ("\n--- %d samples recorded:\n", @count(pcount)) |
| 39 |
foreach (f in profile- limit 10) { |
| 40 |
printf ("%-30s\t%6d\n", f, @count(profile[f])) |
| 41 |
} |
| 42 |
delete profile |
| 43 |
delete pcount |
| 44 |
} |
| 45 |
</programlisting> |
| 46 |
</para> |
| 47 |
</formalpara> |
| 48 |
|
| 49 |
<para><xref linkend="kernelprof"/> records and outputs kernel functions called every 5 seconds. You can change this setting by editing <command>probe timer.ms(5000)</command> accordingly. <xref linkend="kernelprofoutput"/> contains an excerpt of the output over a 20-second period:</para> |
| 50 |
|
| 51 |
<example id="kernelprofoutput"> |
| 52 |
<title><xref linkend="kernelprof"/> Sample Output</title> |
| 53 |
<screen>[...] |
| 54 |
--- 10002 samples recorded: |
| 55 |
sys_recvfrom 1 |
| 56 |
memmove 1 |
| 57 |
__copy_from_user_ll 17 |
| 58 |
__copy_to_user_ll 15 |
| 59 |
mwait_idle 5868 |
| 60 |
link_path_walk 1 |
| 61 |
kfree 1 |
| 62 |
fget_light 1 |
| 63 |
audit_syscall_exit 1 |
| 64 |
__d_lookup 1 |
| 65 |
|
| 66 |
--- 10002 samples recorded: |
| 67 |
sysfs_read_file 1 |
| 68 |
free_poll_entry 1 |
| 69 |
syscall_exit_work 1 |
| 70 |
profile_hit 1 |
| 71 |
do_page_fault 2 |
| 72 |
_read_lock 3 |
| 73 |
kmap_atomic 4 |
| 74 |
strncpy_from_user 1 |
| 75 |
find_vma_prepare 1 |
| 76 |
__copy_from_user_ll 12 |
| 77 |
|
| 78 |
--- 10000 samples recorded: |
| 79 |
system_call 4 |
| 80 |
unix_stream_sendmsg 1 |
| 81 |
__d_path 1 |
| 82 |
do_page_fault 2 |
| 83 |
kmap_atomic 1 |
| 84 |
find_vma 1 |
| 85 |
__copy_to_user_ll 16 |
| 86 |
__copy_from_user_ll 10 |
| 87 |
mwait_idle 5759 |
| 88 |
memcpy_fromiovec 1 |
| 89 |
|
| 90 |
--- 10004 samples recorded: |
| 91 |
syscall_exit 1 |
| 92 |
__d_path 1 |
| 93 |
fput 2 |
| 94 |
do_page_fault 4 |
| 95 |
strncpy_from_user 1 |
| 96 |
may_open 1 |
| 97 |
ide_outb 1 |
| 98 |
ide_outsw 1 |
| 99 |
__copy_to_user_ll 11 |
| 100 |
__copy_from_user_ll 14 |
| 101 |
[...]</screen> |
| 102 |
</example> |
| 103 |
|
| 104 |
<para><xref linkend="kernelprof"/> allows you to identify interesting kernel-specific performance facts about the system, such as kernel-intensive workloads and idle times (in this case, <command>mwait_idle</command>. Note that <xref linkend="kernelprof"/> does not count user-space functions, although it counts all kernel functions as part of the sample (even if the script cannot identify from which specific kernel function a call originated.</para> |
| 105 |
|
| 106 |
</section> |
| 107 |
|