summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Cohen <wcohen@redhat.com>2009-02-09 10:12:00 -0500
committerWilliam Cohen <wcohen@redhat.com>2009-02-09 10:12:00 -0500
commit22f971e83eddada009053d964a397550807b9b50 (patch)
treef27694ca529f2cc1ed2862dcfbb4c49f9e284c6e
parentde0db58a72f197e4dff867f9040bfff982035b6f (diff)
downloadsystemtap-steved-22f971e83eddada009053d964a397550807b9b50.tar.gz
systemtap-steved-22f971e83eddada009053d964a397550807b9b50.tar.xz
systemtap-steved-22f971e83eddada009053d964a397550807b9b50.zip
Revised version of kmalloc-top in systemtap.examples.
-rw-r--r--testsuite/ChangeLog10
-rw-r--r--testsuite/systemtap.examples/index.html3
-rw-r--r--testsuite/systemtap.examples/index.txt11
-rw-r--r--testsuite/systemtap.examples/keyword-index.html8
-rw-r--r--testsuite/systemtap.examples/keyword-index.txt13
-rwxr-xr-xtestsuite/systemtap.examples/memory/kmalloc-top (renamed from testsuite/systemtap.samples/kmalloc-top)90
-rw-r--r--testsuite/systemtap.examples/memory/kmalloc-top.meta13
-rw-r--r--testsuite/systemtap.samples/kmalloc-stacks.stp35
8 files changed, 139 insertions, 44 deletions
diff --git a/testsuite/ChangeLog b/testsuite/ChangeLog
index a9fc0b1e..fa8701ff 100644
--- a/testsuite/ChangeLog
+++ b/testsuite/ChangeLog
@@ -1,3 +1,13 @@
+2009-02-09 Will Cohen <wcohen@redhat.com>
+
+ * systemtap.samples/kmalloc-top: Removed.
+ * systemtap.examples/memory/kmalloc-top: Revised version from samples.
+ * systemtap.examples/memory/kmalloc-top.meta: New
+ * systemtap.examples/index.html:
+ * systemtap.examples/index.txt:
+ * systemtap.examples/keyword-index.html:
+ * systemtap.examples/keyword-index.txt: Regenerate.
+
2009-02-06 Will Cohen <wcohen@redhat.com>
* systemtap.samples/iotask.stp:
diff --git a/testsuite/systemtap.examples/index.html b/testsuite/systemtap.examples/index.html
index 17c520ef..5c6e2fdb 100644
--- a/testsuite/systemtap.examples/index.html
+++ b/testsuite/systemtap.examples/index.html
@@ -73,6 +73,9 @@ keywords: <a href="keyword-index.html#IO">IO</a> <br>
<li><a href="io/traceio2.stp">io/traceio2.stp</a> - Watch I/O Activity on a Particular Device<br>
keywords: <a href="keyword-index.html#IO">IO</a> <br>
<p>Print out the executable name and process number as reads and writes to the specified device occur.</p></li>
+<li><a href="memory/kmalloc-top">memory/kmalloc-top</a> - Show Paths to Kernel Malloc (kmalloc) Invocations<br>
+keywords: <a href="keyword-index.html#MEMORY">MEMORY</a> <br>
+<p>The kmalloc-top perl program runs a small systemtap script to collect stack traces for each call to the kmalloc function and counts the time that each stack trace is observed. When kmalloc-top exits it prints out sorted list. The output can be be filtered to print only only the first stack traces (-t) stack traces with more a minimum counts (-m), or exclude certain stack traces (-e).</p></li>
<li><a href="network/nettop.stp">network/nettop.stp</a> - Periodic Listing of Processes Using Network Interfaces<br>
keywords: <a href="keyword-index.html#NETWORK">NETWORK</a> <a href="keyword-index.html#TRAFFIC">TRAFFIC</a> <a href="keyword-index.html#PER-PROCESS">PER-PROCESS</a> <br>
<p>Every five seconds the nettop.stp script prints out a list of processed (PID and command) with the number of packets sent/received and the amount of data sent/received by the process during that interval.</p></li>
diff --git a/testsuite/systemtap.examples/index.txt b/testsuite/systemtap.examples/index.txt
index 7ae951db..dd5b990a 100644
--- a/testsuite/systemtap.examples/index.txt
+++ b/testsuite/systemtap.examples/index.txt
@@ -100,6 +100,17 @@ keywords: io
to the specified device occur.
+memory/kmalloc-top - Show Paths to Kernel Malloc (kmalloc) Invocations
+keywords: memory
+
+ The kmalloc-top perl program runs a small systemtap script to collect
+ stack traces for each call to the kmalloc function and counts the
+ time that each stack trace is observed. When kmalloc-top exits it
+ prints out sorted list. The output can be be filtered to print only
+ only the first stack traces (-t) stack traces with more a minimum
+ counts (-m), or exclude certain stack traces (-e).
+
+
network/nettop.stp - Periodic Listing of Processes Using Network Interfaces
keywords: network traffic per-process
diff --git a/testsuite/systemtap.examples/keyword-index.html b/testsuite/systemtap.examples/keyword-index.html
index 822131d5..dd52943a 100644
--- a/testsuite/systemtap.examples/keyword-index.html
+++ b/testsuite/systemtap.examples/keyword-index.html
@@ -39,7 +39,7 @@
</ul>
<h2>Examples by Keyword</h2>
-<p><tt><a href="#BACKTRACE">BACKTRACE</a> <a href="#CALLGRAPH">CALLGRAPH</a> <a href="#CPU">CPU</a> <a href="#DISK">DISK</a> <a href="#FUNCTIONS">FUNCTIONS</a> <a href="#FUTEX">FUTEX</a> <a href="#GRAPH">GRAPH</a> <a href="#INTERRUPT">INTERRUPT</a> <a href="#IO">IO</a> <a href="#LOCKING">LOCKING</a> <a href="#NETWORK">NETWORK</a> <a href="#PER-PROCESS">PER-PROCESS</a> <a href="#PROFILING">PROFILING</a> <a href="#READ">READ</a> <a href="#SCHEDULER">SCHEDULER</a> <a href="#SIGNALS">SIGNALS</a> <a href="#SIMPLE">SIMPLE</a> <a href="#SLEEP">SLEEP</a> <a href="#SOCKET">SOCKET</a> <a href="#SYSCALL">SYSCALL</a> <a href="#TCP">TCP</a> <a href="#TIME">TIME</a> <a href="#TRACE">TRACE</a> <a href="#TRAFFIC">TRAFFIC</a> <a href="#USE">USE</a> <a href="#WAIT4">WAIT4</a> <a href="#WRITE">WRITE</a> </tt></p>
+<p><tt><a href="#BACKTRACE">BACKTRACE</a> <a href="#CALLGRAPH">CALLGRAPH</a> <a href="#CPU">CPU</a> <a href="#DISK">DISK</a> <a href="#FUNCTIONS">FUNCTIONS</a> <a href="#FUTEX">FUTEX</a> <a href="#GRAPH">GRAPH</a> <a href="#INTERRUPT">INTERRUPT</a> <a href="#IO">IO</a> <a href="#LOCKING">LOCKING</a> <a href="#MEMORY">MEMORY</a> <a href="#NETWORK">NETWORK</a> <a href="#PER-PROCESS">PER-PROCESS</a> <a href="#PROFILING">PROFILING</a> <a href="#READ">READ</a> <a href="#SCHEDULER">SCHEDULER</a> <a href="#SIGNALS">SIGNALS</a> <a href="#SIMPLE">SIMPLE</a> <a href="#SLEEP">SLEEP</a> <a href="#SOCKET">SOCKET</a> <a href="#SYSCALL">SYSCALL</a> <a href="#TCP">TCP</a> <a href="#TIME">TIME</a> <a href="#TRACE">TRACE</a> <a href="#TRAFFIC">TRAFFIC</a> <a href="#USE">USE</a> <a href="#WAIT4">WAIT4</a> <a href="#WRITE">WRITE</a> </tt></p>
<h3><a name="BACKTRACE">BACKTRACE</a></h3>
<ul>
<li><a href="interrupt/scf.stp">interrupt/scf.stp</a> - Tally Backtraces for Inter-Processor Interrupt (IPI)<br>
@@ -127,6 +127,12 @@ keywords: <a href="keyword-index.html#IO">IO</a> <a href="keyword-index.html#SCH
keywords: <a href="keyword-index.html#SYSCALL">SYSCALL</a> <a href="keyword-index.html#LOCKING">LOCKING</a> <a href="keyword-index.html#FUTEX">FUTEX</a> <br>
<p>The script watches the futex syscall on the system. On exit the futexes address, the number of contentions, and the average time for each contention on the futex are printed from lowest pid number to highest.</p></li>
</ul>
+<h3><a name="MEMORY">MEMORY</a></h3>
+<ul>
+<li><a href="memory/kmalloc-top">memory/kmalloc-top</a> - Show Paths to Kernel Malloc (kmalloc) Invocations<br>
+keywords: <a href="keyword-index.html#MEMORY">MEMORY</a> <br>
+<p>The kmalloc-top perl program runs a small systemtap script to collect stack traces for each call to the kmalloc function and counts the time that each stack trace is observed. When kmalloc-top exits it prints out sorted list. The output can be be filtered to print only only the first stack traces (-t) stack traces with more a minimum counts (-m), or exclude certain stack traces (-e).</p></li>
+</ul>
<h3><a name="NETWORK">NETWORK</a></h3>
<ul>
<li><a href="network/nettop.stp">network/nettop.stp</a> - Periodic Listing of Processes Using Network Interfaces<br>
diff --git a/testsuite/systemtap.examples/keyword-index.txt b/testsuite/systemtap.examples/keyword-index.txt
index acc010c1..5679474f 100644
--- a/testsuite/systemtap.examples/keyword-index.txt
+++ b/testsuite/systemtap.examples/keyword-index.txt
@@ -193,6 +193,19 @@ keywords: syscall locking futex
highest.
+= MEMORY =
+
+memory/kmalloc-top - Show Paths to Kernel Malloc (kmalloc) Invocations
+keywords: memory
+
+ The kmalloc-top perl program runs a small systemtap script to collect
+ stack traces for each call to the kmalloc function and counts the
+ time that each stack trace is observed. When kmalloc-top exits it
+ prints out sorted list. The output can be be filtered to print only
+ only the first stack traces (-t) stack traces with more a minimum
+ counts (-m), or exclude certain stack traces (-e).
+
+
= NETWORK =
network/nettop.stp - Periodic Listing of Processes Using Network Interfaces
diff --git a/testsuite/systemtap.samples/kmalloc-top b/testsuite/systemtap.examples/memory/kmalloc-top
index 42a6d152..ccce0c17 100755
--- a/testsuite/systemtap.samples/kmalloc-top
+++ b/testsuite/systemtap.examples/memory/kmalloc-top
@@ -1,7 +1,8 @@
#!/usr/bin/perl
#
# This script accumulates the execution paths of all calls to kmalloc
-# in the kernel. On Ctrl-C, it sorts, filters and displays them on
+# in the kernel. On Ctrl-C (or exit of the command provided by -c option),
+# it sorts, filters and displays them on
# stdout.
#
# The -e (exclude) option can be used to specify a comma-separated list
@@ -11,33 +12,77 @@
# The -m (min) option can be used to specify the minimum number of
# occurrences a stack needs to be included in the output.
#
-# Usage: ./kmalloc-top [-m min] [-i exclude list]
+# The -t (top) option can be used to specify printing only the
+# top N stack traces.
+#
+# The -c (command) option runs starts the command and script
+# only runs for the duration of the command.
+#
+# The -o (options) option passes the options to systemap.
+#
+# Usage: ./kmalloc-top [-m min] [-e exclude list] [-t top_n] [-c command]
+# [-o options]
# Ctrl-c
use Getopt::Std;
my $kmalloc_stacks;
my $total_kmallocs;
+my $filtered_kmallocs;
my $sorted_stacks;
+my $first_n = 1000000000;
my $min_count = 1;
my $exclude;
+my $options;
$SIG{INT} = \&sigint_handler;
-getopts('e:m:');
+getopts('c:e:m:t:o:');
if ($opt_e) {
$exclude = join('|', split(/,/, $opt_e));
print "Will exclude stacks containing: $exclude\n";
}
+if ($opt_t) {
+ $first_n = $opt_t;
+ print "Will print only the top $first_n stacks.\n";
+}
+
if ($opt_m) {
- $min_count = $opt_n;
+ $min_count = $opt_m;
+}
+
+if ($opt_c) {
+ $command="-c \"$opt_c\""
+}
+
+if ($opt_o) {
+ $options=$opt_o
}
+
print "Will print stacks with counts >= $min_count.\n";
print STDERR "Press Ctrl-C to stop.\n";
-open STREAM, "stap -g kmalloc-stacks.stp |" or die "Couldn't get output stream $!";
+#The systemtap script that instruments the kmalloc
+$script="
+global kmalloc_stack
+
+probe kernel.function(\"__kmalloc\") { kmalloc_stack[backtrace()]++ }
+
+probe timer.ms(100), end
+{
+ foreach (stack in kmalloc_stack) {
+ printf(\"<hashkey>\\n\")
+ print_stack(stack)
+ printf(\"</hashkey>\\n\")
+ printf(\"<hashval>%d</hashval>\\n\", kmalloc_stack[stack])
+ }
+ delete kmalloc_stack
+}
+";
+
+open STREAM, "stap $options -e '$script' $command|" or die "Couldn't get output stream $!";
while (<STREAM>) {
if (/<hashval>(.*?)<\/hashval>/) {
@@ -49,9 +94,13 @@ while (<STREAM>) {
}
$num_keys_before_filtering = scalar keys %kmalloc_stacks;
+$total_kmallocs = count_kmallocs();
filter_stacks();
-$num_keys_after_filtering = scalar keys %kmalloc_stacks;
sort_stacks();
+top_stacks();
+sort_stacks();
+$num_keys_after_filtering = scalar keys %kmalloc_stacks;
+$filtered_kmallocs = count_kmallocs();
summarize();
exit();
@@ -59,7 +108,6 @@ sub update_hash
{
my($key, $val) = @_;
$kmalloc_stacks{$key} += $val;
- $total_kmallocs += $val;
}
sub filter_stacks
@@ -73,20 +121,46 @@ sub filter_stacks
}
}
+sub top_stacks
+{
+ $count=0;
+ foreach $stack(@sorted_stacks) {
+ $count+=1;
+ if ($count > $first_n) {
+ delete $kmalloc_stacks{$stack};
+ }
+ }
+}
+
sub sort_stacks
{
@sorted_stacks = sort { $kmalloc_stacks{$b} <=> $kmalloc_stacks{$a} } keys %kmalloc_stacks;
}
+sub count_kmallocs {
+ $count = 0;
+ foreach $stack(%kmalloc_stacks) {
+ $count += $kmalloc_stacks{$stack};
+ }
+ return $count;
+}
+
sub summarize {
print "\n";
foreach $stack(@sorted_stacks) {
print "This path seen $kmalloc_stacks{$stack} times:\n$stack\n";
}
- print "Total kmallocs (before filtering): $total_kmallocs\n";
+ if ($total_kmallocs > 0) {
+ $percent = ($filtered_kmallocs)*100/$total_kmallocs;
+ } else {
+ $percent = 0;
+ }
print "Num stacks before filtering: $num_keys_before_filtering\n";
print "Num stacks after filtering: $num_keys_after_filtering\n";
+ print "Total kmallocs (before filtering): $total_kmallocs\n";
+ print "Total kmallocs (after filtering): $filtered_kmallocs\n";
+ print "The filter stacks have $percent of the total kmallocs\n";
close(STREAM);
}
diff --git a/testsuite/systemtap.examples/memory/kmalloc-top.meta b/testsuite/systemtap.examples/memory/kmalloc-top.meta
new file mode 100644
index 00000000..2dfbf898
--- /dev/null
+++ b/testsuite/systemtap.examples/memory/kmalloc-top.meta
@@ -0,0 +1,13 @@
+title: Show Paths to Kernel Malloc (kmalloc) Invocations
+name: kmalloc-top
+version: 1.0
+author: anonymous
+keywords: memory
+subsystem: memory
+status: production
+exit: user-controlled
+output: sorted-list
+scope: system-wide
+description: The kmalloc-top perl program runs a small systemtap script to collect stack traces for each call to the kmalloc function and counts the time that each stack trace is observed. When kmalloc-top exits it prints out sorted list. The output can be be filtered to print only only the first stack traces (-t) stack traces with more a minimum counts (-m), or exclude certain stack traces (-e).
+test_check: kmalloc-top -o "-p4" -c "sleep 0"
+test_installcheck: kmalloc-top -c "sleep 1"
diff --git a/testsuite/systemtap.samples/kmalloc-stacks.stp b/testsuite/systemtap.samples/kmalloc-stacks.stp
deleted file mode 100644
index 25a23f2d..00000000
--- a/testsuite/systemtap.samples/kmalloc-stacks.stp
+++ /dev/null
@@ -1,35 +0,0 @@
-global kmalloc_stack
-
-function reset_maxaction () %{
- if (CONTEXT && CONTEXT->actioncount)
- CONTEXT->actioncount=0;
-%}
-
-function write_output()
-{
- foreach (stack in kmalloc_stack) {
- log("<hashkey>");
- print_stack(stack);
- log("</hashkey>");
- print("<hashval>");
- print(sprint(kmalloc_stack[stack]));
- log("</hashval>");
- reset_maxaction();
- }
-}
-
-probe timer.jiffies(5000)
-{
- write_output();
- delete kmalloc_stack;
-}
-
-probe kernel.function("__kmalloc")
-{
- kmalloc_stack[backtrace()]++;
-}
-
-probe end
-{
- write_output();
-}