#!/bin/bash pname="" verbose="" function usage { echo "Usage: funccount [process]" } if [ $# -eq 1 ]; then pname=$1 fi echo "Creating and building SystemTap module..." stap "$verbose" -e ' global timebyfunc, pages, page_sz global start, pname_str, totcalls probe begin { pname_str = "'$pname'" printf("Collecting data for %s - type Ctrl-C to print output and exit...\n", pname_str); } probe kernel.function("mpage_readpages") { if ($nr_pages && execname() == pname_str) { start[$nr_pages] = gettimeofday_ns() pages=$nr_pages } } probe kernel.function("mpage_readpages").return { if (pages == 0) next delta = gettimeofday_ns() - start[pages] timebyfunc[pages] <<< delta page_sz[pages] = pages delete start[pages] pages=0 } function print_header() { printf("%-19s %10s %12s\n", "Call", "Count", "Total ns") } probe end { print_header() foreach (page in page_sz-) { printf("mpage_readpages(%d) %10d %12d\n", page_sz[page], @count(timebyfunc[page]), @sum(timebyfunc[page])) totcalls += @count(timebyfunc[page]) } printf("Total Calls: %d\n", totcalls); delete page_sz delete timebyfunc }'