public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
* a short script for static function call tracing
@ 2008-05-08 21:53 Masami Hiramatsu
  0 siblings, 0 replies; only message in thread
From: Masami Hiramatsu @ 2008-05-08 21:53 UTC (permalink / raw)
  To: systemtap-ml

[-- Attachment #1: Type: text/plain, Size: 1227 bytes --]

Hi,

Here is a short script for static function call tracing.
Note: currently, this may shows some(or many) false positives.

this is based on cscope, so before using, in kernel tree,

$ make cscope

and

$ ./trace_symbols a_symbol

For example)
$ ./trace_symbols relay_switch_subbuf
(output thousands of functions...)

To avoid tracing unneeded path, you can add IGNORE symbols

For example)
$ IGNORE="__mod_timer" ./trace_symbols relay_switch_subbuf

__mod_timer
BUG
BUG_ON
unlikely
likely
__acquires
__releases
__volatile__
__attribute__
asm
alternative
defined
__asm__
 --- above symbols are ignored  ---
relay_switch_subbuf is calling __mod_timer smp_mb subbuf_start unlikely waitqueue_active
smp_mb is calling barrier mb
barrier is calling __memory_barrier __volatile__
__memory_barrier is calling
mb is calling alternative
subbuf_start is calling
waitqueue_active is calling list_empty
list_empty is calling

Total: 7 symbols are called from relay_switch_subbuf

This means relay_switch_subbuf itself is a very simple function, but __mod_timer
may call many functions...

Thanks,

-- 
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America) Inc.
Software Solutions Division

e-mail: mhiramat@redhat.com


[-- Attachment #2: trace_symbols --]
[-- Type: text/plain, Size: 964 bytes --]

#!/bin/sh
[ $# -ne 1 ] && echo "usage: trace_symbol <symbol> " && exit 0
# NOTE: currently sometimes cscope returns fales positive function calls
# like indirect call handler name, or the functions in other scopes.

TMP=`mktemp callers.XXXX`

IGNORE="$IGNORE BUG BUG_ON unlikely likely __acquires __releases __volatile__ __attribute__ asm alternative defined __asm__"
for i in $IGNORE; do 
  echo "$i " >> $TMP
done
echo " --- above symbols are ignored  --- " >> $TMP

COUNT=-1 # reduce 1 for the original symbol

function _getcaller() {
  cscope -dq -2$1 -L| cut -d\  -f2 | sort | uniq | xargs
}

function getcaller() {
  local _CALLER=`_getcaller $1`
  local i=
  echo $1 is calling $_CALLER >> $TMP
  echo -ne "$COUNT : $1 \t\t\t\r"
  COUNT=$((COUNT+1))
  for i in $_CALLER; do
    `grep "^$i " $TMP > /dev/null` && continue
    getcaller $i
  done
}

getcaller $1
echo -- finished
echo  
cat $TMP
echo 
echo "Total: $COUNT symbols are called from $1"

rm $TMP

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-05-08 20:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-08 21:53 a short script for static function call tracing Masami Hiramatsu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).