diff lisp/prim/profile.el @ 173:8eaf7971accc r20-3b13

Import from CVS: tag r20-3b13
author cvs
date Mon, 13 Aug 2007 09:49:09 +0200
parents 85ec50267440
children 169c0442b401
line wrap: on
line diff
--- a/lisp/prim/profile.el	Mon Aug 13 09:47:55 2007 +0200
+++ b/lisp/prim/profile.el	Mon Aug 13 09:49:09 2007 +0200
@@ -60,14 +60,21 @@
 
 ;;;###autoload
 (defmacro profile (&rest forms)
-  "Turn on profiling, execute FORMS and stop profiling.
+  "Turn on profiling, execute FORMS and restore profiling state.
+Profiling state here means that if profiling was not in effect when
+PROFILE was called, it will be turned off after FORMS are evaluated.
+Otherwise, profiling will be left running.
+
 Returns the profiling info, printable by `pretty-print-profiling-info'."
   `(progn
-     (unwind-protect
+     (if (profiling-active-p)
 	 (progn
-	   (start-profiling)
 	   ,@forms)
-       (stop-profiling))
+       (unwind-protect
+	   (progn
+	     (start-profiling)
+	     ,@forms)
+	 (stop-profiling)))
      (get-profiling-info)))
 
 (put 'profile 'lisp-indent-function 0)