diff options
5 files changed, 252 insertions, 8 deletions
diff --git a/doc/SystemTap_Beginners_Guide/en-US/Useful_Scripts-disktop.xml b/doc/SystemTap_Beginners_Guide/en-US/Useful_Scripts-disktop.xml index 0c191cff..69877c5b 100644 --- a/doc/SystemTap_Beginners_Guide/en-US/Useful_Scripts-disktop.xml +++ b/doc/SystemTap_Beginners_Guide/en-US/Useful_Scripts-disktop.xml @@ -95,19 +95,19 @@ probe end{ <para><xref linkend="scriptdisktop"/> outputs the top ten processes responsible for the heaviest reads/writes to disk. <xref linkend="disktopoutput"/> displays a sample output for this script, and includes the following data per listed process:</para> <itemizedlist> - <listitem><para><command>UID</command> — user ID. A user ID of <command>0</command> refers to the root user.</para></listitem> + <listitem><para><computeroutput>UID</computeroutput> — user ID. A user ID of <computeroutput>0</computeroutput> refers to the root user.</para></listitem> - <listitem><para><command>PID</command> — the ID of the listed process.</para></listitem> + <listitem><para><computeroutput>PID</computeroutput> — the ID of the listed process.</para></listitem> - <listitem><para><command>PPID</command> — the process ID of the listed process's <emphasis>parent process</emphasis>.</para></listitem> + <listitem><para><computeroutput>PPID</computeroutput> — the process ID of the listed process's <emphasis>parent process</emphasis>.</para></listitem> - <listitem><para><command>CMD</command> — the name of the listed process.</para></listitem> + <listitem><para><computeroutput>CMD</computeroutput> — the name of the listed process.</para></listitem> - <listitem><para><command>DEVICE</command> — which storage device the listed process is reading from or writing to.</para></listitem> + <listitem><para><computeroutput>DEVICE</computeroutput> — which storage device the listed process is reading from or writing to.</para></listitem> - <listitem><para><command>T</command> — the type of action performed by the listed process; <command>W</command> refers to write, while <command>R</command> refers to read.</para></listitem> + <listitem><para><computeroutput>T</computeroutput> — the type of action performed by the listed process; <computeroutput>W</computeroutput> refers to write, while <computeroutput>R</computeroutput> refers to read.</para></listitem> - <listitem><para><command>BYTES</command> — the amount of data read to or written from disk.</para></listitem> + <listitem><para><computeroutput>BYTES</computeroutput> — the amount of data read to or written from disk.</para></listitem> </itemizedlist> diff --git a/doc/SystemTap_Beginners_Guide/en-US/Useful_Scripts-functioncalls.xml b/doc/SystemTap_Beginners_Guide/en-US/Useful_Scripts-functioncalls.xml index 76a2fad9..4ebfa6fa 100644 --- a/doc/SystemTap_Beginners_Guide/en-US/Useful_Scripts-functioncalls.xml +++ b/doc/SystemTap_Beginners_Guide/en-US/Useful_Scripts-functioncalls.xml @@ -22,7 +22,7 @@ no script in examples <title>countcalls.stp</title> <para> <programlisting> -probe kernel.function(@1) { # probe every function in any C file under mm/ +probe kernel.function(@1) { # probe function passed as argument from stdin called[probefunc()] <<< 1 # add a count efficiently } global called diff --git a/doc/SystemTap_Beginners_Guide/en-US/Useful_Scripts-kernelprofiling.xml b/doc/SystemTap_Beginners_Guide/en-US/Useful_Scripts-kernelprofiling.xml new file mode 100644 index 00000000..0fd172dd --- /dev/null +++ b/doc/SystemTap_Beginners_Guide/en-US/Useful_Scripts-kernelprofiling.xml @@ -0,0 +1,111 @@ +<?xml version='1.0'?> +<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [ +]> + + + <section id="kernelprofsect"> + <title>Kernel Profiling</title> + + +<remark> + WAR STORY: Kernel Profiling http://sourceware.org/systemtap/wiki/WSKernelProfile?highlight=((WarStories)) +</remark> + +<remark> + http://sourceware.org/systemtap/examples/process/pf2.stp +</remark> + + +<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> + +<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> + +<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> + + +<formalpara id="kernelprof"> + <title>kernelprof.stp</title> +<para> +<programlisting> +#! /usr/bin/env stap
+
+global profile, pcount
+probe timer.profile {
+pcount <<< 1
+ fn = probefunc ()
+ if (fn != "") profile[fn] <<< 1
+}
+probe timer.ms(5000) {
+ printf ("\n--- %d samples recorded:\n", @count(pcount))
+ foreach (f in profile- limit 10) {
+ printf ("%-30s\t%6d\n", f, @count(profile[f]))
+ }
+ delete profile
+ delete pcount
+}
+ +</programlisting> +</para> +</formalpara> + +<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> + +<example id="kernelprofoutput"> + <title><xref linkend="kernelprof"/> Sample Output</title> +<screen> +[...] +--- 10002 samples recorded:
+sys_recvfrom 1
+memmove 1
+__copy_from_user_ll 17
+__copy_to_user_ll 15
+mwait_idle 5868
+link_path_walk 1
+kfree 1
+fget_light 1
+audit_syscall_exit 1
+__d_lookup 1
+ +--- 10002 samples recorded:
+sysfs_read_file 1
+free_poll_entry 1
+syscall_exit_work 1
+profile_hit 1
+do_page_fault 2
+_read_lock 3
+kmap_atomic 4
+strncpy_from_user 1
+find_vma_prepare 1
+__copy_from_user_ll 12
+ +--- 10000 samples recorded:
+system_call 4
+unix_stream_sendmsg 1
+__d_path 1
+do_page_fault 2
+kmap_atomic 1
+find_vma 1
+__copy_to_user_ll 16
+__copy_from_user_ll 10
+mwait_idle 5759
+memcpy_fromiovec 1
+ +--- 10004 samples recorded:
+syscall_exit 1
+__d_path 1
+fput 2
+do_page_fault 4
+strncpy_from_user 1
+may_open 1
+ide_outb 1
+ide_outsw 1
+__copy_to_user_ll 11
+__copy_from_user_ll 14
+[...] +</screen> +</example> + +<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> + + </section> + diff --git a/doc/SystemTap_Beginners_Guide/en-US/Useful_Scripts-nettop.xml b/doc/SystemTap_Beginners_Guide/en-US/Useful_Scripts-nettop.xml new file mode 100644 index 00000000..d56cbfc1 --- /dev/null +++ b/doc/SystemTap_Beginners_Guide/en-US/Useful_Scripts-nettop.xml @@ -0,0 +1,131 @@ +<?xml version='1.0'?> +<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [ +]> + + + <section id="nettopsect"> + <title>Kernel Profiling</title> + + +<remark> + WAR STORY: Top network users by PID http://sourceware.org/systemtap/wiki/WSNetTop?highlight=((WarStories)) +</remark> + +<remark> + probably http://sourceware.org/systemtap/examples/network/nettop.stp +</remark> + + +<para>This section describes how to profile network activity. <xref linkend="nettop"/> provides a glimpse into how much network traffic each process is generating on a machine.</para> + +<formalpara id="nettop"> + <title>nettop.stp</title> +<para> +<programlisting> +global ifxmit, ifrecv, ifdevs, ifpid, execname, user + +probe netdev.transmit +{ + p = pid() + execname[p] = execname() + user[p] = uid() + ifdevs[p, dev_name] = dev_name + ifxmit[p, dev_name] <<< length + ifpid[p, dev_name] ++ +} + +probe netdev.receive +{ + p = pid() + execname[p] = execname() + user[p] = uid() + ifdevs[p, dev_name] = dev_name + ifrecv[p, dev_name] <<< length + ifpid[p, dev_name] ++ +} + + +function print_activity() +{ + printf("%5s %5s %-7s %7s %7s %7s %7s %-15s\n", + "PID", "UID", "DEV", "XMIT_PK", "RECV_PK", + "XMIT_KB", "RECV_KB", "COMMAND") + + foreach ([pid, dev] in ifpid-) { + n_xmit = @count(ifxmit[pid, dev]) + n_recv = @count(ifrecv[pid, dev]) + printf("%5d %5d %-7s %7d %7d %7d %7d %-15s\n", + pid, user[pid], dev, n_xmit, n_recv, + n_xmit ? @sum(ifxmit[pid, dev])/1024 : 0, + n_recv ? @sum(ifrecv[pid, dev])/1024 : 0, + execname[pid]) + } + + print("\n") + + delete execname + delete user + delete ifdevs + delete ifxmit + delete ifrecv + delete ifpid +} + +probe timer.ms(5000) +{ + print_activity() +} +</programlisting> +</para> +</formalpara> + +<para><xref linkend="nettop"/> tracks which processes are generating network traffic on the system, and provides the following information about each process:</para> + +<itemizedlist> + <listitem><para><computeroutput>PID</computeroutput> — the ID of the listed process.</para></listitem> + + <listitem><para><computeroutput>UID</computeroutput> — user ID. A user ID of <computeroutput>0</computeroutput> refers to the root user.</para></listitem> + + <listitem><para><computeroutput>DEV</computeroutput> — which ethernet device the process used to send / receive data (e.g. eth0, eth1)</para></listitem> + <listitem><para><computeroutput>XMIT_PK</computeroutput> — number of packets transmitted by the process</para></listitem> + <listitem><para><computeroutput>RECV_PK</computeroutput> — number of packets received by the process</para></listitem> + <listitem><para><computeroutput>XMIT_KB</computeroutput> — amount of data sent by the process, in kilobytes</para></listitem> + <listitem><para><computeroutput>RECV_KB</computeroutput> — amount of data received by the service, in kilobytes</para></listitem> +</itemizedlist> + +<para><xref linkend="nettop"/> provides network profile sampling every 5 seconds. You can change this setting by editing <command>probe timer.ms(5000)</command> accordingly. <xref linkend="nettopoutput"/> contains an excerpt of the output from <xref linkend="nettop"/> over a 20-second period:</para> + + +<example id="nettopoutput"> + <title><xref linkend="nettop"/> Sample Output</title> +<screen> +[...] + PID UID DEV XMIT_PK RECV_PK XMIT_KB RECV_KB COMMAND
+ 0 0 eth0 0 5 0 0 swapper
+11178 0 eth0 2 0 0 0 synergyc
+
+ PID UID DEV XMIT_PK RECV_PK XMIT_KB RECV_KB COMMAND
+ 2886 4 eth0 79 0 5 0 cups-polld
+11362 0 eth0 0 61 0 5 firefox
+ 0 0 eth0 3 32 0 3 swapper
+ 2886 4 lo 4 4 0 0 cups-polld
+11178 0 eth0 3 0 0 0 synergyc
+
+ PID UID DEV XMIT_PK RECV_PK XMIT_KB RECV_KB COMMAND
+ 0 0 eth0 0 6 0 0 swapper
+ 2886 4 lo 2 2 0 0 cups-polld
+11178 0 eth0 3 0 0 0 synergyc
+ 3611 0 eth0 0 1 0 0 Xorg
+
+ PID UID DEV XMIT_PK RECV_PK XMIT_KB RECV_KB COMMAND
+ 0 0 eth0 3 42 0 2 swapper
+11178 0 eth0 43 1 3 0 synergyc
+11362 0 eth0 0 7 0 0 firefox
+ 3897 0 eth0 0 1 0 0 multiload-apple
+[...] +</screen> +</example> + + + </section> + diff --git a/doc/SystemTap_Beginners_Guide/en-US/Useful_SystemTap_Scripts.xml b/doc/SystemTap_Beginners_Guide/en-US/Useful_SystemTap_Scripts.xml index fb2dba54..ecfc2341 100644 --- a/doc/SystemTap_Beginners_Guide/en-US/Useful_SystemTap_Scripts.xml +++ b/doc/SystemTap_Beginners_Guide/en-US/Useful_SystemTap_Scripts.xml @@ -29,7 +29,9 @@ <xi:include href="Useful_Scripts-inodewatch.xml" xmlns:xi="http://www.w3.org/2001/XInclude" /> <xi:include href="Useful_Scripts-inodewatch2.xml" xmlns:xi="http://www.w3.org/2001/XInclude" /> <xi:include href="Useful_Scripts-functioncalls.xml" xmlns:xi="http://www.w3.org/2001/XInclude" /> + <xi:include href="Useful_Scripts-kernelprofiling.xml" xmlns:xi="http://www.w3.org/2001/XInclude" /> <xi:include href="Useful_Scripts-futexes.xml" xmlns:xi="http://www.w3.org/2001/XInclude" /> + <xi:include href="Useful_Scripts-nettop.xml" xmlns:xi="http://www.w3.org/2001/XInclude" /> <!-- <xi:include href="Useful_Scripts-Network.xml" xmlns:xi="http://www.w3.org/2001/XInclude" /> <xi:include href="Useful_Scripts-Signals.xml" xmlns:xi="http://www.w3.org/2001/XInclude" /> <xi:include href="Useful_Scripts-Syscalls.xml" xmlns:xi="http://www.w3.org/2001/XInclude" /> |