~ chicken-core (chicken-5) fac15e433ed60e4becc7794c948fc99c21b553f1


commit fac15e433ed60e4becc7794c948fc99c21b553f1
Author:     felix <felix@call-with-current-continuation.org>
AuthorDate: Tue Jan 18 09:35:38 2011 +0100
Commit:     felix <felix@call-with-current-continuation.org>
CommitDate: Tue Jan 18 09:35:38 2011 +0100

    accumulated profile stuff seriously broken (needs name or is ineffective) - thanks to Taylor Venable

diff --git a/batch-driver.scm b/batch-driver.scm
index b6e8c3e1..a9e7f276 100644
--- a/batch-driver.scm
+++ b/batch-driver.scm
@@ -31,7 +31,6 @@
 (include "compiler-namespace")
 (include "tweaks")
 
-(define-constant default-profile-name "PROFILE")
 (define-constant funny-message-timeout 60000)
 
 (define user-options-pass (make-parameter #f))
@@ -77,8 +76,11 @@
 	(time-breakdown #f)
 	(forms '())
 	(cleanup-forms '(((##sys#implicit-exit-handler))))
-	(profile (or (memq 'profile options) (memq 'accumulate-profile options) (memq 'profile-name options)))
-	(profile-name (or (and-let* ((pn (memq 'profile-name options))) (cadr pn)) default-profile-name))
+	(profile (or (memq 'profile options)
+		     (memq 'accumulate-profile options) 
+		     (memq 'profile-name options)))
+	(profile-name 
+	 (and-let* ((pn (memq 'profile-name options))) (cadr pn)))
 	(hsize (memq 'heap-size options))
 	(hisize (memq 'heap-initial-size options))
 	(hgrowth (memq 'heap-growth options))
@@ -344,7 +346,10 @@
 		 "calltrace"
 		 "none") )
     (when profile
-      (let ([acc (eq? 'accumulate-profile (car profile))])
+      (let ((acc (eq? 'accumulate-profile (car profile))))
+	(when (and acc (not profile-name))
+	  (quit
+	   "you need to specify -profile-name if using accumulated profiling runs"))
 	(set! emit-profile #t)
 	(set! profiled-procedures 'all)
 	(set! initforms
@@ -354,7 +359,7 @@
 	   (if acc
 	       '((set! ##sys#profile-append-mode #t))
 	       '() ) ) )
-	(dribble "generating ~aprofiled code" (if acc "accumulative " "")) ) )
+	(dribble "generating ~aprofiled code" (if acc "accumulative " "")) ))
 
     ;;*** hardcoded "modules.db" is bad (also used in chicken-install.scm)
     (load-identifier-database "modules.db")
@@ -442,7 +447,8 @@
 			     `((set! ,profile-info-vector-name 
 				 (##sys#register-profile-info
 				  ',plen
-				  ',(if unit-name #f profile-name))))
+				  ',(and (not unit-name)
+					 (or profile-name #t)))))
 			     '() )
 			 (map (lambda (pl)
 				`(##sys#set-profile-info-vector!
diff --git a/manual/Using the compiler b/manual/Using the compiler
index b1c22629..45374e52 100644
--- a/manual/Using the compiler	
+++ b/manual/Using the compiler	
@@ -171,9 +171,9 @@ the source text should be read from standard input.
 ; -prelude EXPRESSIONS : Add {{EXPRESSIONS}} before all other toplevel expressions in the compiled file.  This option may be given multiple times. Processing of this option takes place before processing of {{-prologue}}.
 
 ; -profile : 
-; -accumulate-profile : Instruments the source code to count procedure calls and execution times. After the program terminates (either via an explicit {{exit}} or implicitly), profiling statistics are written to a file named {{PROFILE.<randomnumber>}}. Each line of the generated file contains a list with the procedure name, the number of calls and the time spent executing it. Use the {{chicken-profile}} program to display the profiling information in a more user-friendly form. Enter {{chicken-profile}} with no arguments at the command line to get a list of available options. The {{-accumulate-profile}} option is similar to {{-profile}}, but the resulting profile information will be appended to any existing {{PROFILE}} file. {{chicken-profile}} will merge and sum up the accumulated timing information, if several entries for the same procedure calls exist. Only profiling information for global procedures will be collected.
+; -accumulate-profile : Instruments the source code to count procedure calls and execution times. After the program terminates (either via an explicit {{exit}} or implicitly), profiling statistics are written to a file named {{PROFILE.<randomnumber>}}. Each line of the generated file contains a list with the procedure name, the number of calls and the time spent executing it. Use the {{chicken-profile}} program to display the profiling information in a more user-friendly form. The {{-accumulate-profile}} option is similar to {{-profile}}, but the resulting profile information will be appended to the current file (use {{-profile-name}} in this case to specify to which file it should be appended). {{chicken-profile}} will merge and sum up the accumulated timing information, if several entries for the same procedure calls exist. Only profiling information for global procedures will be collected.
 
-; -profile-name FILENAME : Specifies name of the generated profile information (which defaults to {{PROFILE.<randomnumber>}}. Implies {{-profile}}.
+; -profile-name FILENAME : Specifies name of the generated profile information (which defaults to {{PROFILE.<process-id>}}. Implies {{-profile}}.
 
 ; -prologue FILENAME : Includes the file named {{FILENAME}} at the start of the compiled source file.  The include-path is not searched. This option may be given multiple times.
 
diff --git a/profiler.scm b/profiler.scm
index ac21f0a3..81e4c8e2 100644
--- a/profiler.scm
+++ b/profiler.scm
@@ -49,15 +49,16 @@ EOF
 (define ##sys#profile-name #f)
 (define ##sys#profile-append-mode #f)
 
-
 ;;; Initialize profile counter vector:
 
 (define ##sys#register-profile-info
-  (let ([make-vector make-vector])
+  (let ((make-vector make-vector))
     (lambda (size filename)
       (when filename
-	(set! ##sys#profile-name
-	  (string-append filename "." (number->string profile-id)))
+	(set! ##sys#profile-name 
+	  (if (string? filename)
+	      filename
+	      (string-append "PROFILE." (number->string profile-id))))
 	(let ([oldeh (##sys#exit-handler)]
 	      [oldieh (##sys#implicit-exit-handler)] )
 	  (##sys#exit-handler
@@ -69,7 +70,7 @@ EOF
 	     (##sys#finish-profile)
 	     (oldieh) ) ) ) )
       ;; entry: [name, count, time0, total, pending]
-      (let ([vec (make-vector (* size profile-info-entry-size) 0)])
+      (let ((vec (make-vector (* size profile-info-entry-size) 0)))
 	(set! ##sys#profile-vector-list (cons vec ##sys#profile-vector-list))
 	vec) ) ) )
 
@@ -142,5 +143,5 @@ EOF
 		(write-char #\newline) ) ) ) 
 	  ##sys#profile-vector-list) )
        (if ##sys#profile-append-mode
-	   '(append:)
+	   '(#:append)
 	   '() ) ) ) ) )
Trap