#!/bin/bash do_sort=0 sort_ave=0 sort_cnt=0 sort_min=0 sort_max=0 sort_tot=0 show_all=1 verbose="" function usage { echo "Usage: rpccalltimes [-Aachnmtv]" echo " -A - Do all possible sorting" echo " -a - sort by Ave ns" echo " -c - sort by Count" echo " -n - sort by Min ns" echo " -m - sort by Max ns" echo " -t - sort by Total ns" echo " -v - turn on SystemTap debugging" echo " -h - print this help text" } while getopts Aachnmtv option; do case $option in A) sort_ave=1; sort_cnt=1; sort_min=1; sort_max=1; sort_tot=1; do_sort=1;; a) sort_ave=1; do_sort=1;; c) sort_cnt=1; do_sort=1 ;; n) sort_min=1; do_sort=1 ;; m) sort_max=1; do_sort=1 ;; t) sort_tot=1; do_sort=1 ;; v) verbose="-v "$verbose ;; h|?|*) usage exit 1;; esac done if [ $do_sort -eq 1 ]; then show_all=0 fi echo "Creating and building SystemTap module..." stap "$verbose" -e ' global timebyfunc, top global start probe begin { printf("Collecting rpc data - type Ctrl-C to print output and exit...\n") } probe module("sunrpc").function("*@net/sunrpc/*") { start[probefunc(), tid()] = gettimeofday_ns() } probe module("sunrpc").function("*@net/sunrpc/*").return { if (!([probefunc(), tid()] in start)) next delta = gettimeofday_ns() - start[probefunc(), tid()] timebyfunc[probefunc()] <<< delta delete start[probefunc(), tid()] } function print_header() { printf("%-26s %10s %12s %12s %12s %12s\n", "Call", "Count", "Total ns", "Avg ns", "Min ns", "Max ns") } probe end { if ('$sort_ave' != 0) { printf("\nSorted rpc data by Avg ns \n") print_header() foreach (call in timebyfunc) top[call] = @avg(timebyfunc[call]) foreach (call in top- limit 20) printf("%-26s %10d %12d %12d %12d %12d\n", call, @count(timebyfunc[call]), @sum(timebyfunc[call]), @avg(timebyfunc[call]), @min(timebyfunc[call]), @max(timebyfunc[call])) delete top } if ('$sort_cnt' != 0) { printf("\nSorted rpc data by Count\n") print_header() foreach (call in timebyfunc) top[call] = @count(timebyfunc[call]) foreach (call in top- limit 20) printf("%-26s %10d %12d %12d %12d %12d\n", call, @count(timebyfunc[call]), @sum(timebyfunc[call]), @avg(timebyfunc[call]), @min(timebyfunc[call]), @max(timebyfunc[call])) delete top } if ('$sort_tot' != 0) { printf("\nSorted rpc data by Total ns\n") print_header() foreach (call in timebyfunc) top[call] = @sum(timebyfunc[call]) foreach (call in top- limit 20) printf("%-26s %10d %12d %12d %12d %12d\n", call, @count(timebyfunc[call]), @sum(timebyfunc[call]), @avg(timebyfunc[call]), @min(timebyfunc[call]), @max(timebyfunc[call])) delete top } if ('$sort_min' != 0) { printf("\nSorted rpc data by Min ns\n") print_header() foreach (call in timebyfunc) top[call] = @min(timebyfunc[call]) foreach (call in top- limit 20) printf("%-26s %10d %12d %12d %12d %12d\n", call, @count(timebyfunc[call]), @sum(timebyfunc[call]), @avg(timebyfunc[call]), @min(timebyfunc[call]), @max(timebyfunc[call])) delete top } if ('$sort_max' != 0) { printf("\nSorted rpc data by Max ns\n") print_header() foreach (call in timebyfunc) top[call] = @min(timebyfunc[call]) foreach (call in top- limit 20) printf("%-26s %10d %12d %12d %12d %12d\n", call, @count(timebyfunc[call]), @sum(timebyfunc[call]), @avg(timebyfunc[call]), @min(timebyfunc[call]), @max(timebyfunc[call])) delete top } if ('$show_all' != 0) { print_header() foreach (call in timebyfunc) printf("%-26s %10d %12d %12d %12d %12d\n", call, @count(timebyfunc[call]), @sum(timebyfunc[call]), @avg(timebyfunc[call]), @min(timebyfunc[call]), @max(timebyfunc[call])) } delete timebyfunc }'