Re: Counting System Calls [patch]

Sander van Malssen (svm@kozmix.ow.nl)
Sun, 19 Apr 1998 18:27:20 +0200


--OgqxwSJOaUobr8KG
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=mutta00290

On Friday, 17 April 1998 at 12:03:38 -0700, Craig Milo Rogers wrote:

> Has anyone created entry.S code to count system calls (per
> syscall number), and /proc code to read these counts?

Here ya go. Info goes to /proc/syscalls (and a totals counter sits in
/proc/stat, just to be gratuitous). A Q&D pretty-printer might look like
this:

-------------------------------- [cut here] --------------------------------
#!/bin/sh

tmp=${TMP-/tmp}/`basename $0`.$$
trap "rm -f $tmp" 0

if [ "$1" = "-s" ]; then
grep="grep -wv 0"
else
grep=cat
fi

grep '#define __NR_' /usr/include/asm/unistd.h | awk '{print $2}' \
| cut -b6- > $tmp

paste $tmp /proc/syscalls | expand -t24 | $grep | ${PAGER-more}
-------------------------------- [cut here] --------------------------------

Anyone want to benchmark this?

Cheers,
Sander

-- 
Sander van Malssen -- svm@kozmix.ow.nl -- http://svm.www.cistron.nl/
        * The 1-2-5 Page: http://svm.www.cistron.nl/music/ *

--OgqxwSJOaUobr8KG Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="syscalls3.a00290.diff"

--- linux/arch/i386/kernel/entry.S.~1~ Sun Apr 19 14:46:52 1998 +++ linux/arch/i386/kernel/entry.S Sun Apr 19 17:01:14 1998 @@ -155,6 +155,8 @@ jae badsys testb $0x20,flags(%ebx) # PF_TRACESYS jne tracesys + incl kstat # kstat.syscalls + incl syscall_stat(,%eax,4) # syscall counter call SYMBOL_NAME(sys_call_table)(,%eax,4) movl %eax,EAX(%esp) # save the return value ALIGN --- linux/fs/proc/array.c.~1~ Sun Apr 19 14:46:52 1998 +++ linux/fs/proc/array.c Sun Apr 19 17:55:52 1998 @@ -35,6 +35,9 @@ * - Incorporation and non-SMP safe operation * of forissier patch in 2.1.78 by * Hans Marcus <crowbar@concepts.nl> + * + * Sander van Malssen: added /proc/syscalls + * <svm@kozmix.ow.nl> */ #include <linux/types.h> @@ -291,13 +294,23 @@ len += sprintf(buffer + len, "\nctxt %u\n" "btime %lu\n" - "processes %lu\n", + "processes %lu\n" + "syscalls %u\n", kstat.context_swtch, xtime.tv_sec - jiffies / HZ, - total_forks); + total_forks, + kstat.syscalls); return len; } +static int get_syscalls(char * buffer) +{ + int i, len = 0; + + for (i = 0; i < NR_syscalls; i++) + len += sprintf (buffer + len, "%d\n", syscall_stat[i]); + return len; +} static int get_uptime(char * buffer) { @@ -1234,6 +1247,9 @@ case PROC_STAT: return get_kstat(page); + + case PROC_SYSCALLS: + return get_syscalls(page); case PROC_SLABINFO: return get_slabinfo(page); --- linux/fs/proc/root.c.~1~ Sat Apr 18 10:21:02 1998 +++ linux/fs/proc/root.c Sun Apr 19 17:21:42 1998 @@ -613,6 +613,11 @@ S_IFREG | S_IRUGO, 1, 0, 0, 0, &proc_array_inode_operations }; +static struct proc_dir_entry proc_root_syscalls = { + PROC_SYSCALLS, 8, "syscalls", + S_IFREG | S_IRUGO, 1, 0, 0, + 0, &proc_array_inode_operations +}; #ifdef __powerpc__ static struct proc_dir_entry proc_root_ppc_htab = { PROC_PPC_HTAB, 8, "ppc_htab", @@ -657,6 +662,7 @@ proc_register(&proc_root, &proc_root_ksyms); #endif proc_register(&proc_root, &proc_root_stat); + proc_register(&proc_root, &proc_root_syscalls); proc_register(&proc_root, &proc_root_devices); proc_register(&proc_root, &proc_root_interrupts); proc_register(&proc_root, &proc_root_filesystems); --- linux/include/linux/kernel_stat.h.~1~ Sun Apr 19 14:46:52 1998 +++ linux/include/linux/kernel_stat.h Sun Apr 19 17:42:26 1998 @@ -5,16 +5,18 @@ #include <asm/smp.h> #include <linux/smp.h> #include <linux/tasks.h> +#include <linux/sys.h> /* * 'kernel_stat.h' contains the definitions needed for doing * some kernel statistics (cpu usage, context switches ...), - * used by rstatd/perfmeter + * used by rstatd/perfmeter/procinfo */ #define DK_NDRIVE 4 struct kernel_stat { + unsigned int syscalls; /* Keep this first! (see entry.S) */ unsigned int cpu_user, cpu_nice, cpu_system; unsigned int per_cpu_user[NR_CPUS], per_cpu_nice[NR_CPUS], @@ -34,6 +36,7 @@ }; extern struct kernel_stat kstat; +extern int syscall_stat[NR_syscalls]; /* * Number of interrupts per specific IRQ source, since bootup --- linux/include/linux/proc_fs.h.~1~ Sat Apr 18 10:28:03 1998 +++ linux/include/linux/proc_fs.h Sun Apr 19 17:03:52 1998 @@ -49,7 +49,8 @@ PROC_SLABINFO, PROC_PARPORT, PROC_PPC_HTAB, - PROC_SOUND + PROC_SOUND, + PROC_SYSCALLS }; enum pid_directory_inos { --- linux/kernel/sched.c.~1~ Fri Apr 17 22:31:16 1998 +++ linux/kernel/sched.c Sun Apr 19 17:42:44 1998 @@ -104,6 +104,7 @@ struct task_struct * task[NR_TASKS] = {&init_task, }; struct kernel_stat kstat = { 0 }; +int syscall_stat[NR_syscalls] = { 0 }; void scheduling_functions_start_here(void) { }

--OgqxwSJOaUobr8KG--

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu