~ chicken-core (chicken-5) c2d5bebb1c78d096575248107de751fde82dfef3


commit c2d5bebb1c78d096575248107de751fde82dfef3
Author:     felix <felix@call-with-current-continuation.org>
AuthorDate: Sat Jul 10 00:14:53 2010 +0200
Commit:     felix <felix@call-with-current-continuation.org>
CommitDate: Sat Jul 10 00:14:53 2010 +0200

    added -:H runtime option

diff --git a/NEWS b/NEWS
index d0dccb4f..e1742ed6 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,6 @@
 4.5.6
 
+- added `-:H' runtime option to dump heap state on exit
 - fixed missing change in Makefile.cygwin (thanks to John Cowan)
 - fixed bug in `let-optionals' macro that caused problems when the
   rest-variable was actually named `rest' (thanks to Alejandro
diff --git a/library.scm b/library.scm
index 32376ae4..7a3be610 100644
--- a/library.scm
+++ b/library.scm
@@ -3487,6 +3487,9 @@ EOF
 (define ##sys#cleanup-before-exit
   (let ([ffp force-finalizers])
     (lambda ()
+      (when (##sys#fudge 37)
+	(##sys#print "\n" #f ##sys#standard-error)
+	(##sys#dump-heap-state))
       (when (##sys#fudge 13)
 	(##sys#print "[debug] forcing finalizers...\n" #f ##sys#standard-error) )
       (when (ffp) (##sys#force-finalizers)) ) ) )
diff --git a/manual/Using the compiler b/manual/Using the compiler
index 70661b90..a1db00aa 100644
--- a/manual/Using the compiler	
+++ b/manual/Using the compiler	
@@ -240,6 +240,8 @@ compiler itself) accept a small set of runtime options:
 
 ; {{-:G}} : Force GUI mode (show error messages in dialog box, suitable for platform).
 
+; {{-:H}} : Before terminating, dump heap usage to stderr.
+
 ; {{-:fNUMBER}} : Specifies the maximal number of currently pending finalizers before finalization is forced.
 
 ; {{-:hNUMBER}} : Specifies fixed heap size
diff --git a/runtime.c b/runtime.c
index 00fdecc5..f1448287 100644
--- a/runtime.c
+++ b/runtime.c
@@ -410,6 +410,7 @@ static C_TLS int
   show_trace,
   fake_tty_flag,
   debug_mode,
+  dump_heap_on_exit,
   gc_bell,
   gc_report_flag = 0,
   gc_mode,
@@ -1154,6 +1155,7 @@ void CHICKEN_parse_command_line(int argc, char *argv[], C_word *heap, C_word *st
 		 " -:B              sound bell on major GC\n"
 		 " -:G              force GUI mode\n"
 		 " -:aSIZE          set trace-buffer/call-chain size\n"
+		 " -:H              dump heap state on exit\n"
 		 "\n  SIZE may have a `k' (`K'), `m' (`M') or `g' (`G') suffix, meaning size\n"
 		 "  times 1024, 1048576, and 1073741824, respectively.\n\n");
 	  exit(0);
@@ -1192,6 +1194,10 @@ void CHICKEN_parse_command_line(int argc, char *argv[], C_word *heap, C_word *st
 	  C_gui_mode = 1;
 	  break;
 
+	case 'H':
+	  dump_heap_on_exit = 1;
+	  break;
+
 	case 's':
 	  *stack = arg_val(ptr);
 	  stack_size_changed = 1;
@@ -4144,7 +4150,8 @@ C_regparm C_word C_fcall C_fudge(C_word fudge_factor)
     debug_mode = !debug_mode;
     return C_mk_bool(debug_mode);
 
-    /* 37 */
+  case C_fix(37):
+    return C_mk_bool(dump_heap_on_exit);
 
   case C_fix(38):
 #ifdef C_SVN_REVISION
diff --git a/tests/runbench.sh b/tests/runbench.sh
index 05125ac8..dee74442 100644
--- a/tests/runbench.sh
+++ b/tests/runbench.sh
@@ -26,7 +26,7 @@ esac
 
 run()
 {
-    /usr/bin/time "$timeopts" ./a.out "$1"
+    /usr/bin/time "$timeopts" ./a.out "$1" "$2" "$3"
 }
 
 echo
@@ -36,13 +36,13 @@ compile="../csc -w -compiler $CHICKEN -I.. -L.. -include-path .. -o a.out $COMPI
 
 echo -n "null ... "
 $compile null.scm -O5
-run
+run -:Hd
 
 echo -n "compilation ... "
 /usr/bin/time "$timeopts" $compile compiler.scm
 
 echo -n "compiler ... "
-run
+run -:Hd
 
 echo -n "slatex ... "
 $compile slatex.scm
@@ -52,7 +52,7 @@ run
 
 echo -n "grep ... "
 $compile sgrep.scm
-run
+run compiler.scm
 
 echo -n "fft/boxed ... "
 $compile fft.scm
Trap