How to get the number of system calls after kernel boot in xv6?

advertisements

I want to write a simple "C" program to find number of system calls after OS boot. I am following other system calls like fork() or getpid() and basically copying most of their stuff. I am unsure where/when I should increase my counter? Any example?

Is it a good idea to define the counter in kernel/syscall.c and increment it accordingly?

void
syscall(void)
{
  int num;
  counter++; //mona
  num = proc->tf->eax;
  if(num > 0 && num < NELEM(syscalls) && syscalls[num] != NULL) {
    proc->tf->eax = syscalls[num]();
  } else {
    cprintf("%d %s: unknown sys call %d\n",
            proc->pid, proc->name, num);
    proc->tf->eax = -1;
  }
}

Also here's the code I've got so far in kernel/sysproc.c for my trivial system call:

sys_getsyscallinfo(void)
{

 return counter;  //mona
}

However I receive this error:

kernel/sysproc.c: In function ‘sys_getsyscallinfo’:
kernel/sysproc.c:48: error: ‘counter’ undeclared (first use in this function)
kernel/sysproc.c:48: error: (Each undeclared identifier is reported only once
kernel/sysproc.c:48: error: for each function it appears in.)
make: *** [kernel/sysproc.o] Error 1


I defined a counter variable as extern int in kernel/defs.h and made use of it in syscall definition as the return value in kernel/sysproc.c and increased it where all trap handlings is done in kernel/syscall.c. I hope it helps.