This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Top syscalls


This script will list the top 20 system calls during the interval of 2000 jiffies contineuosly. Run this script with the latest systemtap from CVS. To run the script
stap -g topsys.stp


It takes a while for the system compiling the module, so be patient. The output would look like this

SYSCALL                                                 COUNT
sys_gettimeofday                                        191
sys_ioctl                                               67
sys_poll                                                67
sys_read                                                54
sys_select                                              50
sys_setitimer                                           43
sys_write                                               27
sys_sigreturn                                           21
sys_stat64                                              7
sys_lstat64                                             5
sys_rt_sigprocmask                                      4
sys_time                                                2
sys_rt_sigaction                                        1
sys_wait4                                               1
sys_exit_group                                          1
sys_exit                                                1
sys_waitpid                                             1
sys_fstat64                                             1
sys_writev                                              1
sys_open                                                1
----------------------------------------------------------------


Note: In order fro this script to run contineuosly I have to reset CONTEXT->actioncount every time I print the list, which breaks Frank's safety measure, otherwise I would get this error


ERROR: MAXACTION exceeded near identifier 'sys_cnt' at topsys.stp:33:3

I guess if you are running a script in guru mode such action is allowed.

Hien.
#! stap

global syscall_count, syscall_name

function syscall_name:string () %{
	char *str, buff[80];
	char *tok;
	str = buff;
	strlcpy(str, CONTEXT->probe_point, sizeof(buff));
	tok = strsep(&str, "\"");
	tok = strsep(&str, "@");
	sprintf(str, "%-25s", tok);
	strlcpy(THIS->__retvalue, str, MAXSTRINGLEN);
%}

function reset_maxaction () %{
	if (CONTEXT && CONTEXT->actioncount)
		CONTEXT->actioncount=0;
%}
	
function accumulate () {
	syscall=syscall_name()
	syscall_count[syscall]++
	# I use this array to reference to syscall_count array in reset_count 
	syscall_name[syscall]=0	 
}


function print_top () {
	lcnt=0
	reset_maxaction ()
	foreach ([syscall] in syscall_count) {
		sys_cnt = syscall_count[syscall]
		if (sys_cnt > lcnt) {
 			lsyscall = syscall
			lcnt = sys_cnt
		}
	}
	if (lcnt > 0) 
		log (lsyscall . "\t\t\t\t" . string(lcnt))
	else 
		print ("\n");
	syscall_count[lsyscall]=0
}

function reset_syscall_count () {
	foreach ([syscall] in syscall_name) 
		syscall_count[syscall] = 0
}

function print_systop () {
	log ("SYSCALL                  \t\t\t\tCOUNT")
	for (line=0; line<20; line++)
		print_top()
	reset_syscall_count ()
}
 
function get_daemon_pid:long () 
%{
	THIS->__retvalue = _stp_pid;
%}

probe kernel.function("sys_*") {
	if (pid() != get_daemon_pid())
		accumulate ()
}

probe timer.jiffies(2000) {
	print_systop ()
	log("--------------------------------------------------------------")
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]