Profiling timer not delivered during syscalls?

Patrick J. LoPresti (patl@cag.lcs.mit.edu)
01 Nov 1999 11:59:33 -0500


I did this test on a Red Hat 6.1 system (glibc 2.1.2) with kernel
2.2.13.

I compiled the appended program like so:

gcc -O2 -Wall -g -pg -o foo foo.c

*** Note the -pg option; it is the whole point of the exercise ***

I ran it, and found that the profiling timer is not being delivered
while the program is in select(). In fact, I have not been able to
find a single system call during which the profiling signal is
delivered. (I do admit, so far I have only tried select(), sleep(),
and pthread_join().)

Is this behavior expected? I would have thought that time spent in
system calls would be pretty important when profiling an application.

- Pat

======================================================================
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>

static __sighandler_t orig_sigprof_handler;

static void
handle_sigprof (int sig, struct sigcontext cxt)
{
fprintf (stderr, "here\n");

if (orig_sigprof_handler != NULL)
((void (*)(int, struct sigcontext))orig_sigprof_handler) (sig, cxt);
}

static void
do_nothing (void)
{
return;
}

int
main (int argc, char *argv[])
{
struct sigaction act;
int i;
struct timeval timeout = { 10, 0 };

/* Get old signal handler. */
if (__sigaction (SIGPROF, NULL, &act) != 0)
{
perror ("first sigaction");
exit (1);
}

/* Install new signal handler, preserving flags and such. */
orig_sigprof_handler = act.sa_handler;
act.sa_handler = (__sighandler_t)handle_sigprof;
if (__sigaction (SIGPROF, &act, NULL) != 0)
{
perror ("second sigaction");
exit (1);
}

select (0, NULL, NULL, NULL, &timeout);
fprintf (stderr, "select finished\n");
for (i=0 ; i<2000000 ; i++)
do_nothing();

return 0;
}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/