From 22f971e83eddada009053d964a397550807b9b50 Mon Sep 17 00:00:00 2001 From: William Cohen Date: Mon, 9 Feb 2009 10:12:00 -0500 Subject: Revised version of kmalloc-top in systemtap.examples. --- testsuite/ChangeLog | 10 ++ testsuite/systemtap.examples/index.html | 3 + testsuite/systemtap.examples/index.txt | 11 ++ testsuite/systemtap.examples/keyword-index.html | 8 +- testsuite/systemtap.examples/keyword-index.txt | 13 ++ testsuite/systemtap.examples/memory/kmalloc-top | 171 +++++++++++++++++++++ .../systemtap.examples/memory/kmalloc-top.meta | 13 ++ testsuite/systemtap.samples/kmalloc-stacks.stp | 35 ----- testsuite/systemtap.samples/kmalloc-top | 97 ------------ 9 files changed, 228 insertions(+), 133 deletions(-) create mode 100755 testsuite/systemtap.examples/memory/kmalloc-top create mode 100644 testsuite/systemtap.examples/memory/kmalloc-top.meta delete mode 100644 testsuite/systemtap.samples/kmalloc-stacks.stp delete mode 100755 testsuite/systemtap.samples/kmalloc-top 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 + + * 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 * 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: IO
  • io/traceio2.stp - Watch I/O Activity on a Particular Device
    keywords: IO

    Print out the executable name and process number as reads and writes 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

    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.

  • 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 @@

    Examples by Keyword

    -

    BACKTRACE CALLGRAPH CPU DISK FUNCTIONS FUTEX GRAPH INTERRUPT IO LOCKING NETWORK PER-PROCESS PROFILING READ SCHEDULER SIGNALS SIMPLE SLEEP SOCKET SYSCALL TCP TIME TRACE TRAFFIC USE WAIT4 WRITE

    +

    BACKTRACE CALLGRAPH CPU DISK FUNCTIONS FUTEX GRAPH INTERRUPT IO LOCKING MEMORY NETWORK PER-PROCESS PROFILING READ SCHEDULER SIGNALS SIMPLE SLEEP SOCKET SYSCALL TCP TIME TRACE TRAFFIC USE WAIT4 WRITE

    BACKTRACE

    • interrupt/scf.stp - Tally Backtraces for Inter-Processor Interrupt (IPI)
      @@ -127,6 +127,12 @@ keywords: IO SYSCALL LOCKING FUTEX

      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.

    +

    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.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.examples/memory/kmalloc-top b/testsuite/systemtap.examples/memory/kmalloc-top new file mode 100755 index 00000000..ccce0c17 --- /dev/null +++ b/testsuite/systemtap.examples/memory/kmalloc-top @@ -0,0 +1,171 @@ +#!/usr/bin/perl +# +# This script accumulates the execution paths of all calls to kmalloc +# 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 +# - any stack with contents matching any of the items in the list will +# be excluded from the output. +# +# The -m (min) option can be used to specify the minimum number of +# occurrences a stack needs to be included in the output. +# +# 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('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_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"; + +#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(\"\\n\") + print_stack(stack) + printf(\"\\n\") + printf(\"%d\\n\", kmalloc_stack[stack]) + } + delete kmalloc_stack +} +"; + +open STREAM, "stap $options -e '$script' $command|" or die "Couldn't get output stream $!"; + +while () { + if (/(.*?)<\/hashval>/) { + update_hash($key, $1); + $key = ""; + } elsif ($_ !~ (/|<\/hashkey>/)) { + $key .= $_; + } +} + +$num_keys_before_filtering = scalar keys %kmalloc_stacks; +$total_kmallocs = count_kmallocs(); +filter_stacks(); +sort_stacks(); +top_stacks(); +sort_stacks(); +$num_keys_after_filtering = scalar keys %kmalloc_stacks; +$filtered_kmallocs = count_kmallocs(); +summarize(); +exit(); + +sub update_hash +{ + my($key, $val) = @_; + $kmalloc_stacks{$key} += $val; +} + +sub filter_stacks +{ + while (($stack, $count) = each %kmalloc_stacks) { + if ($count < $min_count) { + delete $kmalloc_stacks{$stack}; + } elsif ($exclude && $stack =~ /$exclude/) { + delete $kmalloc_stacks{$stack}; + } + } +} + +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"; + } + + 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); +} + +sub sigint_handler +{ + system("pkill kmalloc-stacks"); +} 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(""); - print_stack(stack); - log(""); - print(""); - print(sprint(kmalloc_stack[stack])); - log(""); - reset_maxaction(); - } -} - -probe timer.jiffies(5000) -{ - write_output(); - delete kmalloc_stack; -} - -probe kernel.function("__kmalloc") -{ - kmalloc_stack[backtrace()]++; -} - -probe end -{ - write_output(); -} diff --git a/testsuite/systemtap.samples/kmalloc-top b/testsuite/systemtap.samples/kmalloc-top deleted file mode 100755 index 42a6d152..00000000 --- a/testsuite/systemtap.samples/kmalloc-top +++ /dev/null @@ -1,97 +0,0 @@ -#!/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 -# stdout. -# -# The -e (exclude) option can be used to specify a comma-separated list -# - any stack with contents matching any of the items in the list will -# be excluded from the output. -# -# 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] -# Ctrl-c - -use Getopt::Std; - -my $kmalloc_stacks; -my $total_kmallocs; -my $sorted_stacks; -my $min_count = 1; -my $exclude; - -$SIG{INT} = \&sigint_handler; - -getopts('e:m:'); - -if ($opt_e) { - $exclude = join('|', split(/,/, $opt_e)); - print "Will exclude stacks containing: $exclude\n"; -} - -if ($opt_m) { - $min_count = $opt_n; -} -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 $!"; - -while () { - if (/(.*?)<\/hashval>/) { - update_hash($key, $1); - $key = ""; - } elsif ($_ !~ (/|<\/hashkey>/)) { - $key .= $_; - } -} - -$num_keys_before_filtering = scalar keys %kmalloc_stacks; -filter_stacks(); -$num_keys_after_filtering = scalar keys %kmalloc_stacks; -sort_stacks(); -summarize(); -exit(); - -sub update_hash -{ - my($key, $val) = @_; - $kmalloc_stacks{$key} += $val; - $total_kmallocs += $val; -} - -sub filter_stacks -{ - while (($stack, $count) = each %kmalloc_stacks) { - if ($count < $min_count) { - delete $kmalloc_stacks{$stack}; - } elsif ($exclude && $stack =~ /$exclude/) { - delete $kmalloc_stacks{$stack}; - } - } -} - -sub sort_stacks -{ - @sorted_stacks = sort { $kmalloc_stacks{$b} <=> $kmalloc_stacks{$a} } keys %kmalloc_stacks; -} - -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"; - print "Num stacks before filtering: $num_keys_before_filtering\n"; - print "Num stacks after filtering: $num_keys_after_filtering\n"; - - close(STREAM); -} - -sub sigint_handler -{ - system("pkill kmalloc-stacks"); -} -- cgit