[comp.lang.perl] caller doesn't work in signal handler

worley@compass.com (Dale Worley) (04/11/91)

I was hoping to use the interval timer to do some crude profiling of
my Perl program, but I discovered that the call forced by a signal
does not set whatever it is that 'caller' reads.  Can this be fixed?

More specifically, the program

    #! /usr/local/bin/perl

    &setup_profile;

    for (;;) {
	    for ($i = 0; $i < 100; $i++) {}
	    print "tick\n";
    }

    package profile;

    sub main'setup_profile {
	    $SYS_setitimer = 83;
	    $ITIMER_PROF = 2;
	    $interval = 1;

	    local($value) = pack('LLLL', $interval, 0, $interval, 0);

	    $main'SIG{'PROF'} = "profile'report";

	    syscall($SYS_setitimer, $ITIMER_PROF, $value, 0) &&
		    die "syscall() failed";
    }

    sub report {
	    print "profile ", join(' ', caller), "\n";
    }

gives the output (on Perl 3.44):

    tick
    tick
    tick
    tick
    tick
    tick
    tick
    tick
    tick
    There is no caller at tick line 26.

Dale

Dale Worley		Compass, Inc.			worley@compass.com
--
Gag me with a BITNET!

rbj@uunet.UU.NET (Root Boy Jim) (04/12/91)

In <1991Apr10.233240.29339@uvaarpa.Virginia.EDU> worley@compass.com writes:
>I was hoping to use the interval timer to do some crude profiling of
>my Perl program, but I discovered that the call forced by a signal
>does not set whatever it is that 'caller' reads.  Can this be fixed?

Perhaps. But you may want to add a bit of extra code yourself,
so that you can profile *sections* within a subroutine.

Add push(@where,"here") and pop(@where) to your code
at entrance/exit of functions or interesting pieces of code.
-- 
		[rbj@uunet 1] stty sane
		unknown mode: sane

lwall@jpl-devvax.jpl.nasa.gov (Larry Wall) (04/12/91)

In article <1991Apr10.233240.29339@uvaarpa.Virginia.EDU> worley@compass.com writes:
: I was hoping to use the interval timer to do some crude profiling of
: my Perl program, but I discovered that the call forced by a signal
: does not set whatever it is that 'caller' reads.  Can this be fixed?

It has already been fixed, and will be in the patch that is coming out
tomorrow (Friday).  Along with that is a patch to let you die in a
signal handler and trap it with an eval reasonably.  Configure has been
extensively reworked to automate most of the hints that were in the
README file, and to pay better attention to what was in your previous
config.sh.  Several other unofficial patches are being made official.
Some of the labels in eval.c have been relocated to alleviate the
problems with branch addressing.  There is now a mechanism for
modifying the CFLAGS for just some of the files, though none of the
hint files make use of that yet.

Larry