Subject: | dump at SIGNAME |
I was hoping the -dump_at_SIGI<NAME> option would provide a mechanism to grab a profile from a daemon process without having to kill it; however the injected signal handler is simply removed after dumping without restoring the original handler.
Not sure if there's some reason it should be considered unsafe to continue after dumping, but a trivial test suggests the patch below (written against v0.33) would achieve what I hoped:
% perl -wle 'BEGIN { $SIG{"HUP"} = "IGNORE" } use Devel::MAT::Dumper "-dump_at_SIGHUP"; print "pid $$"; sleep 2; my $a = []; push @$a, $a; print "leaked"; while (1) { sleep 5; print "still running" }'
pid 15150
leaked
still running
Dumping to /home/hv/src/nl/perl-e.pmat because of SIGHUP
still running
still running
^C
%
Hugo
--- Devel/MAT/Dumper.pm.old 2018-08-03 11:35:24.801422267 +0100
+++ Devel/MAT/Dumper.pm 2018-08-03 11:36:52.181422267 +0100
@@ -171,11 +171,12 @@
my $signal = $1;
exists $SIG{$signal} or die "Unrecognised signal name SIG$signal\n";
+ my $orig_handler = $SIG{$signal};
$SIG{$signal} = sub {
( my $file = $dumpfile_name ) =~ s/NNN/$next_serial++/e;
print STDERR "Dumping to $file because of SIG$signal\n";
Devel::MAT::Dumper::dump( $file );
- undef $SIG{$signal};
+ $SIG{$signal} = $orig_handler;
kill $signal => $$;
};
}