diff options
Diffstat (limited to 'systemtap/org.eclipse.linuxtools.systemtap.ui.ide/documentation/html/reference/exampleScripts.html')
-rw-r--r-- | systemtap/org.eclipse.linuxtools.systemtap.ui.ide/documentation/html/reference/exampleScripts.html | 174 |
1 files changed, 174 insertions, 0 deletions
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/documentation/html/reference/exampleScripts.html b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/documentation/html/reference/exampleScripts.html new file mode 100644 index 0000000000..19185a763d --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/documentation/html/reference/exampleScripts.html @@ -0,0 +1,174 @@ +<a href="../toc.html">Table of Contents</a> > <a href="reference.html">Reference</a> + +<h2> +Example SystemTap Scripts +</h2> + +What follows is a few SystemTap Scripts that you may use in SystemTap GUI, taken from and linked to +<a href="http://sourceware.org/systemtap/documentation.html">http://sourceware.org/systemtap/documentation.html</a> + +<br><br>There is also a +<a href="http://sourceware.org/systemtap/examples/demo_script.txt">description of the examples</a>. + +<h3> +top.stp - Prints the top 20 system calls (<a href="http://sourceware.org/systemtap/examples/top.stp">online source</a>) +</h3> + +<code><pre> +#!/usr/bin/env stap +# +# This script continuously lists the top 20 systemcalls on the system +# + +global syscalls + +function print_top () { + cnt=0 + log ("SYSCALL\t\t\t\tCOUNT") + foreach ([name] in syscalls-) { + printf("%-20s\t\t%5d\n",name, syscalls[name]) + if (cnt++ == 20) + break + } + printf("--------------------------------------\n") + delete syscalls +} + +probe kernel.function("sys_*") { + syscalls[probefunc()]++ +} + +# print top syscalls every 5 seconds +probe timer.ms(5000) { + print_top () +</pre></code> + + +<h3> +prof.stp - Simple profiling (<a href="http://sourceware.org/systemtap/examples/prof.stp">online source</a>) +</h3> + +<code><pre> +#!/usr/bin/env stap + +# This is an example of profiling a specific command or pid. +# It works by recording the time when a system call is entered +# exited. + +# Usage: prof.stp -c "top -n5" +# Will start up "top" and after 5 iterations, will exit. +# +# Usage: prof.stp -x 3323 +# Will profile pid 3323 until it ^c is hit. +# + +probe kernel.function("sys_*") { + if (target() == tid()) + calltime[tid()] = gettimeofday_us() +} + +probe kernel.function("sys_*").return { + if (target() != tid()) next + now = gettimeofday_us() + c = calltime[tid()] + if (!c) next + ttime[probefunc()] <<< now - c + delete calltime[tid()] +} + +probe end { + printf("\n") + foreach (x in ttime) + printf("%-20s\tcalls:%6d\tavg time (ms):%5d\ttotal(ms):%7d\n", + x, @count(ttime[x]), @avg(ttime[x]), @sum(ttime[x])) +} + +global calltime, ttime +</pre></code> + + +<h3> +keyhack.stp - Modifying variables in the kernel. (<a href="http://sourceware.org/systemtap/examples/keyhack.stp">online source</a>) +</h3> + +<code><pre> +#! /usr/bin/env stap + +# This is not useful, but it demonstrates that +# Systemtap can modify variables in a running kernel. + +# Usage: ./keyhack.stp -g + +probe kernel.function("kbd_event") { + # Changes 'm' to 'b' . + if ($event_code == 50) $event_code = 48 +} + +probe end { + printf("\nDONE\n") +} +</code></pre> + + +<h3> +kmalloc.stp - Statistics example. (<a href="http://sourceware.org/systemtap/examples/kmalloc.stp">online source</a>) +</h3> + +<code><pre> +#! /usr/bin/env stap + +# Using statistics to examine kernel memory allocations + +global kmalloc + +probe kernel.function("__kmalloc") { + kmalloc <<< $size +} + +# Exit after 10 seconds +probe timer.ms(10000) { exit () } + +probe end { + printf("Count: %d allocations\n", @count(kmalloc)) + printf("Sum: %d Kbytes\n", @sum(kmalloc)/1000) + printf("Average: %d bytes\n", @avg(kmalloc)) + printf("Min: %d bytes\n", @min(kmalloc)) + printf("Max: %d bytes\n", @max(kmalloc)) + print("\nAllocations by size in bytes\n") + print(@hist_log(kmalloc)) +} +</code></pre> + + +<h3> +kmalloc2.stp - Example using arrays of statistics. (<a href="http://sourceware.org/systemtap/examples/kmalloc2.stp">online source</a>) +</h3> + +<code><pre> +#! /usr/bin/env stap + +# Using statistics and maps to examine kernel memory allocations + +global kmalloc + +probe kernel.function("__kmalloc") { + kmalloc[execname()] <<< $size +} + +# Exit after 10 seconds +probe timer.ms(10000) { exit () } + +probe end { + foreach ([name] in kmalloc) { + printf("Allocations for %s\n", name) + printf("Count: %d allocations\n", @count(kmalloc[name])) + printf("Sum: %d Kbytes\n", @sum(kmalloc[name])/1000) + printf("Average: %d bytes\n", @avg(kmalloc[name])) + printf("Min: %d bytes\n", @min(kmalloc[name])) + printf("Max: %d bytes\n", @max(kmalloc[name])) + print("\nAllocations by size in bytes\n") + print(@hist_log(kmalloc[name])) + printf("-------------------------------------------------------\n\n"); + } +} +</code></pre>
\ No newline at end of file |