Added signal handlers for Smalltalk/X.
Upon SIGUSR2 and SIGTERM all processes and their stacks are dumped to
stderr.
--- a/s/stx/BenchmarkRunnerAdapterStX.st Fri Jul 05 03:02:12 2013 +0100
+++ b/s/stx/BenchmarkRunnerAdapterStX.st Sat Jul 13 15:10:44 2013 +0100
@@ -22,14 +22,65 @@
initialize
"Invoked at system start or when the class is dynamically loaded."
-
+
+ "Install signl handlers"
+ self setupSignalHandlers.
"Make sure platform is initialized"
BenchmarkPlatformStX initialize.
-
runner := BenchmarkRunner new.
+ "Modified: / 13-07-2013 / 15:05:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
- "Modified: / 06-06-2013 / 11:25:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!BenchmarkRunnerAdapterStX class methodsFor:'debugging'!
+
+dumpProcess: aProcess
+ Stderr cr; cr
+
+ "Created: / 27-06-2013 / 23:41:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+dumpProcess: aProcess on: aStream
+ | ctx |
+ aStream cr; cr.
+ aStream nextPutAll: '== ['; nextPutAll: aProcess id printString; nextPutAll:'] '; nextPutAll: aProcess name; nextPutAll: ' =='; cr.
+ aStream cr.
+
+ aProcess == Processor activeProcess ifTrue:[ctx := thisContext] ifFalse:[ctx := aProcess suspendedContext].
+ [ ctx notNil ] whileTrue:[
+ aStream nextPutAll: ' '.
+ ctx fullPrintOn: aStream.
+ aStream cr.
+ ctx := ctx sender.
+ ].
+ aStream cr.
+
+ "
+ self dumpProcess: Processor activeProcess on: Transcript.
+ "
+
+ "Created: / 28-06-2013 / 01:00:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+dumpProcesses
+ self dumpProcessesOn: Stderr
+
+ "
+ self dumpProcessesOn: Transcript.
+ "
+
+ "Created: / 27-06-2013 / 23:41:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified (comment): / 28-06-2013 / 01:06:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+dumpProcessesOn: aStream
+ Process allInstancesDo:[:process|
+ process isDead ifFalse:[
+ self dumpProcess: process on: aStream
+ ]
+ ]
+
+ "Created: / 27-06-2013 / 23:42:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!BenchmarkRunnerAdapterStX class methodsFor:'defaults'!
@@ -86,6 +137,48 @@
!BenchmarkRunnerAdapterStX class methodsFor:'startup'!
+handleSIGTERM
+ self dumpProcesses.
+ self exit:127.
+
+ "Created: / 27-06-2013 / 23:10:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 13-07-2013 / 15:09:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+handleSIGUSR2
+ self dumpProcesses
+
+ "Created: / 27-06-2013 / 23:10:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+setupSignalHandlers
+ "On UNIX, this sets up a custom signal handler on SIGUSR2 and SIGTERM that
+ dumps stacks on all threads"
+
+ | sigusr2 sigterm |
+
+ OperatingSystem isUNIXlike ifTrue:[
+
+
+ sigterm := Signal new.
+ sigterm handlerBlock: [:ex | self handleSIGTERM].
+ OperatingSystem operatingSystemSignal:OperatingSystem sigTERM install: sigterm.
+ OperatingSystem enableSignal: OperatingSystem sigTERM.
+
+ sigusr2 := Signal new.
+ sigusr2 handlerBlock: [:ex | self handleSIGUSR2].
+ OperatingSystem operatingSystemSignal:OperatingSystem sigUSR2 install: sigusr2.
+ OperatingSystem enableSignal: OperatingSystem sigUSR2.
+ ].
+
+ "
+ OperatingSystem sendSignal: OperatingSystem sigUSR2 to: OperatingSystem getProcessId
+ "
+
+ "Created: / 27-06-2013 / 20:57:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 28-06-2013 / 01:11:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
setupToolsForDebug
super setupToolsForDebug.